MainframeMaster

COBOL Tutorial

COBOL Screen Handling

Progress0 of 0 lessons

Introduction to Screen Handling

Screen handling in COBOL involves managing user input and output through terminal interfaces. It encompasses displaying information to users, accepting input from keyboards, formatting screens, and creating interactive user interfaces.

What is Screen Handling?

Screen handling refers to the techniques and statements used to:

  • Display information - Show data, messages, and prompts to users
  • Accept user input - Read data from keyboards and other input devices
  • Format screens - Control the appearance and layout of user interfaces
  • Position cursor - Control where text appears on the screen
  • Handle user interaction - Manage input validation and user responses
  • Create menus - Build navigation systems and user choices

Effective screen handling is essential for creating user-friendly, interactive COBOL applications.

Key Components of Screen Handling

ComponentPurposeExample
DISPLAY StatementOutput data to screenDISPLAY "Hello World"
ACCEPT StatementRead user inputACCEPT USER-NAME
SCREEN SECTIONDefine screen layoutsScreen field definitions
Cursor ControlPosition text on screenAT LINE, AT COLUMN
Screen AttributesFormat appearanceHIGHLIGHT, UNDERLINE

DISPLAY Statement

The DISPLAY statement is the primary method for outputting data to the screen, printer, or other output devices. It provides various options for formatting and positioning output.

Basic DISPLAY Syntax

cobol
1
2
3
4
5
6
7
8
9
10
11
12
* Basic DISPLAY statement DISPLAY "Hello, World!" * DISPLAY with multiple items DISPLAY "Customer Name: " CUSTOMER-NAME DISPLAY "Account Balance: " ACCOUNT-BALANCE * DISPLAY with positioning DISPLAY "Title" AT LINE 5 AT COLUMN 10 * DISPLAY with formatting DISPLAY "Important Message" WITH HIGHLIGHT

The DISPLAY statement can output literals, variables, and expressions with optional formatting.

Cursor Positioning

Control where text appears on the screen using positioning clauses:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
* Position text at specific coordinates DISPLAY "Menu Options:" AT LINE 3 AT COLUMN 5 DISPLAY "1. Add Customer" AT LINE 5 AT COLUMN 10 DISPLAY "2. View Customer" AT LINE 6 AT COLUMN 10 DISPLAY "3. Exit" AT LINE 7 AT COLUMN 10 * Clear screen and position cursor DISPLAY SPACES AT LINE 1 AT COLUMN 1 DISPLAY "Welcome to Customer System" AT LINE 1 AT COLUMN 1 * Create a formatted header DISPLAY "CUSTOMER MANAGEMENT SYSTEM" AT LINE 1 AT COLUMN 20 WITH HIGHLIGHT DISPLAY "=================================" AT LINE 2 AT COLUMN 20

AT LINE and AT COLUMN provide precise control over screen positioning.

Display Attributes

Use attributes to enhance the appearance of displayed text:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
* Various display attributes DISPLAY "ERROR MESSAGE" WITH HIGHLIGHT DISPLAY "Warning" WITH LOWLIGHT DISPLAY "Important" WITH REVERSE-VIDEO DISPLAY "Underlined Text" WITH UNDERLINE DISPLAY "Blinking Text" WITH BLINK DISPLAY "Beep Sound" WITH BEEP * Combining attributes DISPLAY "CRITICAL ERROR" WITH HIGHLIGHT REVERSE-VIDEO BLINK * Conditional formatting IF ERROR-FLAG = "Y" DISPLAY "Error occurred" WITH HIGHLIGHT ELSE DISPLAY "Operation successful" WITH LOWLIGHT END-IF

Attributes can be combined to create visually distinct output for different purposes.

Display Attributes Reference

AttributeEffectUse Case
HIGHLIGHTBright/bold textImportant information, errors
LOWLIGHTDim textSecondary information
REVERSE-VIDEOReversed colorsHeaders, emphasis
UNDERLINEUnderlined textField labels, titles
BLINKFlashing textCritical alerts
BEEPAudible toneError notifications

ACCEPT Statement

The ACCEPT statement is used to read data from the keyboard or other input devices. It provides various options for positioning, prompting, and formatting input.

Basic ACCEPT Syntax

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
* Basic ACCEPT statement ACCEPT USER-NAME * ACCEPT with prompt ACCEPT USER-NAME PROMPT "Enter your name: " * ACCEPT with positioning ACCEPT CUSTOMER-ID AT LINE 10 AT COLUMN 15 * ACCEPT with prompt and positioning ACCEPT CUSTOMER-NAME AT LINE 12 AT COLUMN 15 PROMPT "Customer Name: " * ACCEPT with formatting ACCEPT PASSWORD WITH SECURE

ACCEPT statements can include prompts, positioning, and various input options.

ACCEPT with PROMPT

Use PROMPT to provide user guidance:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
* Simple prompts ACCEPT CUSTOMER-ID PROMPT "Enter Customer ID: " ACCEPT CUSTOMER-NAME PROMPT "Enter Customer Name: " ACCEPT ORDER-AMOUNT PROMPT "Enter Order Amount: " * Prompts with positioning DISPLAY "Customer Information Entry" AT LINE 5 AT COLUMN 10 ACCEPT CUSTOMER-ID AT LINE 7 AT COLUMN 10 PROMPT "Customer ID: " ACCEPT CUSTOMER-NAME AT LINE 8 AT COLUMN 10 PROMPT "Customer Name: " ACCEPT CUSTOMER-ADDRESS AT LINE 9 AT COLUMN 10 PROMPT "Address: " * Prompts with validation hints ACCEPT PHONE-NUMBER PROMPT "Enter Phone Number (XXX-XXX-XXXX): " ACCEPT EMAIL-ADDRESS PROMPT "Enter Email Address: "

PROMPT provides clear instructions to users about what information to enter.

ACCEPT Options and Clauses

Various clauses provide additional input control:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
* ACCEPT with SECURE (password input) ACCEPT PASSWORD PROMPT "Enter Password: " WITH SECURE * ACCEPT with NO PROMPT (suppress prompt) ACCEPT CONFIRMATION AT LINE 15 AT COLUMN 10 NO PROMPT * ACCEPT with SIZE clause ACCEPT SHORT-INPUT PROMPT "Enter Code (3 chars): " SIZE 3 * ACCEPT with UPDATE clause ACCEPT CUSTOMER-NAME PROMPT "Customer Name: " WITH UPDATE * ACCEPT with AUTO-SKIP ACCEPT FIELD-1 SIZE 5 AUTO-SKIP ACCEPT FIELD-2 SIZE 10 AUTO-SKIP

These options provide enhanced input control and user experience.

ACCEPT Clauses Reference

ClausePurposeExample
PROMPTDisplay input promptPROMPT "Enter name: "
AT LINE/COLUMNPosition input fieldAT LINE 10 AT COLUMN 15
SECUREHide input charactersWITH SECURE
SIZELimit input lengthSIZE 10
AUTO-SKIPAuto-advance cursorAUTO-SKIP
UPDATEAllow field editingWITH UPDATE

SCREEN SECTION

The SCREEN SECTION is a specialized part of the DATA DIVISION that defines the visual layout and behavior of user interface screens. It provides a structured way to create formatted, professional-looking screens.

SCREEN SECTION Structure

The SCREEN SECTION contains screen descriptions that define field layouts:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
DATA DIVISION. SCREEN SECTION. 01 CUSTOMER-ENTRY-SCREEN. 05 LINE 5 COLUMN 10 VALUE "CUSTOMER INFORMATION ENTRY". 05 LINE 7 COLUMN 10 VALUE "Customer ID: ". 05 LINE 7 COLUMN 25 PIC X(10) TO CUSTOMER-ID REQUIRED AUTO-SKIP. 05 LINE 8 COLUMN 10 VALUE "Customer Name: ". 05 LINE 8 COLUMN 25 PIC X(30) TO CUSTOMER-NAME REQUIRED AUTO-SKIP. 05 LINE 9 COLUMN 10 VALUE "Address: ". 05 LINE 9 COLUMN 25 PIC X(50) TO CUSTOMER-ADDRESS AUTO-SKIP. 05 LINE 10 COLUMN 10 VALUE "Phone: ". 05 LINE 10 COLUMN 25 PIC X(15) TO CUSTOMER-PHONE AUTO-SKIP. 05 LINE 12 COLUMN 10 VALUE "Press ENTER to save, ESC to cancel". 01 MENU-SCREEN. 05 LINE 3 COLUMN 20 VALUE "CUSTOMER MANAGEMENT SYSTEM" HIGHLIGHT. 05 LINE 5 COLUMN 20 VALUE "1. Add New Customer". 05 LINE 6 COLUMN 20 VALUE "2. View Customer". 05 LINE 7 COLUMN 20 VALUE "3. Update Customer". 05 LINE 8 COLUMN 20 VALUE "4. Delete Customer". 05 LINE 9 COLUMN 20 VALUE "5. Exit". 05 LINE 11 COLUMN 20 VALUE "Enter your choice: ". 05 LINE 11 COLUMN 40 PIC 9 TO MENU-CHOICE REQUIRED AUTO-SKIP.

Screen descriptions define the layout, field positions, and input behavior.

Using ACCEPT OMITTED

ACCEPT OMITTED displays and processes entire screens:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
PROCEDURE DIVISION. MAIN-PROCESS. PERFORM DISPLAY-MENU PERFORM PROCESS-MENU-CHOICE STOP RUN. DISPLAY-MENU. ACCEPT OMITTED FROM MENU-SCREEN. PROCESS-MENU-CHOICE. EVALUATE MENU-CHOICE WHEN 1 PERFORM ADD-CUSTOMER WHEN 2 PERFORM VIEW-CUSTOMER WHEN 3 PERFORM UPDATE-CUSTOMER WHEN 4 PERFORM DELETE-CUSTOMER WHEN 5 MOVE "Y" TO EXIT-FLAG WHEN OTHER DISPLAY "Invalid choice" AT LINE 15 AT COLUMN 20 END-EVALUATE. ADD-CUSTOMER. ACCEPT OMITTED FROM CUSTOMER-ENTRY-SCREEN IF CUSTOMER-ID NOT = SPACES PERFORM SAVE-CUSTOMER DISPLAY "Customer saved successfully" AT LINE 15 AT COLUMN 20 END-IF.

ACCEPT OMITTED automatically handles screen display and field input.

Screen Field Attributes

Screen fields can have various attributes for formatting and behavior:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
01 DETAILED-SCREEN. 05 LINE 3 COLUMN 10 VALUE "FIELD ATTRIBUTES EXAMPLE" HIGHLIGHT UNDERLINE. 05 LINE 5 COLUMN 10 VALUE "Required Field: ". 05 LINE 5 COLUMN 25 PIC X(20) TO REQUIRED-FIELD REQUIRED AUTO-SKIP. 05 LINE 6 COLUMN 10 VALUE "Password Field: ". 05 LINE 6 COLUMN 25 PIC X(15) TO PASSWORD-FIELD SECURE AUTO-SKIP. 05 LINE 7 COLUMN 10 VALUE "Highlighted Field: ". 05 LINE 7 COLUMN 25 PIC X(20) TO HIGHLIGHT-FIELD HIGHLIGHT AUTO-SKIP. 05 LINE 8 COLUMN 10 VALUE "Reverse Video: ". 05 LINE 8 COLUMN 25 PIC X(20) TO REVERSE-FIELD REVERSE-VIDEO AUTO-SKIP. 05 LINE 9 COLUMN 10 VALUE "Underlined Field: ". 05 LINE 9 COLUMN 25 PIC X(20) TO UNDERLINE-FIELD UNDERLINE AUTO-SKIP. 05 LINE 10 COLUMN 10 VALUE "Blinking Field: ". 05 LINE 10 COLUMN 25 PIC X(20) TO BLINK-FIELD BLINK AUTO-SKIP.

Attributes can be combined to create visually distinct and functional fields.

Screen Field Clauses

ClausePurposeExample
VALUEDisplay literal textVALUE "Enter name: "
TOInput field destinationTO CUSTOMER-NAME
FROMOutput field sourceFROM CUSTOMER-NAME
REQUIREDMandatory fieldREQUIRED
AUTO-SKIPAuto-advance cursorAUTO-SKIP
SECUREHide input charactersSECURE

Screen Formatting and Layout

Effective screen formatting creates professional, user-friendly interfaces. Proper layout, spacing, and visual organization improve usability and user experience.

Creating Professional Screens

Design screens with clear structure and visual hierarchy:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
01 PROFESSIONAL-SCREEN. 05 LINE 1 COLUMN 1 VALUE "================================================". 05 LINE 2 COLUMN 15 VALUE "CUSTOMER MANAGEMENT SYSTEM" HIGHLIGHT. 05 LINE 3 COLUMN 1 VALUE "================================================". 05 LINE 5 COLUMN 10 VALUE "Customer Information Entry Form". 05 LINE 6 COLUMN 10 VALUE "----------------------------------------". 05 LINE 8 COLUMN 10 VALUE "Customer ID: ". 05 LINE 8 COLUMN 25 PIC X(10) TO CUSTOMER-ID REQUIRED AUTO-SKIP. 05 LINE 9 COLUMN 10 VALUE "Customer Name: ". 05 LINE 9 COLUMN 25 PIC X(30) TO CUSTOMER-NAME REQUIRED AUTO-SKIP. 05 LINE 10 COLUMN 10 VALUE "Address: ". 05 LINE 10 COLUMN 25 PIC X(40) TO CUSTOMER-ADDRESS AUTO-SKIP. 05 LINE 11 COLUMN 10 VALUE "City: ". 05 LINE 11 COLUMN 25 PIC X(20) TO CUSTOMER-CITY AUTO-SKIP. 05 LINE 12 COLUMN 10 VALUE "State: ". 05 LINE 12 COLUMN 25 PIC X(2) TO CUSTOMER-STATE AUTO-SKIP. 05 LINE 13 COLUMN 10 VALUE "Zip Code: ". 05 LINE 13 COLUMN 25 PIC X(10) TO CUSTOMER-ZIP AUTO-SKIP. 05 LINE 14 COLUMN 10 VALUE "Phone: ". 05 LINE 14 COLUMN 25 PIC X(15) TO CUSTOMER-PHONE AUTO-SKIP. 05 LINE 16 COLUMN 10 VALUE "----------------------------------------". 05 LINE 18 COLUMN 10 VALUE "F1=Save F2=Cancel F3=Clear ESC=Exit". 05 LINE 20 COLUMN 1 VALUE "================================================".

Professional screens include headers, clear field labels, and navigation instructions.

Menu Design

Create clear, navigable menu systems:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
01 MAIN-MENU-SCREEN. 05 LINE 1 COLUMN 1 VALUE "================================================". 05 LINE 2 COLUMN 15 VALUE "CUSTOMER MANAGEMENT SYSTEM" HIGHLIGHT. 05 LINE 3 COLUMN 1 VALUE "================================================". 05 LINE 5 COLUMN 20 VALUE "MAIN MENU". 05 LINE 6 COLUMN 20 VALUE "---------". 05 LINE 8 COLUMN 20 VALUE "1. Customer Operations". 05 LINE 9 COLUMN 20 VALUE "2. Report Generation". 05 LINE 10 COLUMN 20 VALUE "3. System Maintenance". 05 LINE 11 COLUMN 20 VALUE "4. User Administration". 05 LINE 12 COLUMN 20 VALUE "5. Exit System". 05 LINE 14 COLUMN 20 VALUE "Enter your choice (1-5): ". 05 LINE 14 COLUMN 45 PIC 9 TO MENU-CHOICE REQUIRED AUTO-SKIP. 05 LINE 16 COLUMN 20 VALUE "----------------------------------------". 05 LINE 18 COLUMN 20 VALUE "F1=Help ESC=Exit". 05 LINE 20 COLUMN 1 VALUE "================================================". 01 CUSTOMER-MENU-SCREEN. 05 LINE 1 COLUMN 1 VALUE "================================================". 05 LINE 2 COLUMN 15 VALUE "CUSTOMER OPERATIONS" HIGHLIGHT. 05 LINE 3 COLUMN 1 VALUE "================================================". 05 LINE 5 COLUMN 20 VALUE "CUSTOMER MENU". 05 LINE 6 COLUMN 20 VALUE "-------------". 05 LINE 8 COLUMN 20 VALUE "1. Add New Customer". 05 LINE 9 COLUMN 20 VALUE "2. View Customer Details". 05 LINE 10 COLUMN 20 VALUE "3. Update Customer". 05 LINE 11 COLUMN 20 VALUE "4. Delete Customer". 05 LINE 12 COLUMN 20 VALUE "5. Search Customers". 05 LINE 13 COLUMN 20 VALUE "6. Return to Main Menu". 05 LINE 15 COLUMN 20 VALUE "Enter your choice (1-6): ". 05 LINE 15 COLUMN 45 PIC 9 TO CUSTOMER-CHOICE REQUIRED AUTO-SKIP.

