Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more ➡
Download
Standard view
Full view
of .
Add note
Save to My Library
Sync to mobile
Look up keyword
Like this
16Activity
×
0 of .
Results for:
No results containing your search query
P. 1
How to MOVE an Alphanumeric Field

How to MOVE an Alphanumeric Field

Ratings: (0)|Views: 6,562|Likes:
Published by sxdasgu

More info:

Published by: sxdasgu on Jan 21, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, DOC, TXT or read online from Scribd
See More
See less

02/08/2012

pdf

text

original

 
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 *************************************************************** 

Activity (16)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
ketaki.k14 liked this
Rajashekar Peddi liked this
adityamahendru liked this
infossiva liked this
scarceboyz liked this
nandaec862897 liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->