COBOL Tutorial

COBOL UNDERLINE Attribute

The UNDERLINE attribute in COBOL is a screen display enhancement feature used to visually emphasize text or fields on the screen by displaying them with an underline. This attribute is particularly useful for highlighting required input fields, distinguishing labels from data, creating visual hierarchy in forms, and improving readability in data entry screens. UNDERLINE is essential for creating effective user interfaces in terminal-based applications where visual cues help guide users through data entry processes and draw attention to important information.

Understanding UNDERLINE Attribute

The UNDERLINE attribute is a screen formatting feature that makes text appear underlined on the screen during both ACCEPT and DISPLAY operations. It's used in the Screen Section at the elementary level to specify that a particular screen item should be displayed with an underline. The effectiveness of this attribute depends on the terminal or display device capabilities - if the device does not support underlining, the clause may be ignored.

Key Characteristics:

  • Used only at the elementary level in Screen Section
  • Applicable during both ACCEPT and DISPLAY operations
  • Requires terminal support for underlining
  • Can be combined with other screen attributes
  • Provides visual emphasis and hierarchy
cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
SCREEN SECTION. 01 DATA-ENTRY-SCREEN. 05 LINE 5 COL 10 VALUE "Customer Name:". 05 LINE 5 COL 25 PIC X(30) TO CUSTOMER-NAME UNDERLINE. 05 LINE 7 COL 10 VALUE "Account Number:". 05 LINE 7 COL 25 PIC 9(10) TO ACCOUNT-NUMBER UNDERLINE. 05 LINE 9 COL 10 VALUE "Email Address:". 05 LINE 9 COL 25 PIC X(50) TO EMAIL-ADDRESS UNDERLINE. 01 DISPLAY-SCREEN. 05 LINE 12 COL 10 VALUE "Required Fields:" UNDERLINE. 05 LINE 14 COL 10 VALUE "Customer Name:". 05 LINE 14 COL 25 PIC X(30) FROM CUSTOMER-NAME UNDERLINE. 05 LINE 16 COL 10 VALUE "Account Number:". 05 LINE 16 COL 25 PIC 9(10) FROM ACCOUNT-NUMBER UNDERLINE. PROCEDURE DIVISION. DISPLAY-ENTRY-SCREEN. DISPLAY DATA-ENTRY-SCREEN. ACCEPT DATA-ENTRY-SCREEN.

Basic Syntax and Usage

The UNDERLINE clause follows a simple syntax pattern. It must be specified at the elementary level within the Screen Section, and it applies to the field during both input (ACCEPT) and output (DISPLAY) operations.

cobol
1
2
3
4
5
6
7
8
9
10
11
*> Basic UNDERLINE syntax SCREEN SECTION. 01 SCREEN-ITEMS. *> Elementary item with UNDERLINE 05 USER-NAME PIC X(20) UNDERLINE. *> UNDERLINE with other attributes 05 PASSWORD PIC X(20) UNDERLINE HIGHLIGHT. *> UNDERLINE in display field 05 STATUS-MESSAGE PIC X(40) UNDERLINE REVERSE-VIDEO.

Syntax Rules:

  • UNDERLINE must be specified at the elementary level
  • Cannot be used at group level
  • Placed after the PICTURE clause
  • Can be combined with other screen attributes
  • Works with both TO (input) and FROM (output) clauses

