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

Alphanumeric to decimal conversion logic


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

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Tue Apr 16, 2013 11:00 am
Reply with quote

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
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


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

PostPosted: Tue Apr 16, 2013 11:38 am
Reply with quote

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.
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Tue Apr 16, 2013 11:39 am
Reply with quote

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
Back to top
View user's profile Send private message
mistah kurtz

Active User


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

PostPosted: Tue Apr 16, 2013 11:42 am
Reply with quote

Check out the below post:

http://ibmmainframes.com/about56428.html
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Tue Apr 16, 2013 9:02 pm
Reply with quote

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
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: Tue Apr 16, 2013 9:21 pm
Reply with quote

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.
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 Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts 10 byte RBA conversion DB2 2
No new posts 10 byte RBA conversion -non applicati... JCL & VSAM 1
No new posts file manager is doing string conversion IBM Tools 3
No new posts Need Help with Packed Decimal Signs DFSORT/ICETOOL 4
Search our Forums:

Back to Top