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
 

 

How to Convert a char to integer value in cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to Convert a char to integer value in cobol
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    Post subject:
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: 1228
Location: Israel

PostPosted: Thu Feb 25, 2010 8:36 pm    Post subject: Reply to: How to Convert a char to integer value in cobol
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    Post subject: Reply to: How to Convert a char to integer value in cobol
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    Post subject: Reply to: How to Convert a char to integer value in cobol
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: 1228
Location: Israel

PostPosted: Thu Feb 25, 2010 9:15 pm    Post subject:
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    Post subject: Reply to: How to Convert a char to integer value in cobol
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    Post subject:
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    Post subject:
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    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
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts COBOL Code Parsers and Lineage Establ... balimanja COBOL Programming 2 Tue May 02, 2017 3:30 am
No new posts Cobol upgrade - source code missing f... gthmrj IBM Tools 1 Wed Apr 26, 2017 6:04 pm
No new posts COBOL Programming Sandpit? jodrisco COBOL Programming 6 Wed Apr 12, 2017 3:47 am


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