SCREEN SECTION defines terminal screens, field positions, and attributes. Use ACCEPT to read, DISPLAY to show.
It’s like drawing a form on graph paper: each box (field) has a row and column. The user fills the boxes; you check the values.
12345678DATA DIVISION. SCREEN SECTION. 01 LOGIN-SCREEN. 05 LINE 2 COLUMN 10 VALUE 'User ID:'. 05 LINE 2 COLUMN 20 PIC X(10) TO USER-ID. 05 LINE 3 COLUMN 10 VALUE 'Password:'. 05 LINE 3 COLUMN 20 PIC X(10) TO USER-PASS.
TO / FROM clauses bind screen fields to data items (compiler-specific).
12345678PROCEDURE DIVISION. DISPLAY LOGIN-SCREEN ACCEPT LOGIN-SCREEN IF USER-ID = SPACES OR USER-PASS = SPACES DISPLAY 'Both fields required.' DISPLAY LOGIN-SCREEN ACCEPT LOGIN-SCREEN WITH UPDATE END-IF.
WITH UPDATE allows editing existing values in-place.
1234IF USER-ID = SPACES OR FUNCTION LENGTH(USER-ID) < 3 DISPLAY 'Invalid user id' AT LINE 5 COLUMN 10 GO TO REDISPLAY END-IF.
Validate immediately after ACCEPT and show messages at clear positions.
Mistake | Problem | Fix |
---|---|---|
Hard-coded positions only | Difficult to change | Use constants for LINE/COLUMN |
No input masking | Leaked sensitive input | Mask passwords |
Feature | Syntax | Example |
---|---|---|
Screen definition | SCREEN SECTION | 01 LOGIN-SCREEN ... |
Positioning | LINE n COLUMN m | LINE 2 COLUMN 10 |
Interaction | DISPLAY / ACCEPT | ACCEPT LOGIN-SCREEN |
1. Where are screen items defined?
2. Which verbs interact with the terminal?
3. How do you position a field?
4. What does UPDATE do with ACCEPT?
5. Where to validate input?