Well-designed menus provide clear navigation and logical grouping of functions.

Error and Status Messages

Design effective message areas for user feedback:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
01 MESSAGE-SCREEN. 05 LINE 1 COLUMN 1 VALUE "================================================". 05 LINE 2 COLUMN 15 VALUE "CUSTOMER MANAGEMENT SYSTEM" HIGHLIGHT. 05 LINE 3 COLUMN 1 VALUE "================================================". 05 LINE 5 COLUMN 10 VALUE "Customer ID: ". 05 LINE 5 COLUMN 25 PIC X(10) TO CUSTOMER-ID REQUIRED AUTO-SKIP. 05 LINE 6 COLUMN 10 VALUE "Customer Name: ". 05 LINE 6 COLUMN 25 PIC X(30) TO CUSTOMER-NAME REQUIRED AUTO-SKIP. 05 LINE 8 COLUMN 10 VALUE "----------------------------------------". 05 LINE 10 COLUMN 10 VALUE "Status: ". 05 LINE 10 COLUMN 20 PIC X(40) FROM STATUS-MESSAGE. 05 LINE 12 COLUMN 10 VALUE "Error: ". 05 LINE 12 COLUMN 20 PIC X(40) FROM ERROR-MESSAGE HIGHLIGHT. 05 LINE 14 COLUMN 10 VALUE "----------------------------------------". 05 LINE 16 COLUMN 10 VALUE "Press ENTER to continue...". 05 LINE 18 COLUMN 1 VALUE "================================================".

Dedicated message areas provide clear feedback for user actions and errors.

Interactive Program Examples

Interactive COBOL programs use screen handling to create user-friendly applications. These examples demonstrate practical screen handling techniques.

Complete Interactive Program

