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

Can we move from Alphanumeric field to COMP field?


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

New User


Joined: 30 May 2013
Posts: 8
Location: India

PostPosted: Mon Jun 03, 2013 3:53 pm
Reply with quote

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
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Mon Jun 03, 2013 4:13 pm
Reply with quote

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
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Mon Jun 03, 2013 4:17 pm
Reply with quote

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
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Mon Jun 03, 2013 4:18 pm
Reply with quote

oops Sorry Pandora for repeated reply I was in edit mode and that time there was no reply for the post..
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon Jun 03, 2013 4:31 pm
Reply with quote

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
View user's profile Send private message
Mainforum

New User


Joined: 30 May 2013
Posts: 8
Location: India

PostPosted: Wed Jun 05, 2013 10:21 am
Reply with quote

Thanks for your link.
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 Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
No new posts S0C7 - Field getting overlayed COBOL Programming 2
Search our Forums:

Back to Top