Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Can we move from Alphanumeric field to COMP field?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Can we move from Alphanumeric field to COMP field?
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

Moderator


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

PostPosted: Mon Jun 03, 2013 4:13 pm    Post subject:
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: 269
Location: Mumbai

PostPosted: Mon Jun 03, 2013 4:17 pm    Post subject:
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: 269
Location: Mumbai

PostPosted: Mon Jun 03, 2013 4:18 pm    Post subject:
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: 7909
Location: Bellevue, IA

PostPosted: Mon Jun 03, 2013 4:31 pm    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 1 Tue Dec 06, 2016 8:04 pm
No new posts How to move a long alphanumeric data ... lind sh COBOL Programming 6 Mon Dec 05, 2016 7:51 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us