💻 COBOL
COBOL DISPLAY Statement
Beginner 🕑 10 min read
👁 3 views
COBOL DISPLAY Statement
The DISPLAY statement outputs data to the console or other output device.
Syntax
DISPLAY identifier/literal [identifier/literal ...]
[UPON mnemonic-name]
[WITH NO ADVANCING]
Example Program
IDENTIFICATION DIVISION.
PROGRAM-ID. DISPLAY-DEMO.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-NAME PIC X(20) VALUE 'John Smith'.
01 WS-SALARY PIC 9(7)V99 VALUE 55000.00.
01 WS-EDITED-SAL PIC $$$,$$$,$$9.99.
01 WS-COUNTER PIC 99 VALUE 0.
01 WS-HEADER PIC X(40) VALUE ALL '='.
PROCEDURE DIVISION.
* Simple display
DISPLAY 'Hello, COBOL World!'
* Display with variable
DISPLAY 'Employee: ' WS-NAME
* Display multiple items
MOVE WS-SALARY TO WS-EDITED-SAL
DISPLAY 'Name: ' WS-NAME ' Salary: ' WS-EDITED-SAL
* Display with formatting
DISPLAY WS-HEADER
DISPLAY ' EMPLOYEE REPORT'
DISPLAY WS-HEADER
* Display in a loop
DISPLAY ' '
DISPLAY 'Counting:'
PERFORM VARYING WS-COUNTER FROM 1 BY 1
UNTIL WS-COUNTER > 5
DISPLAY ' Count: ' WS-COUNTER
END-PERFORM
* Display without new line
DISPLAY 'Processing' WITH NO ADVANCING
DISPLAY '.' WITH NO ADVANCING
DISPLAY '.' WITH NO ADVANCING
DISPLAY '.' WITH NO ADVANCING
DISPLAY ' Done!'
* Display special values
DISPLAY 'Spaces: [' SPACES ']'
DISPLAY 'Zeros: [' ZEROS ']'
DISPLAY 'Quote: [' QUOTE ']'
STOP RUN.
Expected Output
Hello, COBOL World!
Employee: John Smith
Name: John Smith Salary: $55,000.00
========================================
EMPLOYEE REPORT
========================================
Counting:
Count: 01
Count: 02
Count: 03
Count: 04
Count: 05
Processing... Done!
Spaces: [ ]
Zeros: [0000000000]
Quote: [""]
Key Points
- Multiple items concatenated on one line
- WITH NO ADVANCING suppresses newline
- UPON specifies output device
- Figurative constants: SPACES, ZEROS, QUOTES
- Essential for debugging and user output