Screen handling in COBOL lets you define form-like layouts and use ACCEPT and DISPLAY to show and collect data at fixed positions. The SCREEN SECTION (when supported) defines these layouts; each screen item can be positioned with LINE and COLUMN and bound to data with TO (input), FROM (output), or USING (update). This page is a quick reference to the main concepts and syntax. Support for SCREEN SECTION varies by compiler; IBM mainframe COBOL often uses BMS or CICS maps instead.
A screen is like a form: there are labels ("Name", "Amount") and boxes where the user types or where the program shows values. You define where each label and box goes (row and column) and which box is for typing (TO), which is only for showing (FROM), or which can be edited (USING). Then you say DISPLAY to show the form and ACCEPT to let the user fill it in. The screen is the layout; ACCEPT and DISPLAY are the actions that use it.
The SCREEN SECTION appears in the DATA DIVISION after FILE SECTION and WORKING-STORAGE SECTION (or in an implementation-defined order). It contains screen description entries. Each entry describes a screen item: a literal (e.g. a prompt), an input field (TO), an output field (FROM), or an update field (USING). Level numbers (01–49) organize items; 01-level entries are screen names that you use in ACCEPT or DISPLAY. Elementary items must have at least one of: LINE/COLUMN (or equivalent), PICTURE, VALUE, or a clause like BLANK LINE. The exact syntax (e.g. LINE NUMBER vs LINE, SCREEN SECTION vs SCREEN SECTION) depends on the COBOL standard level and the compiler. Check your product documentation.
A screen description entry defines one visible item on the screen. It includes positioning (where the item appears), optional visual attributes (highlight, reverse video), and for data fields a link to a data item. Input fields use TO data-item: when the user types, the value goes into that data item. Output fields use FROM data-item: the current value of that item is displayed and not editable (unless you use UPDATE). Update fields use USING data-item: the value is shown and the user can change it when you use ACCEPT ... WITH UPDATE. Literals use VALUE "text" and no TO/FROM/USING; they are fixed text (e.g. prompts).
| Phrase | Meaning | When to use |
|---|---|---|
| TO data-item | Input: value entered by user is stored in data-item. | Input fields for ACCEPT. |
| FROM data-item | Output: value of data-item is displayed. | Display-only fields (labels, computed values). |
| USING data-item | Update: value is displayed and user can change it. | ACCEPT ... WITH UPDATE for editable display. |
Screen items are placed at row and column. Typically LINE (or LINE NUMBER) gives the row and COLUMN (or COLUMN NUMBER) gives the column. Rows and columns are usually 1-based (e.g. LINE 1 COLUMN 1 is top-left). Some compilers support relative positioning (e.g. LINE NUMBER PLUS 1 to move down one line from the previous item). The screen size (e.g. 24 lines × 80 columns) is environment-dependent.
| Clause | Meaning | Example |
|---|---|---|
| LINE number / LINE NUMBER | Row on the screen (e.g. 1-based). | LINE 5 |
| COLUMN number / COLUMN NUMBER | Column on the screen. | COLUMN 10 |
| PICTURE | Format and length of the field (same as data description). | PIC X(20) |
| VALUE literal | Initial literal displayed (no data binding). | VALUE "Name:" |
| HIGHLIGHT / REVERSE-VIDEO / BLINK | Visual attribute (implementation-dependent). | HIGHLIGHT |
DISPLAY screen-name (or screen-item) sends the screen to the device. Literals and FROM (and USING) fields are shown at their positions; TO fields may show the current value of the data item or be blank depending on the implementation. ACCEPT screen-name displays the screen and then accepts input: the user can move between fields (e.g. Tab, arrow keys) and type into TO (and USING with UPDATE) fields. When the user terminates input (e.g. Enter), the entered values are in the bound data items. ACCEPT ... WITH UPDATE allows the user to modify FROM and USING fields as well; the new values are written back to the data items. So DISPLAY is output-only; ACCEPT is input (and with UPDATE, in-place edit).
1234567891011SCREEN SECTION. 01 INPUT-SCREEN. 05 LINE 2 COLUMN 2 VALUE 'Name: '. 05 LINE 2 COLUMN 10 PIC X(30) TO WS-NAME. 05 LINE 4 COLUMN 2 VALUE 'Amount: '. 05 LINE 4 COLUMN 12 PIC 9(5)V99 TO WS-AMOUNT. PROCEDURE DIVISION. DISPLAY INPUT-SCREEN ACCEPT INPUT-SCREEN *> WS-NAME and WS-AMOUNT now contain user input.
Exact syntax (LINE/COLUMN, TO, PIC) may differ by compiler. Some use FULL for full-screen and require different positioning rules.
SCREEN SECTION is not universal. IBM Enterprise COBOL for z/OS does not use SCREEN SECTION for 3270 screens; applications use BMS (Basic Mapping Support) or CICS maps. Micro Focus COBOL and similar PC/midrange compilers often support SCREEN SECTION for character or block-mode screens. The exact clauses (BELL, BLANK SCREEN, ERASE, FULL, etc.) and behavior (cursor handling, function keys) are implementation-defined. Always check your compiler manual for the supported screen syntax and for alternatives (e.g. CICS SEND MAP / RECEIVE MAP) on the mainframe.
1. A screen item with TO is used for:
2. ACCEPT screen-name WITH UPDATE is used to:
3. SCREEN SECTION is: