View previous topic :: View next topic
|
Author |
Message |
Mainforum
New User
Joined: 30 May 2013 Posts: 8 Location: India
|
|
|
|
Hi,
When we debug an existing code in production, we found that the value from X(3) is moved to S9(03) COMP.
The values are declared as below.
A PIC X(4) VALUE SPACE .
B PIC S9(3) COMP .
MOVE A to B.
Note: When we pass A=030 , we are getting B=300
When we pass A=120 , we are getting B=1200
We are not clear how its getting moved.
If you explain us it would be great.
Basic query:
1)Can we move from alpha numeric to COMP or numeric field? If possible, how to move a value from alpha numeric to COMP?
Thanks,
Mainforum |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
The field 'A' is ALPHANUMERIC always justified LEFT by default so spaces are treated as '0' when moved to numeric.
So to avoid the issue you could either JUSTIFY RIGHT and populate to numeric or use FUNCTION NUMVAL |
|
Back to top |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
Hi,
You are getting those displays becuase of Spaces in your input data.
yes we can move Alphanumeric to COMP/Numeric fields provided it has numeric data.
For your case use NUMVAL function like below
Code: |
COMPUTE B = FUNCTION NUMVAL(A). |
|
|
Back to top |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
oops Sorry Pandora for repeated reply I was in edit mode and that time there was no reply for the post.. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
There is a link to IBM Manuals at the top of this page. CLick on that link and open the Enterprise COBOL Language Reference manual. Find 6.2.24.1.2 Valid and invalid elementary moves and study this section carefully. It answers your question, completely, about all valid and invalid elementary MOVE statements in COBOL. From there, you can branch into internal represenations of data and figure out the results of a MOVE statement before you code it. |
|
Back to top |
|
|
Mainforum
New User
Joined: 30 May 2013 Posts: 8 Location: India
|
|
|
|
Thanks for your link. |
|
Back to top |
|
|
|