COBOL Screen – Quick Reference

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.

Explain Like I'm Five: What Is a Screen?

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.

SCREEN SECTION

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.

Screen Description Entry Basics

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).

TO, FROM, USING
PhraseMeaningWhen to use
TO data-itemInput: value entered by user is stored in data-item.Input fields for ACCEPT.
FROM data-itemOutput: value of data-item is displayed.Display-only fields (labels, computed values).
USING data-itemUpdate: value is displayed and user can change it.ACCEPT ... WITH UPDATE for editable display.

Positioning: LINE and COLUMN

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.

Common screen description clauses
ClauseMeaningExample
LINE number / LINE NUMBERRow on the screen (e.g. 1-based).LINE 5
COLUMN number / COLUMN NUMBERColumn on the screen.COLUMN 10
PICTUREFormat and length of the field (same as data description).PIC X(20)
VALUE literalInitial literal displayed (no data binding).VALUE "Name:"
HIGHLIGHT / REVERSE-VIDEO / BLINKVisual attribute (implementation-dependent).HIGHLIGHT

ACCEPT and DISPLAY with Screens

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).

cobol
1
2
3
4
5
6
7
8
9
10
11
SCREEN 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.

Step-by-Step: Defining a Simple Input Screen

  1. In the DATA DIVISION, add SCREEN SECTION. Define a 01-level name for the screen (e.g. 01 ENTRY-SCREEN.).
  2. For each prompt, add an entry with LINE and COLUMN and VALUE "prompt text".
  3. For each input field, add an entry with LINE and COLUMN, PICTURE matching the data item, and TO data-item. Ensure the data item is defined in WORKING-STORAGE (or LINKAGE) with the same PICTURE.
  4. In the PROCEDURE DIVISION, DISPLAY the screen (optional if you only need input), then ACCEPT the screen. After ACCEPT, the TO data items contain the user input.

Step-by-Step: Display-Only and Update Fields

  1. For a field that only shows a value (e.g. a total), use FROM data-item. DISPLAY will show it; ACCEPT without UPDATE will not let the user change it.
  2. For a field that shows a value and can be edited, use USING data-item. Use ACCEPT screen-name WITH UPDATE so the user can change it; the new value is stored back in the data item.
  3. Order and position LINE/COLUMN so that the cursor movement (e.g. Tab) follows a logical order for the user.

Compiler and Platform Notes

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.

Best Practices

Test Your Knowledge

Test Your Knowledge

1. A screen item with TO is used for:

  • Display only
  • Input: user entry is stored in the TO data item
  • Both input and output
  • Deleting data

2. ACCEPT screen-name WITH UPDATE is used to:

  • Only display
  • Display and allow the user to edit fields bound with FROM or USING
  • Clear the screen
  • Print the screen

3. SCREEN SECTION is:

  • Part of PROCEDURE DIVISION
  • An optional part of the DATA DIVISION for defining screen layouts
  • Required in every program
  • A file section