View previous topic :: View next topic
|
Author |
Message |
vaibhavjadhav
New User
Joined: 27 Jul 2007 Posts: 33 Location: mumbai
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
manishmittal
New User
Joined: 25 Apr 2008 Posts: 49 Location: Gurgaon
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
vaibhavjadhav
New User
Joined: 27 Jul 2007 Posts: 33 Location: mumbai
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
sivamani
New User
Joined: 03 Apr 2012 Posts: 1 Location: INDIA
|
|
|
|
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 |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Add the following line right before the ID DIVISION in your COBOL program:
Follow this link to understand how it works. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
|