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
 

 

Zero fill when Alpha to numeric convertion

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
abin

Active User


Joined: 14 Aug 2006
Posts: 198

PostPosted: Thu Nov 13, 2008 5:09 am    Post subject: Zero fill when Alpha to numeric convertion
Reply with quote

Hi,

Can somebody explain this.

Here is my data definition
Code:
01  WS-TEST.                                       
    05  WS-ALPHA                     PIC X(12)     
                    VALUE '1234567     '.         
    05  WS-NUMERIC                   PIC 9(12).   


Here is my code
Code:
INITIALIZE WS-NUMERIC                 
DISPLAY WS-ALPHA                       
DISPLAY WS-NUMERIC                     
MOVE WS-ALPHA TO WS-NUMERIC           
DISPLAY WS-NUMERIC                     
GOBACK                                 


and here is what I get

Code:

1234567       
000000000000   
1234567    0   



Here is the question what is the 0 doing at end of my output 1234567 0
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7989
Location: Bellevue, IA

PostPosted: Thu Nov 13, 2008 5:22 am    Post subject:
Reply with quote

Code:
         MVC   12(12,8),0(8)
         OI    23(8),X'F0'

I tested a similar program and here's the assembler generated. COBOL is forcing the last byte to have an unsigned value, which changes the space to a zero.
Back to top
View user's profile Send private message
abin

Active User


Joined: 14 Aug 2006
Posts: 198

PostPosted: Thu Nov 13, 2008 6:16 am    Post subject:
Reply with quote

Robert,

Thanks for help. The code I used was ugly. This is how I fixed it.

Quote:
COMPUTE WS-NUMERIC = FUNCTION NUMVAL(WS-ALPHA)


I hope this is the best way.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7989
Location: Bellevue, IA

PostPosted: Thu Nov 13, 2008 6:21 am    Post subject:
Reply with quote

Glad I could help. Your fix might or might not be the best way, but it'll work and is easy to maintain -- stick with it.
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 Converting decimal to numeric using I... Balaryan DFSORT/ICETOOL 4 Thu Feb 02, 2017 11:27 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts Casting a Binary Number to Numeric in... Bob Steinkraus Java & MQSeries 6 Tue Aug 09, 2016 5:58 pm
This topic is locked: you cannot edit posts or make replies. Alphanumeric to Numeric move on UNIX mistah kurtz COBOL Programming 16 Wed Jul 27, 2016 8:47 pm
No new posts pass numeric value of length 14 to ti... Ralph Zbrog Java & MQSeries 4 Fri Jan 15, 2016 3:20 pm


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