Data Entry Forms with UNDERLINE

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
*> Comprehensive data entry form with underlined fields DATA DIVISION. WORKING-STORAGE SECTION. 01 CUSTOMER-DATA. 05 CUSTOMER-ID PIC 9(8). 05 CUSTOMER-NAME PIC X(40). 05 CUSTOMER-ADDRESS PIC X(60). 05 CUSTOMER-PHONE PIC X(15). 05 CUSTOMER-EMAIL PIC X(50). 05 CUSTOMER-STATUS PIC X. 88 ACTIVE-CUSTOMER VALUE 'A'. 88 INACTIVE-CUSTOMER VALUE 'I'. 01 VALIDATION-FLAGS. 05 NAME-VALID PIC X VALUE 'N'. 88 VALID-NAME VALUE 'Y'. 05 EMAIL-VALID PIC X VALUE 'N'. 88 VALID-EMAIL VALUE 'Y'. SCREEN SECTION. 01 CUSTOMER-ENTRY-FORM. 05 BLANK SCREEN. 05 LINE 2 COL 30 VALUE "CUSTOMER REGISTRATION FORM" HIGHLIGHT UNDERLINE. *> Required fields with UNDERLINE 05 LINE 5 COL 5 VALUE "Customer ID:". 05 LINE 5 COL 20 PIC 9(8) TO CUSTOMER-ID UNDERLINE REQUIRED. 05 LINE 7 COL 5 VALUE "Customer Name:". 05 LINE 7 COL 20 PIC X(40) TO CUSTOMER-NAME UNDERLINE REQUIRED. 05 LINE 9 COL 5 VALUE "Address:". 05 LINE 9 COL 20 PIC X(60) TO CUSTOMER-ADDRESS UNDERLINE. 05 LINE 11 COL 5 VALUE "Phone:". 05 LINE 11 COL 20 PIC X(15) TO CUSTOMER-PHONE UNDERLINE. 05 LINE 13 COL 5 VALUE "Email:". 05 LINE 13 COL 20 PIC X(50) TO CUSTOMER-EMAIL UNDERLINE REQUIRED. *> Status field with conditional UNDERLINE 05 LINE 15 COL 5 VALUE "Status:". 05 LINE 15 COL 20 PIC X TO CUSTOMER-STATUS UNDERLINE WHEN ACTIVE-CUSTOMER. *> Validation messages 05 LINE 17 COL 5 VALUE "Name is required" UNDERLINE FOREGROUND-COLOR 4 WHEN NOT VALID-NAME. 05 LINE 18 COL 5 VALUE "Email is required" UNDERLINE FOREGROUND-COLOR 4 WHEN NOT VALID-EMAIL. 05 LINE 22 COL 10 VALUE "Press F1 to save, F3 to cancel" UNDERLINE. PROCEDURE DIVISION. MAIN-PROCEDURE. PERFORM DISPLAY-ENTRY-FORM PERFORM ACCEPT-CUSTOMER-DATA PERFORM VALIDATE-INPUT IF VALID-NAME AND VALID-EMAIL PERFORM SAVE-CUSTOMER-RECORD END-IF STOP RUN. DISPLAY-ENTRY-FORM. DISPLAY CUSTOMER-ENTRY-FORM. ACCEPT-CUSTOMER-DATA. ACCEPT CUSTOMER-ENTRY-FORM. VALIDATE-INPUT. IF CUSTOMER-NAME = SPACES SET VALID-NAME TO FALSE ELSE SET VALID-NAME TO TRUE END-IF. IF CUSTOMER-EMAIL = SPACES SET VALID-EMAIL TO FALSE ELSE PERFORM VALIDATE-EMAIL-FORMAT END-IF. VALIDATE-EMAIL-FORMAT. *> Basic email validation IF CUSTOMER-EMAIL(1:1) = SPACE OR CUSTOMER-EMAIL(FUNCTION LENGTH(CUSTOMER-EMAIL):1) = SPACE SET VALID-EMAIL TO FALSE ELSE SET VALID-EMAIL TO TRUE END-IF.

Displaying Information with UNDERLINE

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
*> Displaying data with underlined emphasis DATA DIVISION. WORKING-STORAGE SECTION. 01 REPORT-HEADER. 05 REPORT-TITLE PIC X(50) VALUE "MONTHLY SALES REPORT". 05 REPORT-DATE PIC X(10). 05 REPORT-PERIOD PIC X(20). 01 SALES-DATA. 05 PRODUCT-NAME PIC X(30). 05 SALES-AMOUNT PIC 9(10)V99. 05 QUANTITY-SOLD PIC 9(6). 05 SALES-REP PIC X(25). SCREEN SECTION. 01 REPORT-DISPLAY-SCREEN. 05 BLANK SCREEN. *> Underlined header section 05 LINE 2 COL 15 FROM REPORT-TITLE UNDERLINE HIGHLIGHT. 05 LINE 3 COL 15 VALUE "Date:". 05 LINE 3 COL 22 FROM REPORT-DATE UNDERLINE. 05 LINE 3 COL 35 VALUE "Period:". 05 LINE 3 COL 44 FROM REPORT-PERIOD UNDERLINE. *> Column headers with UNDERLINE 05 LINE 6 COL 5 VALUE "Product Name" UNDERLINE. 05 LINE 6 COL 25 VALUE "Amount" UNDERLINE. 05 LINE 6 COL 35 VALUE "Quantity" UNDERLINE. 05 LINE 6 COL 45 VALUE "Sales Rep" UNDERLINE. *> Data rows 05 LINE 8 COL 5 FROM PRODUCT-NAME. 05 LINE 8 COL 25 FROM SALES-AMOUNT. 05 LINE 8 COL 35 FROM QUANTITY-SOLD. 05 LINE 8 COL 45 FROM SALES-REP UNDERLINE. *> Total line with UNDERLINE 05 LINE 20 COL 5 VALUE "TOTAL:" UNDERLINE HIGHLIGHT. 05 LINE 20 COL 25 FROM TOTAL-SALES-AMOUNT UNDERLINE HIGHLIGHT. PROCEDURE DIVISION. DISPLAY-REPORT. PERFORM INITIALIZE-REPORT PERFORM DISPLAY-REPORT-HEADER PERFORM DISPLAY-SALES-DATA PERFORM DISPLAY-TOTALS ACCEPT DUMMY-FIELD. DISPLAY-REPORT-HEADER. MOVE FUNCTION CURRENT-DATE(1:8) TO REPORT-DATE MOVE "January 2024" TO REPORT-PERIOD DISPLAY REPORT-DISPLAY-SCREEN.

