View previous topic :: View next topic
|
Author |
Message |
preethan Warnings : 1 New User
Joined: 15 Dec 2008 Posts: 33 Location: Chennai
|
|
|
|
How to read a decimal variable in Cobol ?
I have some reports to read. Those reports will have values like
-1010.24
I tried reading this value like PIC S9(4)V9(2).
When tried like this the job is not running fine. I guess it is not accepting with the dots. How can i read this variable ? |
|
Back to top |
|
|
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
Back to top |
|
|
preethan Warnings : 1 New User
Joined: 15 Dec 2008 Posts: 33 Location: Chennai
|
|
|
|
I tried running this.. it is still not working fine.. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
too bad |
|
Back to top |
|
|
preethan Warnings : 1 New User
Joined: 15 Dec 2008 Posts: 33 Location: Chennai
|
|
|
|
dbzTHEdinosauer wrote: |
too bad |
Can some one help me in this ??
For time being I have planned to read the numbers before the decimal point and the numbers after the decimal point in two different variables and divide the latter with 100 and add it with the former one. If a negative sign is there i will multiply it by -1.
It is not a good programming at all. Please help if anyone knows a better way. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Search the fourm/look in the manuals for the intrinsic function NUMVAL and see if you can get that to work. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
If your COBOL version/release is a minimum of COBOL/370 (early 1990's) -
Code: |
03 WS-EDIT-VALUE PIC -9(04).99 VALUE -1010.24.
03 WS-DISPLAY PIC S9(04)V99.
03 WS-PACKED PIC S9(05)V99 COMP-3.
MOVE WS-EDIT-VALUE TO WS-DISPLAY.
MOVE WS-DISPLAY TO WS-PACKED.
|
The value in WS-DISPLAY equals X'F1F0F1F0F2D4' (The X'D4' (C'M') indicates a negative value (the X'D' zone-nibble), also known as an overpunch). Character value ===> C'10102M'.
If you then moved WS-DISPLAY to WS-PACKED, the result would be X'0000000101024D' (negative 101024).
Mr. Bill |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
When tried like this the job is not running fine. |
Quote: |
Can some one help me in this ?? |
As you have been a member for nearly 3 years, i'm sure you've seen us tell people they should NOT post "it didn't work". . . All this is is a waste of everyone's time.
You need to post what happened so someone here has a chance to help from the beginning. . . |
|
Back to top |
|
|
cyrus.e.cabrera
New User
Joined: 25 Jul 2011 Posts: 14 Location: Philippines
|
|
|
|
move the value of "that" variable to a printing variable.
to display 123456789 to 123,456,789
try pic zzz,zzz,zz9.
and the rest needs to be searched. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Please post only things that have been tested. . .
This will not handle the leading minus (-). . . |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Preethan,
If you're reading report data, try using the field definitions of the pgm that created the report in your pgm(they s/b numeric edited).
After they're read into the edited fields, move them to a work field large enough and with enough decimal places to accommodate the largest of them. They're now ready for arithmetic operations.
This is the safest approach. If you can't/won't use the originating report's defs, you can create your own. |
|
Back to top |
|
|
|