Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 8165
Location: East Dubuque, Illinois, USA

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: 8165
Location: East Dubuque, Illinois, USA

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 File Aid tool to compare numeric data balaji81_k Compuware & Other Tools 2 Tue Sep 26, 2017 3:35 am
No new posts Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am
No new posts Return a Non Numeric value from REXX Learncoholic CLIST & REXX 3 Fri Sep 01, 2017 8:33 pm
No new posts Select numeric portion from CHAR data... balaji81_k DB2 6 Sat Aug 19, 2017 1:51 am
No new posts Validate if a Value from the file is ... balacsv2 COBOL Programming 8 Mon Jun 19, 2017 11:52 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us