Numeric Data Type

The numeric data type is used to declare variables to store the numeric or decimal values. Numeric values are the combination of 0 to 9 numbers. The numeric data type uses the character '9' in the PICTURE clause of the data description.

Each digit in the number should have been counted and specified with the data type definition using the PICTURE clause. For Example - Declaring a variable to store a 3-digit value should have the declaration as 999 or 9(3).

Syntax -

       01 ws-variable      PIC 9(var-length) 
	                      [VALUE number].
Note! All statements coded in [ ] are optional.

Example -

01 WS-VAR      PIC 9(03) VALUE 123.
  • ws-variable - specifies the variable name. From example, it is WS-VAR.
  • var-length - specifies the number of digits in the value. The maximum length is 18 digits. From example, it is 03.
  • input-string - specifies the string assigned to the variable during the declaration. From example, it is 123.

Rules -

  • The numeric data type maximum length is 18 digits in the PICTURE clause (9(18)) using the default compiler option ARITH(COMPAT). If using ARITH(EXTEND), up to 31 digits can be coded in the PICTURE clause.
  • Numeric data type can code with a combination of other data types P(actual decimal point), S(sign), and V(virtual decimal point).
  • All USAGE clauses are applicable for numeric data type. The variable length is calculated based on the USAGE clause used during the declaration.
  • If no USAGE clause is coded, DISPLAY computation is applied to the declaration. i.e., i.e., 1 character = 1 byte.

Alignment | Justification -

  • The numeric data type is right justified by default, and the data in all numeric variables are right justified automatically.
  • The leftmost characters are truncated if the input data is larger than the variable size. For example – the variable declared with 9(4) and the input data is 12345, the variable contains only 2345.
  • Suppose the input data is smaller than the receiving variable. In that case, the unused positions at the left are filled with zeroes.

Practical Example -

Scenario - Example describes the numeric variable declaration, justification, and truncation.

Code -

       AUTHOR. MTH.

       01 WS-VAR.
	  * Variable with shorter length than the passing input data
	      05 WS-NUM-SVAR   PIC 9(03).
	  * Variable with larger length than the passing input data
          05 WS-NUM-LVAR   PIC 9(09). 

           MOVE 123456   TO  WS-NUM-SVAR 

           DISPLAY "WS-NUM-SVAR:  -" WS-NUM-SVAR "-". 
           DISPLAY "WS-NUM-LVAR:  -" WS-NUM-LVAR "-". 
           STOP RUN.

Output -

WS-NUM-SVAR:  -456-       
WS-NUM-LVAR:  -000123456- 
Note! In the above example, '-' is used to show the boundaries of the data.