Combining UNDERLINE with Other Attributes

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
*> Using UNDERLINE with other screen attributes SCREEN SECTION. 01 ENHANCED-SCREEN. 05 BLANK SCREEN. *> UNDERLINE with HIGHLIGHT 05 LINE 3 COL 10 VALUE "Important Notice" UNDERLINE HIGHLIGHT. *> UNDERLINE with REVERSE-VIDEO 05 LINE 5 COL 10 VALUE "System Status" UNDERLINE REVERSE-VIDEO. *> UNDERLINE with BLINK for urgent messages 05 LINE 7 COL 10 VALUE "URGENT: Action Required" UNDERLINE BLINK FOREGROUND-COLOR 4. *> UNDERLINE with color 05 LINE 9 COL 10 VALUE "Warning Message" UNDERLINE FOREGROUND-COLOR 3. *> UNDERLINE with multiple attributes 05 LINE 11 COL 10 VALUE "Critical Alert" UNDERLINE HIGHLIGHT BLINK FOREGROUND-COLOR 4. *> Conditional UNDERLINE 05 LINE 13 COL 10 VALUE "Status: Active" UNDERLINE WHEN SYSTEM-ACTIVE. 05 LINE 13 COL 10 VALUE "Status: Inactive" UNDERLINE WHEN SYSTEM-INACTIVE. PROCEDURE DIVISION. DISPLAY-ENHANCED-SCREEN. DISPLAY ENHANCED-SCREEN. ACCEPT DUMMY-FIELD.

Best Practices

  • Use UNDERLINE to highlight required input fields
  • Apply UNDERLINE to column headers in tabular displays
  • Use UNDERLINE to distinguish labels from data values
  • Combine UNDERLINE with other attributes for emphasis
  • Test on target terminals to ensure proper display
  • Use UNDERLINE consistently throughout your application
  • Consider accessibility - provide alternative cues if UNDERLINE is not supported

When to Use UNDERLINE

  • Required Fields: Highlight mandatory input fields
  • Headers: Emphasize section headers and column titles
  • Important Data: Draw attention to critical information
  • Form Labels: Distinguish labels from input areas
  • Validation: Indicate fields that need correction
  • Navigation: Highlight menu options or navigation elements

Common Issues and Solutions

Issue: UNDERLINE not appearing on screen

Cause: The terminal or display device may not support underlining.

Solution: Test on your target environment. If UNDERLINE is not supported, use alternative visual cues such as HIGHLIGHT, REVERSE-VIDEO, or color attributes to achieve similar emphasis.

Issue: UNDERLINE at group level causes error

Cause: UNDERLINE can only be used at the elementary level, not at group level.

Solution: Move the UNDERLINE clause to each elementary item within the group that needs underlining. Each field must have UNDERLINE specified individually.

Issue: UNDERLINE appears in wrong location

Cause: UNDERLINE may be applied to the wrong field or positioning may be incorrect.

Solution: Verify that UNDERLINE is specified on the correct elementary item. Check LINE and COL positioning to ensure fields are displayed in the intended locations.

Test Your Knowledge

1. What is the primary purpose of the UNDERLINE attribute in COBOL?

  • To underline text in printed reports
  • To display text with an underline on the screen during ACCEPT and DISPLAY operations
  • To format data in files
  • To validate input data

2. In which COBOL section is the UNDERLINE clause used?

  • WORKING-STORAGE SECTION
  • SCREEN SECTION
  • FILE SECTION
  • LINKAGE SECTION

3. At what level can the UNDERLINE clause be used?

  • Group level only
  • Elementary level only
  • Both group and elementary levels
  • Only in PROCEDURE DIVISION

4. What determines whether the UNDERLINE attribute will actually appear on the screen?

  • The COBOL compiler version
  • The terminal or display device capabilities
  • The operating system
  • The program logic

5. When can the UNDERLINE attribute be applied?

  • Only during DISPLAY operations
  • Only during ACCEPT operations
  • During both ACCEPT and DISPLAY operations
  • Only in printed output