Numeric Data Type
Numeric Data Type Example
Scenario - Describes how the numeric data aligns in COBOL variables.
Code -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. NUMERICJ.
AUTHOR. MTH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VAR.
05 NUMERIC-J1 PIC 9(03).
05 NUMERIC-J2 PIC 9(09).
PROCEDURE DIVISION.
MOVE 256128 TO NUMERIC-J1
NUMERIC-J2.
DISPLAY 'NUMERIC-J1: ' NUMERIC-J1.
DISPLAY 'NUMERIC-J2: ' NUMERIC-J2.
STOP RUN.
Output -
NUMERIC-J1: 128 NUMERIC-J2: 000256128
Explaining Example -
In the above example:
- NUMERIC-J1 is declared with length 3, and NUMERIC-J2 is declared with length 9. 256128 value moved to both fields.
- After moving, NUMERIC-J1 is smaller than the value passed. Because of the right justification, the value should move from right to left up to the length declared. So NUMERIC-J1 had the value 128.
- After moving, NUMERIC-J2 is larger than the value passed. Because of the right justification, the value should move from right to left up to the length declared. So NUMERIC-J2 had the value 000256128.