# Alphanumeric to decimal conversion logic

Author Message
vinu78

Active User

Joined: 02 Oct 2008
Posts: 179
Location: India

Posted: Tue Apr 16, 2013 11:00 am

Hi All,

My reqt is to accept alphanumeric value as input and the output should be as mentioned below.

01 WS-INPUT PIC X(10)
01 WS-OUTPUT PIC X(10)

 Code: Input                  Output 4006.65             0004006650             905.65             0000905650   1                 0000001000

Reason for above conversion
The output will be passed to another existing logic that is defined as 9(6)V9(3). So the values will be read and passed to further downstream as 4006.65, 905.65, 1.00

Please help in coming with the conversion logic. I have tried with NUMVAL however not able to achieve the result.

Thanks
Vinu
Bill Woodger

Moderator Emeritus

Joined: 09 Mar 2011
Posts: 7310
Location: Inside the Matrix

 Posted: Tue Apr 16, 2013 11:38 am Where are you not getting the result? And what result are you getting? 9(6)V9(3) is only nine bytes, so it you think it 10, that could be the problem. V is an implied, not actual decimal place, so if you expect ".", that could be the problem. As long as all the input data are valid, NUMVAL should do what you want. If the data are not all valid, NUMVAL will turn it's nose up at the first one it doesn't like, and an abend will ensue, so be sure.
chandan.inst

Active User

Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

 Posted: Tue Apr 16, 2013 11:39 am Hi, Agree with BIll.. Even You can try below approach. This is untested 1. Unstring INPUT fields in two numeric fields with delimited by '.' 2. Multiply 1st part of ustring output by 1000 and then add later part of unstring output to multiplication result I might be missing something here so its better try out and play around the logic Also it will be better if you show us how you have used Numval and provide answers to Bill's question Regards, Chandan
mistah kurtz

Active User

Joined: 28 Jan 2012
Posts: 310
Location: Room: TREE(3). Hilbert's Hotel

 Posted: Tue Apr 16, 2013 11:42 am Check out the below post: http://ibmmainframes.com/about56428.html
vinu78

Active User

Joined: 02 Oct 2008
Posts: 179
Location: India

 Posted: Tue Apr 16, 2013 9:02 pm Hi Bill, I have tried the following: 01 WS-INPUT PIC X(10). 01 WS-TEMP PIC 9(7)V9(3). COMPUTE WS-TEMP = FUNCTION NUMVAL (WS-INPUT). MOVE WS-TEMP TO WS-INPUT. While compiling, I am getting the error message at the COMPUTE step as follows: "WS-TEMP (NUMERIC NON-INTEGER)" and "WS-INPUT(ALPHANUMERIC)" did not follow the statement compatibility rules. The statement was discarded. Then I tried changing the WS-INPUT as 9(10) and got the following error: Function argument "WS-INPUT" did not have the correct type for function "NUMVAL". The statement was discarded. Not sure how to get rid of this error. Plz help. Thanks Vinu
Robert Sample

Global Moderator

Joined: 06 Jun 2008
Posts: 8569
Location: Dubuque, Iowa, USA

 Posted: Tue Apr 16, 2013 9:21 pm The statement compatability rules error is due to you attempting to move an alphanumeric variable to a numeric variable with a decimal point. The invalid function argument is because NUMVAL only works on alphanumeric variables; numbers are already numeric and valued.
 View Bookmarks All times are GMT + 6 Hours

 Topic Forum Replies Similar Topics Packed decimal to Alphanumeric COBOL Programming 2 Date conversion using SORT SYNCSORT 4 HOW TO OVERLAY A Packed decimal VALUE... DFSORT/ICETOOL 5 Write Character to Hexadecimal file w... COBOL Programming 8 Date Conversion Y2T to Y2W SYNCSORT 8
Search our Forums: