Constant Example


Scenario - Declaring the constant variables.

Code -

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

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-VAR. 
          05 WS-PI        PIC 9V99 VALUE 3.14.
          05 WS-RADIUS    PIC 9(2).
          05 WS-AREA      PIC 9(3).9(2) VALUE ZEROES.

       PROCEDURE DIVISION.

           MOVE 5         TO WS-RADIUS.
           COMPUTE WS-AREA = WS-PI * WS-RADIUS * WS-RADIUS 
           DISPLAY "AREA OF CIRCLE:  " WS-AREA. 

           STOP RUN.

Output -

AREA OF CIRCLE:  078.50

Explaining Example -

In the above example:

  • 3.14 value is not changed in the vriable WS-PI through out the program execution. So the WS-PI is called as constant variable and 3.14 is called as constant value.