COMP-2
COMP-2 Example
Scenario - Defining, initializing, its usage and display of COMP-2 variables.
Code -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. COMP2.
AUTHOR. MTH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VAR.
05 WS-PI USAGE IS COMP-2.
05 WS-RADIUS USAGE IS COMP-2.
05 WS-AREA USAGE IS COMP-2.
PROCEDURE DIVISION.
MOVE 3.1415927 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-2 VARIABLE LENGTH: " LENGTH OF WS-AREA.
STOP RUN.
Output -
AREA OF THE CIRCLE: .31415926999999994E 03 COMP-2 VARIABLE LENGTH: 000000008
Explaining Example -
In the above example:
- Length of variables declared with COMP-2 is 8 bytes.
- COMP-2 stores the numbers in a double-precision (64-bit) floating-point format. Result 314.15926999999994 stores in the format is .31415926999999994E 03.