The user interface in COBOL is how your program talks to the user: showing messages and prompts and reading what they type. Most COBOL programs use a character-based interface built from two main verbs—DISPLAY and ACCEPT—and, in some compilers, a Screen Section that defines full-screen layouts. This page explains these building blocks and how to use them for simple, clear interaction.
The user interface is what the user sees and uses. When the program shows a message like "Enter your name:" and waits for the user to type something, that is the user interface. COBOL does this with DISPLAY (to show text) and ACCEPT (to read what was typed). Think of DISPLAY as the program speaking and ACCEPT as the program listening.
DISPLAY sends data to the screen (or another device). You can display literals, variables, or both. ACCEPT reads input from the keyboard (or from the system, e.g. date or time) and stores it in a variable. Together they form the basis of a simple conversation with the user.
| Verb | Purpose | Example |
|---|---|---|
| DISPLAY | Send data to screen or device | DISPLAY "Enter ID: ". |
| ACCEPT | Read input from keyboard or system | ACCEPT WS-USER-ID. |
In this snippet, the program prompts for a customer number, reads it into WS-CUST-NUM, and then displays it back. The DISPLAY lines show text; the ACCEPT line reads the value into the variable.
123DISPLAY "Enter customer number: " ACCEPT WS-CUST-NUM DISPLAY "You entered: " WS-CUST-NUM
DISPLAY can output one or more items. Each item can be a literal (in quotes), a data name (variable), or a combination. Items are sent in order; spacing depends on how you separate them. Some implementations support WITH NO ADVANCING so the cursor stays on the same line after the DISPLAY, which is useful for prompts where the user types on the same line.
1234567*> Cursor moves to next line after each DISPLAY DISPLAY "Name: " DISPLAY WS-NAME *> With NO ADVANCING, prompt and input can be on same line DISPLAY "Name: " WITH NO ADVANCING ACCEPT WS-NAME
ACCEPT reads input into a variable. Without any extra clauses, it typically reads from the keyboard. You can also use ACCEPT ... FROM to get system values, for example ACCEPT WS-DATE FROM DATE or ACCEPT WS-TIME FROM TIME. The receiving field must be large enough and have a type (e.g. numeric or alphanumeric) that matches how you use the data.
Some COBOL compilers support a Screen Section in the Data Division. There you define a screen by giving each element a line and column position, and whether it is output-only, input, or both. You then DISPLAY the screen to show it and ACCEPT the screen to read user input. This gives you a full-screen form instead of line-by-line DISPLAY and ACCEPT. Support and syntax vary by vendor (e.g. Micro Focus, IBM).
05 WS-INPUT PIC X(20)).1. Which COBOL verb sends data to the screen?
2. Which verb reads input from the user into a variable?