Figurative Constants Example


Scenario - Initializing a variable using figurative constants.

Code -

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

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-VAR.
          05 WS-A     PIC X(5) VALUE SPACES.
          05 WS-B     PIC 9(3) VALUE ZEROES.
          05 WS-C     PIC A(7).

       PROCEDURE DIVISION.

		   MOVE SPACES    TO WS-C.
           DISPLAY "Initialized variable values: -" WS-VAR "-".
           STOP RUN.

Output -

Initialized variable values: -     000       -

Explaining Example -

In the above example:

  • WS-A is alpha-numeric variable initialized with figurative constant SPACES. So spaces placed in WS-A.
  • WS-B is a numeric variable initialized with ZEROES.
  • WS-C is a alphabetic variable assigned with figurative constant SPACES.
  • Displaying the WS-VAR displays all variable under it according to their initialization.