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

Zero fill when Alpha to numeric convertion


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Nov 13, 2008 5:22 am
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Nov 13, 2008 6:21 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Convert HEX to Numeric DB2 3
No new posts Find a record count/numeric is multip... COBOL Programming 1
No new posts Handling the numeric data in unstring... COBOL Programming 18
No new posts IBM DCW (data convertion workbench) IBM Tools 0
No new posts Numeric check on packed signed and un... COBOL Programming 4
Search our Forums:

Back to Top