To
Numeric field.
Let us take an example and analyze each case along with their solutions.
The following Table shows the Input records and the Expected Output
COBOL statements:
Result:
OUTPUT IS : 1234567890
Here even tough the Input field is Alphanumeric but as the Data in the field is
numeric and has no spaces. Thus the simple MOVE statement will work.
CASE 2 & 3:
COBOL statements:
ERROR!
The reason being there are spaces in the input data, which are Characters.
And we cannot move characters into a numeric field.
The simple MOVE statement will not work.
1. Using an array:
01 WS-ARR.
05 WS-INPUT-ARR OCCURS 10 TIMES
PIC X (1).
01 WS-IDX PIC 9(02) VALUE ZEROES.
**************************************************************
* IT COUNTS THE NUMBER CHARACTERS BEFORE THE FIRST SPACE *
* IS ENCOUNTERED AND MOVES THE VALUE OF THAT COUNT TO WS-IDX *
**************************************************************
INSPECT WS-INPUT TALLYING WS-IDX FOR CHARACTERS BEFORE INITIAL
SPACES.
MOVE WS-INPUT (1:WS-IDX) TO WS-OUTPUT.
The NUMVAL function returns the numeric value represented by the character
string specified by parameter-1. Leading and trailing spaces are ignored.
Syntax