COMP-1 Example


Scenario - Declaring, initializing, their usage, and display of COMP-1 variables.

Code -

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

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-VAR.
          05 WS-PI           USAGE IS COMP-1.
          05 WS-RADIUS       USAGE IS COMP-1.
          05 WS-AREA         USAGE IS COMP-1.

       PROCEDURE DIVISION.

           MOVE 3.1415918    TO WS-PI.
           MOVE 10           TO WS-RADIUS.
           COMPUTE WS-AREA = WS-PI * (WS-RADIUS ** 2)

           DISPLAY "AREA OF THE CIRCLE:  " WS-AREA.
           DISPLAY "COMP-1 VARIABLE LENGTH: " LENGTH OF WS-AREA.
           STOP RUN.

Output -

AREA OF THE CIRCLE:   .31415918E 03
COMP-1 VARIABLE LENGTH: 000000004

Explaining Example -

In the above example:

  • Length of variables declared with COMP-1 is 4 bytes.
  • COMP-1 stores the numbers in a single-precision (32-bit) floating-point format. Result 314.15918 stores in the format is .31415918E 03.