A complete customer management program with screen handling:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
IDENTIFICATION DIVISION. PROGRAM-ID. CUSTOMER-MANAGER. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 MENU-CHOICE PIC 9. 01 EXIT-FLAG PIC X VALUE "N". 88 EXIT-PROGRAM VALUE "Y". 01 CUSTOMER-ID PIC X(10). 01 CUSTOMER-NAME PIC X(30). 01 CUSTOMER-ADDRESS PIC X(50). 01 CUSTOMER-PHONE PIC X(15). 01 STATUS-MESSAGE PIC X(40). 01 ERROR-MESSAGE PIC X(40). SCREEN SECTION. 01 MAIN-MENU-SCREEN. 05 LINE 1 COLUMN 1 VALUE "================================================". 05 LINE 2 COLUMN 15 VALUE "CUSTOMER MANAGEMENT SYSTEM" HIGHLIGHT. 05 LINE 3 COLUMN 1 VALUE "================================================". 05 LINE 5 COLUMN 20 VALUE "MAIN MENU". 05 LINE 6 COLUMN 20 VALUE "---------". 05 LINE 8 COLUMN 20 VALUE "1. Add Customer". 05 LINE 9 COLUMN 20 VALUE "2. View Customer". 05 LINE 10 COLUMN 20 VALUE "3. Update Customer". 05 LINE 11 COLUMN 20 VALUE "4. Delete Customer". 05 LINE 12 COLUMN 20 VALUE "5. Exit". 05 LINE 14 COLUMN 20 VALUE "Enter your choice (1-5): ". 05 LINE 14 COLUMN 45 PIC 9 TO MENU-CHOICE REQUIRED AUTO-SKIP. 01 CUSTOMER-ENTRY-SCREEN. 05 LINE 1 COLUMN 1 VALUE "================================================". 05 LINE 2 COLUMN 15 VALUE "CUSTOMER ENTRY FORM" HIGHLIGHT. 05 LINE 3 COLUMN 1 VALUE "================================================". 05 LINE 5 COLUMN 10 VALUE "Customer ID: ". 05 LINE 5 COLUMN 25 PIC X(10) TO CUSTOMER-ID REQUIRED AUTO-SKIP. 05 LINE 6 COLUMN 10 VALUE "Customer Name: ". 05 LINE 6 COLUMN 25 PIC X(30) TO CUSTOMER-NAME REQUIRED AUTO-SKIP. 05 LINE 7 COLUMN 10 VALUE "Address: ". 05 LINE 7 COLUMN 25 PIC X(50) TO CUSTOMER-ADDRESS AUTO-SKIP. 05 LINE 8 COLUMN 10 VALUE "Phone: ". 05 LINE 8 COLUMN 25 PIC X(15) TO CUSTOMER-PHONE AUTO-SKIP. 05 LINE 10 COLUMN 10 VALUE "Status: ". 05 LINE 10 COLUMN 20 PIC X(40) FROM STATUS-MESSAGE. 05 LINE 12 COLUMN 10 VALUE "Press ENTER to save, ESC to cancel". PROCEDURE DIVISION. MAIN-PROCESS. PERFORM UNTIL EXIT-PROGRAM PERFORM DISPLAY-MAIN-MENU PERFORM PROCESS-MENU-CHOICE END-PERFORM STOP RUN. DISPLAY-MAIN-MENU. ACCEPT OMITTED FROM MAIN-MENU-SCREEN. PROCESS-MENU-CHOICE. EVALUATE MENU-CHOICE WHEN 1 PERFORM ADD-CUSTOMER WHEN 2 PERFORM VIEW-CUSTOMER WHEN 3 PERFORM UPDATE-CUSTOMER WHEN 4 PERFORM DELETE-CUSTOMER WHEN 5 MOVE "Y" TO EXIT-FLAG WHEN OTHER MOVE "Invalid choice - please try again" TO ERROR-MESSAGE DISPLAY ERROR-MESSAGE AT LINE 16 AT COLUMN 20 END-EVALUATE. ADD-CUSTOMER. MOVE SPACES TO CUSTOMER-ID MOVE SPACES TO CUSTOMER-NAME MOVE SPACES TO CUSTOMER-ADDRESS MOVE SPACES TO CUSTOMER-PHONE MOVE SPACES TO STATUS-MESSAGE ACCEPT OMITTED FROM CUSTOMER-ENTRY-SCREEN IF CUSTOMER-ID NOT = SPACES AND CUSTOMER-NAME NOT = SPACES PERFORM SAVE-CUSTOMER-DATA MOVE "Customer saved successfully" TO STATUS-MESSAGE ELSE MOVE "Customer ID and Name are required" TO STATUS-MESSAGE END-IF. SAVE-CUSTOMER-DATA. * Here you would add code to save to file or database DISPLAY "Saving customer data..." AT LINE 15 AT COLUMN 10. VIEW-CUSTOMER. MOVE "View customer functionality not implemented" TO STATUS-MESSAGE DISPLAY STATUS-MESSAGE AT LINE 15 AT COLUMN 10. UPDATE-CUSTOMER. MOVE "Update customer functionality not implemented" TO STATUS-MESSAGE DISPLAY STATUS-MESSAGE AT LINE 15 AT COLUMN 10. DELETE-CUSTOMER. MOVE "Delete customer functionality not implemented" TO STATUS-MESSAGE DISPLAY STATUS-MESSAGE AT LINE 15 AT COLUMN 10.

This complete program demonstrates menu-driven interaction with proper screen handling.

Login Screen Example

A secure login screen with password handling:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
01 LOGIN-SCREEN. 05 LINE 1 COLUMN 1 VALUE "================================================". 05 LINE 2 COLUMN 15 VALUE "SYSTEM LOGIN" HIGHLIGHT. 05 LINE 3 COLUMN 1 VALUE "================================================". 05 LINE 5 COLUMN 20 VALUE "Username: ". 05 LINE 5 COLUMN 30 PIC X(20) TO USERNAME REQUIRED AUTO-SKIP. 05 LINE 6 COLUMN 20 VALUE "Password: ". 05 LINE 6 COLUMN 30 PIC X(15) TO PASSWORD SECURE REQUIRED AUTO-SKIP. 05 LINE 8 COLUMN 20 VALUE "----------------------------------------". 05 LINE 10 COLUMN 20 VALUE "Press ENTER to login, ESC to exit". 05 LINE 12 COLUMN 20 VALUE "Status: ". 05 LINE 12 COLUMN 30 PIC X(30) FROM LOGIN-STATUS. 05 LINE 14 COLUMN 1 VALUE "================================================". WORKING-STORAGE SECTION. 01 USERNAME PIC X(20). 01 PASSWORD PIC X(15). 01 LOGIN-STATUS PIC X(30). 01 LOGIN-ATTEMPTS PIC 9(2) VALUE 0. 01 MAX-ATTEMPTS PIC 9(2) VALUE 3. PROCEDURE DIVISION. LOGIN-PROCESS. PERFORM UNTIL LOGIN-ATTEMPTS >= MAX-ATTEMPTS PERFORM DISPLAY-LOGIN-SCREEN PERFORM VALIDATE-LOGIN IF LOGIN-SUCCESSFUL PERFORM MAIN-APPLICATION EXIT PERFORM ELSE ADD 1 TO LOGIN-ATTEMPTS MOVE "Invalid username or password" TO LOGIN-STATUS END-IF END-PERFORM IF LOGIN-ATTEMPTS >= MAX-ATTEMPTS MOVE "Too many login attempts - exiting" TO LOGIN-STATUS DISPLAY LOGIN-STATUS AT LINE 15 AT COLUMN 20 END-IF STOP RUN. DISPLAY-LOGIN-SCREEN. MOVE SPACES TO USERNAME MOVE SPACES TO PASSWORD MOVE SPACES TO LOGIN-STATUS ACCEPT OMITTED FROM LOGIN-SCREEN. VALIDATE-LOGIN. * Simple validation - in real applications, check against database IF USERNAME = "ADMIN" AND PASSWORD = "PASSWORD123" MOVE "Login successful" TO LOGIN-STATUS MOVE "Y" TO LOGIN-SUCCESSFUL ELSE MOVE "N" TO LOGIN-SUCCESSFUL END-IF.

