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

How to Convert a char to integer value in cobol


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

New User


Joined: 12 Feb 2010
Posts: 4
Location: hyderabad

PostPosted: Thu Feb 25, 2010 8:07 pm
Reply with quote

Hi Friends..

I am facing this problem when I was calculating premium amount.

WORKING-STORAGE SECTION.
01 WS-ALPHA PIC X(10) VALUE '1500 '.
01 WS-INTEGER PIC S9(10) USAGE COMP.
01 WS-ZONED PIC ZZZZZZZZZ9.
PROCEDURE DIVISION.

COMPUTE WS-ZONED = FUNCTION NUMVAL(WS-ALPHA).
DISPLAY 'ZONED=' WS-ZONED
COMPUTE WS-INTEGER = FUNCTION NUM(WS-ALPHA).
DISPLAY 'INTEGER=' WS-INTEGER
When I display it in spool I get

ZONED = 1500
INTEGER = 15000000

But I want to get the value as 1500 in WS-INTEGER Which is a comp.

Please give me a solution for my problem.

Thanks in advance
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Thu Feb 25, 2010 8:28 pm
Reply with quote

Hi Yousuf,

Are u sure you have posted the code correctly and have not missed anything... icon_wink.gif

Am trying the same code here, but its working fine for me...
Code:
01  WS-WORKING-VARIABLES.                               
    05  WS-WORK1                PIC X(10)  VALUE '1500'.
    05  WS-WORK2                PIC S9(10) USAGE COMP. 

COMPUTE WS-WORK2 = FUNCTION NUMVAL (WS-WORK1).
DISPLAY WS-WORK2.                             
Output
Code:
0000001500


Do let me know if I have coded anything wrong ? icon_smile.gif
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Thu Feb 25, 2010 8:36 pm
Reply with quote

I too tried your code, with only 2 minor changes:
1. corrected the FUNCTION NUM to FUNCTION NUMVAL
2. added delimiters in the DISPLAY statements
Code:
COMPUTE WS-ZONED = FUNCTION NUMVAL(WS-ALPHA).   
DISPLAY 'ZONED=/' WS-ZONED '/'                 
COMPUTE WS-INTEGER = FUNCTION NUMVAL(WS-ALPHA).
DISPLAY 'INTEGER=/' WS-INTEGER '/'
The result I received was as expected:
Code:
ZONED=/      1500/   
INTEGER=/0000001500/

Maybe you've got a compile error and are running an old version of the program ??
Back to top
View user's profile Send private message
Yousuf

New User


Joined: 12 Feb 2010
Posts: 4
Location: hyderabad

PostPosted: Thu Feb 25, 2010 9:04 pm
Reply with quote

I apologize Friends!!!!
Actually the following is the declaration for ws-alpha.
1500 is followed by 6 spaces
01 WS-ALPHA PIC X(10) VALUE '1500 '.

Can you please help me in this again....
Thanks in Advance
Back to top
View user's profile Send private message
Yousuf

New User


Joined: 12 Feb 2010
Posts: 4
Location: hyderabad

PostPosted: Thu Feb 25, 2010 9:07 pm
Reply with quote

Hi Friends!!!!
I am declaring 01 WS-ALPHA PIC X(10) VALUE '1500BBBBBB'.
B =spaces.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Thu Feb 25, 2010 9:15 pm
Reply with quote

That is what I used too in my test program:
Code:
01 WS-ALPHA PIC X(10) VALUE '1500 '.

I added a DISPLAY just to be sure:
Code:
ALPHA=/1500      / 
ZONED=/      1500/ 
INTEGER=/0000001500/


Have you corrected this line of yours:
Code:
COMPUTE WS-INTEGER = FUNCTION NUM(WS-ALPHA).
Back to top
View user's profile Send private message
Yousuf

New User


Joined: 12 Feb 2010
Posts: 4
Location: hyderabad

PostPosted: Thu Feb 25, 2010 9:26 pm
Reply with quote

Hi Marso!!!Thanks for the reply.
I have wrongly written the NUM to NUMVAL
But If I declare ws-work as s9(5) comp
05 WS-WORK2 PIC S9(05) USAGE COMP.

I am getting the display as 15000000.

Thanks for now.....
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Thu Feb 25, 2010 9:42 pm
Reply with quote

icon_eek.gif icon_eek.gif icon_eek.gif

Got a feeling that your "self review" time is very minimal... Have a look at your code once again... you would be able to find the problem yourself...

Please do post your code if you are not able to find the problem...
Suggest using BBcode to display your code
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Fri Feb 26, 2010 8:57 pm
Reply with quote

Hi Yousuf,

Use cut&paste to put your example into the thread and use BB Code (this gives you the green text on a black background and preserves the original spacing).

This will faithfully reproduce what you have, including any undetected errors.
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 each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top