Read without ads and support Scribd by becoming a Scribd Premium Reader.
 
How to MOVE an Alphanumeric FieldToNumeric field. 
An Alphanumeric to numeric move is not a valid move in COBOL.There is an
exceptional case
where this move is permissible which will bediscussed in the text.The Moves in Cobol are always guided by the 'Receiving field' in Cobol. If the receiving field is declared as numeric then the move is called a numericmove.
 
Let us take an example and analyze each case along with their solutions.
Let us consider the following fields: - WS-INPUTPIC X(10).WS-OUTPUTPIC 9(10). The following Table shows the Input records and the Expected Output 
CASE 1: (
Exceptional case
) 
COBOL statements: MOVE WS-INPUTTO WS-OUTPUT.DISPLAY “ OUTPUT IS : “ WS-OUTPUT. Result:OUTPUT IS : 1234567890 Here even tough the Input field is Alphanumeric but as the Data in the field isnumeric and has
no spaces
. Thus the simple
MOVE statement will work.
 
 
CaseINPUT RECORDOUTPUT RECORD
1.123456789012345678902.1010700000101073.1010060000101006
 
CASE 2 & 3:
 COBOL statements: MOVE WS-INPUTTO WS-OUTPUT.DISPLAY “ OUTPUT IS : “ WS-OUTPUT.
 ERROR!
The reason being there arespacesin the input data, which are Characters.And we cannot move characters into a numeric field.
The simple
MOVE statement will not work. Now the Question arises what to do if we need the numeric values of analphanumeric variable?
 
The above result can be achieved in 3 ways:
1.
Using an array.
 
2.
Using INSPECT statement.
 
3.
NUMVAL () Function.
 
1.
Using an array:
 
01 WS-ARR.05 WS-INPUT-ARR OCCURS 10 TIMESPIC X (1).01 WS-IDXPIC 9(02) VALUE ZEROES.MOVE WS-INPUT TO WS-ARR.PERFORM VARYING WS-IDX FROM 1 BY 1 UNTIL WS-INOUT-ARR (WS-IDX) ISNOT NUMERIC.MOVE WS-INPUT (1:WS-IDX) TO WS-OUTPUT. DISPLAY “ OUTPUT IS : “ WS-OUTPUT. Result for INPUT RECORD 2:OUTPUT IS : 0000010107 Result for INPUT RECORD 3:OUTPUT IS : 0000101006 
This particular method is not considered a good programming practice.
 
2.
Using INSPECT Statement:
 
*************************************************************** IT COUNTS THE NUMBER CHARACTERS BEFORE THE FIRST SPACE ** IS ENCOUNTERED AND MOVES THE VALUE OF THAT COUNT TO WS-IDX *************************************************************** 
Search History:
Searching...
Result 00 of 00
00 results for result for
  • p.
  • Notes
    Load more