This login screen demonstrates secure password input and validation.

Best Practices and Guidelines

Following these best practices ensures that your COBOL screen handling creates professional, user-friendly, and maintainable applications.

Screen Design Best Practices

  • Use consistent layouts - Maintain uniform spacing and alignment across screens
  • Provide clear navigation - Include menu options and exit instructions
  • Use descriptive labels - Make field purposes clear and unambiguous
  • Implement proper validation - Use REQUIRED clauses and programmatic validation
  • Provide user feedback - Display status messages and error information
  • Use appropriate attributes - Highlight important information and use SECURE for passwords
  • Design for usability - Group related fields and use logical tab order
  • Handle errors gracefully - Provide clear error messages and recovery options

Performance Considerations

  • Minimize screen refreshes - Only update necessary parts of the screen
  • Use efficient positioning - Plan screen layouts to minimize cursor movement
  • Optimize input validation - Validate data as early as possible
  • Handle large datasets - Use pagination for displaying large amounts of data
  • Consider terminal limitations - Design for the target terminal's capabilities
  • Use appropriate field sizes - Match field sizes to expected data lengths

Security Guidelines

  • Use SECURE for passwords - Always hide password input characters
  • Validate all input - Check for proper data types and ranges
  • Limit login attempts - Implement maximum retry limits
  • Clear sensitive data - Reset password fields after use
  • Use appropriate access controls - Implement user role-based permissions
  • Log security events - Record login attempts and access violations

Maintenance Guidelines

  • Use meaningful screen names - Choose descriptive names for screen descriptions
  • Document screen layouts - Maintain documentation of screen designs
  • Use consistent naming conventions - Follow standard naming for fields and screens
  • Separate concerns - Keep screen definitions separate from business logic
  • Test across terminals - Verify screens work on different terminal types
  • Plan for changes - Design screens to accommodate future modifications

Screen Handling Checklist

AspectCheck ItemStatus
LayoutConsistent spacing and alignment
NavigationClear menu options and exit paths
ValidationRequired fields and data validation
FeedbackStatus messages and error handling
SecurityPassword protection and access control
UsabilityIntuitive design and user guidance

Test Your Knowledge

1. What is the primary purpose of the DISPLAY statement in COBOL screen handling?

  • To read data from files
  • To output data to the screen or other devices
  • To perform calculations
  • To validate user input

2. Which statement is used to accept user input from the keyboard in COBOL?

  • READ statement
  • ACCEPT statement
  • INPUT statement
  • GET statement

3. What is the purpose of the AT LINE and AT COLUMN clauses in DISPLAY statements?

  • To specify file positions
  • To control cursor positioning on the screen
  • To define data types
  • To set program variables

4. What is a screen section in COBOL?

  • A file description
  • A collection of screen layouts and field definitions
  • A program division
  • A data validation routine

5. Which COBOL feature helps create formatted, user-friendly screens?

  • File organization
  • Screen section with ACCEPT OMITTED
  • Data validation
  • Error handling

Frequently Asked Questions