DISPLAY Multiple Variables Example


Scenario - DISPLAY with multiple items.

Code -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. SIMPMULI.
       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  WS-VAR1 " " WS-VAR2.

           STOP RUN.

Output -

HELLO 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".
  • It displays the contents of WS-VAR1 and WS-VAR2 concatenated together with a space between them.
  • The DISPLAY statement outputs the content of WS-VAR1 followed by a space and then the content of WS-VAR2.