The Screen Section is a part of the Data Division (in COBOL implementations that support it) where you define a full-screen layout: where each label and field appears (line and column) and whether each field is input, output, or both. You then use DISPLAY to show the screen and ACCEPT to read user input. Not all compilers support Screen Section; for example, IBM mainframe COBOL often uses CICS BMS for 3270 screens. This page describes the Screen Section for compilers that do support it (e.g. Micro Focus).
Instead of writing DISPLAY and ACCEPT one line at a time, you draw the whole screen once: "At line 2, column 10 put the label 'Name:'; at line 2, column 20 put an input field for the name." That layout is the Screen Section. When the program runs, DISPLAY shows the whole form and ACCEPT lets the user type in the input areas.
The Screen Section appears in the Data Division, after other sections (e.g. FILE SECTION, WORKING-STORAGE SECTION). It is introduced with the words SCREEN SECTION. Under it you define one or more screens, each starting with a level 01 entry that has a screen name. Subordinate entries (e.g. 03, 05) define the lines, columns, and field types.
Each screen item can have LINE and COLUMN (or equivalent clauses, depending on compiler) to fix its position. LINE is the row number; COLUMN is the column number. So you can place a title at LINE 1 COLUMN 25, a label at LINE 3 COLUMN 5, and an input field at LINE 3 COLUMN 25. Exact syntax may be LINE NUMBER IS 5 or LINE 5; check your compiler manual.
| Phrase | Type | Effect |
|---|---|---|
| VALUE literal | Literal/prompt | Output only (fixed text) |
| FROM data-name | Output field | Displays value of data-name |
| TO data-name | Input field | User input stored in data-name |
| USING data-name | Update field | Shows value and accepts input |
VALUE is for fixed text (labels, prompts). FROM displays the value of a data item but does not allow input. TO designates an input field; the value the user types is stored in the named data item. USING shows the current value of the data item and allows the user to change it (display and edit).
In this example, MAIN-SCREEN is the 01-level screen name. The first item is a literal at line 1, column 20. The next items are a label and an input field on line 3, and a label and an output/update field on line 4. The data items (e.g. WS-USER-NAME) would be defined in WORKING-STORAGE. Syntax details (e.g. LINE NUMBER IS) depend on your compiler.
1234567891011121314DATA DIVISION. SCREEN SECTION. 01 MAIN-SCREEN. 05 LINE 1 COLUMN 20 VALUE "Customer Entry". 05 LINE 3 COLUMN 5 VALUE "Name: ". 05 LINE 3 COLUMN 20 PIC X(30) TO WS-USER-NAME. 05 LINE 4 COLUMN 5 VALUE "Balance: ". 05 LINE 4 COLUMN 20 PIC Z(7)9.99 FROM WS-BALANCE. PROCEDURE DIVISION. DISPLAY MAIN-SCREEN ACCEPT MAIN-SCREEN *> User can type into WS-USER-NAME; WS-BALANCE is display-only STOP RUN.
DISPLAY screen-name sends the screen to the terminal: all literals and FROM/USING fields show their current values. ACCEPT screen-name lets the user move the cursor and type into TO and USING fields; when they finish (e.g. press Enter), the input is stored in the corresponding data items. Some systems let you DISPLAY and ACCEPT in one operation or support attributes (e.g. highlight, reverse video) in the screen definition.
1. A Screen Section field with TO phrase is used for:
2. Where is the Screen Section defined?