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
 

 

NUMVAL Function for alphanumeric moves to numeric

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: NUMVAL Function for alphanumeric moves to numeric
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: 7936
Location: Bellevue, IA

PostPosted: Thu May 21, 2009 4:20 pm    Post subject:
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    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Fri May 22, 2009 12:55 am    Post subject: Reply to: FUNCTION NUMVAL for using alphanumeric moves to nu
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    Post subject:
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: 7936
Location: Bellevue, IA

PostPosted: Fri May 22, 2009 3:12 pm    Post subject:
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    Post subject:
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: 1224
Location: Israel

PostPosted: Thu Apr 12, 2012 4:06 pm    Post subject: Reply to: FUNCTION NUMVAL for using alphanumeric moves to nu
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: 7936
Location: Bellevue, IA

PostPosted: Thu Apr 12, 2012 6:08 pm    Post subject:
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    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. How to move a long alphanumeric data ... lind sh COBOL Programming 8 Mon Dec 05, 2016 7:51 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts Strange EXEC function call in z/VM Willy Jensen CLIST & REXX 3 Wed Oct 05, 2016 2:07 pm


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