IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Movement of alphanumeric data to numeric


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sandy_venkat

New User


Joined: 16 May 2007
Posts: 35
Location: India

PostPosted: Wed Oct 24, 2007 4:12 pm
Reply with quote

Hi Guys,

I checked out the previous posts of alpha numeric to numeric moves etc. I am getting a peculiar output for a small cobol pgm. Could someone help me out here.

My Code:

Code:


01  A PIC X(5).
01  B PIC 9(5).
01  C PIC 9(5) VALUE 10000.

PROCEDURE DIVISION.

MAIN-PARA.

     MOVE 'ABCDE' TO A.
     MOVE A TO B.
     ADD B TO C.
     DISPLAY 'A=' A
     DISPLAY 'B=' B.
     DISPLAY 'C=' C.

    STOP-RUN.


Could someone please tell me what the output of the code posted above would be?
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Wed Oct 24, 2007 4:20 pm
Reply with quote

sandy,

Quote:
Could someone please tell me what the output of the code posted above would be?


Why don't you post the output with the queries?
Back to top
View user's profile Send private message
ksk

Active User


Joined: 08 Jun 2006
Posts: 355
Location: New York

PostPosted: Wed Oct 24, 2007 4:21 pm
Reply with quote

What is the output you are getting? Post the same here.
Back to top
View user's profile Send private message
sandy_venkat

New User


Joined: 16 May 2007
Posts: 35
Location: India

PostPosted: Wed Oct 24, 2007 4:24 pm
Reply with quote

Hi aaru,

The output i got was this....

A = ABCDE
B = ABCD5
C = 22345

I dont understand how i got that. Should it not give a S0C7? Does a S0C7 occur during a 'MOVE' of alphanumeric to numeric or during Arithmetic operations on Numerics( that already contain Alphanumeric values )?? Could you please clear this doubt of mine...
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Wed Oct 24, 2007 4:24 pm
Reply with quote

sandy,

The MOVE will happen fine and there wont be any compilation error. But the alphabets would have been compared to integers as the destination field is numeric. A numeric data item cannot have alphanumeric data.

Please refer to the manuals as to why this is happening.
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Wed Oct 24, 2007 4:36 pm
Reply with quote

Searched and found a similar topic discussed.

http://ibmmainframes.com/viewtopic.php?t=6130
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Oct 24, 2007 7:49 pm
Reply with quote

Hello,

When moving pic x fields to some numeric field, it is a good idea to verify that the pic x fields contains valid numeric data.

What happens all tooo often is that some piece of code "works" during testing and later abends or gives unexpected/wrong results in a production execution.

For example, try using STUVW instead of ABCDE and notice what happens. . .
Back to top
View user's profile Send private message
sandy_venkat

New User


Joined: 16 May 2007
Posts: 35
Location: India

PostPosted: Thu Oct 25, 2007 10:11 am
Reply with quote

Hi guys, Thanks a lot for explaining...I got it. It treats the values as a numeric and adds the values. 'A' was taken as C1 and so on. So i got the output of 22345. I got it now. Thanks a lot..
Back to top
View user's profile Send private message
krisprems

Active Member


Joined: 27 Nov 2006
Posts: 649
Location: India

PostPosted: Thu Oct 25, 2007 12:01 pm
Reply with quote

sandy_venkat

Have this attacment reference table with you, this will help you.

dick
Can we have this attachment sticky, because this is the 2 and or 3rd time that i am attaching this. icon_exclaim.gif
Back to top
View user's profile Send private message
sandy_venkat

New User


Joined: 16 May 2007
Posts: 35
Location: India

PostPosted: Thu Oct 25, 2007 12:32 pm
Reply with quote

thanks a lot krisprems. This is indeed very useful
Back to top
View user's profile Send private message
krisprems

Active Member


Joined: 27 Nov 2006
Posts: 649
Location: India

PostPosted: Thu Oct 25, 2007 12:39 pm
Reply with quote

Enjaay! icon_kidra.gif
Back to top
View user's profile Send private message
Shanti

New User


Joined: 19 Jun 2007
Posts: 8
Location: hyderabad

PostPosted: Fri Oct 26, 2007 12:57 pm
Reply with quote

Hi Krisprems,

Could you please explain the chart that you posted. Its a bit confusing.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Oct 26, 2007 8:06 pm
Reply with quote

Hello,

The chart posted shows whether a move from one format to another is valid.

Pick your sending and receiving field types on the chart (say source = "numeric integer" and destination = "alphabetic) and follow the lines for each in the diamond until they intersect. The Y or N tells whether the move is valid or not. In the example i used, the move is not valid, therefore the N at the intersection.

The chart is in the COBOL manual.

Quote:
For example, try using STUVW instead of ABCDE and notice what happens. . .
I still suggest you do this as well.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Store the data for fixed length COBOL Programming 1
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
No new posts SCOPE PENDING option -check data DB2 2
No new posts Check data with Exception Table DB2 0
Search our Forums:

Back to Top