View previous topic :: View next topic
|
Author |
Message |
sandy_venkat
New User
Joined: 16 May 2007 Posts: 35 Location: India
|
|
|
|
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 |
|
|
Aaru
Senior Member
Joined: 03 Jul 2007 Posts: 1287 Location: Chennai, India
|
|
|
|
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 |
|
|
ksk
Active User
Joined: 08 Jun 2006 Posts: 355 Location: New York
|
|
|
|
What is the output you are getting? Post the same here. |
|
Back to top |
|
|
sandy_venkat
New User
Joined: 16 May 2007 Posts: 35 Location: India
|
|
|
|
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 |
|
|
Aaru
Senior Member
Joined: 03 Jul 2007 Posts: 1287 Location: Chennai, India
|
|
|
|
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 |
|
|
Aaru
Senior Member
Joined: 03 Jul 2007 Posts: 1287 Location: Chennai, India
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
sandy_venkat
New User
Joined: 16 May 2007 Posts: 35 Location: India
|
|
|
|
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 |
|
|
krisprems
Active Member
Joined: 27 Nov 2006 Posts: 649 Location: India
|
|
|
|
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. |
|
Back to top |
|
|
sandy_venkat
New User
Joined: 16 May 2007 Posts: 35 Location: India
|
|
|
|
thanks a lot krisprems. This is indeed very useful |
|
Back to top |
|
|
krisprems
Active Member
Joined: 27 Nov 2006 Posts: 649 Location: India
|
|
|
|
Enjaay! |
|
Back to top |
|
|
Shanti
New User
Joined: 19 Jun 2007 Posts: 8 Location: hyderabad
|
|
|
|
Hi Krisprems,
Could you please explain the chart that you posted. Its a bit confusing. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
|