DISPLAY Computation Example


Scenario - Describes how DISPLAY computation is used in COBOL programming.

Code -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. DISPLAYC.
       AUTHOR. MTH.

       DATA DIVISION. 
       WORKING-STORAGE SECTION. 
       01 WS-VAR.
          05 WS-VAR1          PIC 9(06) USAGE DISPLAY.
          05 WS-VAR2          PIC 9(06).

       PROCEDURE DIVISION. 
           DISPLAY "WS-VAR1 (DISPLAY COMPUTATION) LENGTH IS: " 
                                      LENGTH OF WS-VAR1.
           DISPLAY "WS-VAR2 LENGTH IS: "  LENGTH OF WS-VAR2.
           STOP RUN.

Output -

WS-VAR1 (DISPLAY COMPUTATION) LENGTH IS: 000000006  
WS-VAR2 LENGTH IS: 000000006

Explaining Example -

In the above example:

  • WS-VAR1 and WS-VAR2 variables are declared with 9(06).
  • WS-VAR1 with usage DISPLAY computation and WS-VAR2 declared without DISPLAY computation, but the DISPLAY computation might applied by default. So, WS-VAR1 and WS-VAR2 have the same length when displaying length.