Simple DISPLAY
Simple DISPLAY Example
Scenario - Basic DISPLAY usage in COBOL program.
Code -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. SIMPDISP.
AUTHOR. MTH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VAR.
05 WS-VAR1 PIC X(05) VALUE 'HELLO'.
05 WS-VAR2 PIC X(05) VALUE 'WORLD'.
PROCEDURE DIVISION.
* Simple DISPLAY
DISPLAY "MESSAGE1: " WS-VAR1.
DISPLAY "MESSAGE2: " WS-VAR2.
STOP RUN.
Output -
MESSAGE1: HELLO MESSAGE2: WORLD
Explaining Example -
In the above example:
- It declares two variables, WS-VAR1 and WS-VAR2, each capable of holding 5 characters.
- WS-VAR1 is initialized with the value "HELLO" and WS-VAR2 is initialized with the value "WORLD".
- The DISPLAY statement outputs "MESSAGE1: " followed by the content of WS-VAR1 and "MESSAGE2: " followed by the content of WS-VAR2.