DISPLAY String and Variable
DISPLAY String and Variable Example
Scenario - Displaying string and variable with a single DISPLAY statement.
Code -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. DISPSTRV.
AUTHOR. MTH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VAR PIC X(12) VALUE "HELLO WORLD".
PROCEDURE DIVISION.
* Display String and variable in a single line.
DISPLAY "MESSAGE: " WS-VAR.
STOP RUN.
Output -
MESSAGE: HELLO WORLD
Explaining Example -
In the above example:
- It declares a working storage variable WS-VAR capable of holding a string of up to 12 characters and initializes it with the value "HELLO WORLD".
- It displays the string "MESSAGE: " followed by the content of WS-VAR, resulting in the output "MESSAGE: HELLO WORLD" all in a single line.