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.
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.
1234567891011121314151617181920SCREEN 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.
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.
1234567891011*> 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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899*> 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.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556*> 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.
1234567891011121314151617181920212223242526272829303132333435*> 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.
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.
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.
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.
1. What is the primary purpose of the UNDERLINE attribute in COBOL?
2. In which COBOL section is the UNDERLINE clause used?
3. At what level can the UNDERLINE clause be used?
4. What determines whether the UNDERLINE attribute will actually appear on the screen?
5. When can the UNDERLINE attribute be applied?
Learn about the Screen Section and screen handling in COBOL programs
Understanding the ACCEPT statement for input operations
Using the DISPLAY statement for output operations
Overview of all screen attributes including HIGHLIGHT, BLINK, and REVERSE-VIDEO