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

NUMVAL Function for alphanumeric moves to numeric


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

New User


Joined: 27 Jul 2007
Posts: 33
Location: mumbai

PostPosted: Thu May 21, 2009 4:04 pm
Reply with quote

Hi,

I am trying to move alphanumeric fields to numeric fields by using FUNCTION NUMVAL.

When I use input field as PIC X(18) it works fine, but when I change it to X(20) it gives incorrect results. Please have a look at the results below:


INPUT:
01 A PIC X(20) VALUE '+12345678901234.5555'.
01 B PIC S9(14)V9(4).
01 A1 PIC X(18) VALUE '+123456789012.5555'.
01 B1 PIC S9(12)V9(4).

COMPUTE B = FUNCTION NUMVAL A.
COMPUTE B1 = FUNCTION NUMVAL A1.

OUTPUT:
(Incorrect result)
A = +12345678901234.5555
B = 123456789012345555D

(Correct result)
A = +123456789012.5555
B = 123456789012555E

Please let me know why I am getting incorrect results. ALso could you let me know any other alternative for moving alpha numeric to numeric values when I use input as X(20).
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: Thu May 21, 2009 4:20 pm
Reply with quote

Why do you call them incorrect results? The results you get are the results you get -- they are neither correct nor incorrect, they are what COBOL does. Be aware that COBOL, like all computer languages, does not support an infinite number of decimal digits, so the COBOL results will not necessarily be the same as mathematical operations (mathematics assumes infinite decimal digits for all operations).

Check your compile option ARITH. I tested your statements (after fixing the syntax errors) with ARITH(COMPAT) and got
Code:
 A  = +12345678901234.5555
 B  = 12345678901234555D
 A1 = +123456789012.5555
 B1 = 123456789012555E
and with ARITH(EXTEND) I got
Code:
 A  = +12345678901234.5555
 B  = 12345678901234555E
 A1 = +123456789012.5555
 B1 = 123456789012555E
Back to top
View user's profile Send private message
manishmittal

New User


Joined: 25 Apr 2008
Posts: 49
Location: Gurgaon

PostPosted: Fri May 22, 2009 12:44 am
Reply with quote

In general , until you specify Extend in your compile option u will be seeing the same result.Because maximum limit for a numeric field in Cobol is 18(Extend is other way).
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri May 22, 2009 12:55 am
Reply with quote

Unless, your compiler is COBOL OS/390 V2.2 (about 10-12 years ago) and greater, where you can specify compiler option ARITH(EXTEND), which allows up to 31-Digit numeric values.

Regards,
Back to top
View user's profile Send private message
vaibhavjadhav

New User


Joined: 27 Jul 2007
Posts: 33
Location: mumbai

PostPosted: Fri May 22, 2009 3:02 pm
Reply with quote

Thanks for the immediate reply guys.
I tried changing the compiler option but as I am using SCLM tool it doesnt have ARITH(EXTEND) option. Could you please let me know is their any other option either through programming or some other alternative where I can ahieve the required result.

Thanks in advance.
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: Fri May 22, 2009 3:12 pm
Reply with quote

Contact your site support group -- if the COBOL compiler you're using is any of the versions from the last few years then it has the ARITH(EXTEND) option. Your SCLM group may need to change something to support it.

ARITH(EXTEND) is the simplest way to get the precision you need. You could use an array in your program to represent your numbers, but then your program would be responsible for doing the arithmetic operations so it could get messy in a hurry.
Back to top
View user's profile Send private message
sivamani

New User


Joined: 03 Apr 2012
Posts: 1
Location: INDIA

PostPosted: Thu Apr 12, 2012 3:57 pm
Reply with quote

For this there is one more reason, cobol will allow numerics upto 18 bytes i.e. 9(18).
Here you atre trying to move with 20 bytes
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Thu Apr 12, 2012 4:06 pm
Reply with quote

Add the following line right before the ID DIVISION in your COBOL program:
Code:
CBL ARITH(EXTEND)


Follow this link to understand how it works.
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: Thu Apr 12, 2012 6:08 pm
Reply with quote

sivamani, any particular reason you felt the need to respond after nearly three years, AND adding a comment that adds absolutely nothing to the discussion already in the thread -- especially since your comment is only paritally accurate and depends upon the setting of the compile option ARITH (as made clear in earlier comments)?
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 Calling an Open C library function in... CICS 1
No new posts DATE2 function SYNCSORT 15
No new posts Help on PL/I jsonPutValue function PL/I & Assembler 8
No new posts how to use Tso outtrap external function All Other Mainframe Topics 8
No new posts INSYNC option with same function as I... JCL & VSAM 0
Search our Forums:

Back to Top