COBOL by Example: Screen Section
Code
IDENTIFICATION DIVISION.
PROGRAM-ID. SCREEN-DEMO.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 USER-INPUT PIC X(20).
SCREEN SECTION.
01 MAIN-SCREEN.
05 BLANK SCREEN.
05 LINE 5 COLUMN 20 VALUE "Welcome to COBOL".
05 LINE 7 COLUMN 20 VALUE "Enter Name: ".
05 LINE 7 COLUMN 32 PIC X(20) TO USER-INPUT REVERSE-VIDEO.
PROCEDURE DIVISION.
DISPLAY MAIN-SCREEN.
ACCEPT MAIN-SCREEN.
DISPLAY "You entered: " USER-INPUT AT 1020.
STOP RUN.Explanation
The SCREEN SECTION allows you to define complex terminal layouts with colors, positioning, and input fields. Instead of using raw DISPLAY statements, you define the entire screen structure declaratively in the Data Division. This was the standard way to build user interfaces before GUIs.
You can control attributes like REVERSE-VIDEO, BLINK, HIGHLIGHT, and colors (foreground/background). The DISPLAY statement paints the whole screen at once, and ACCEPT handles the interaction, moving the cursor between fields and collecting user input.
This section is often used in CICS or other transaction processing monitors to define the "maps" that users see on their green-screen terminals. It provides a structured way to handle form data separately from the program logic.

