Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print value 9(7) IN FORMAT 99.99999

Status
Not open for further replies.

shaily123

Programmer
Feb 5, 2005
17
US
Hi i need to print the value of field2 in format 99.99999
SO I CREATED A N EW FIELD WITH FORMAT 99.99999. But when i do move from field2 to field3 it PRINTS 45.00000 WHICH IS WRONG. i WANT IT TO PRINT 45.12345.
can any one help HOW TO WRITE IN THE CODE.




WORKING-STORAGE SECTION.
01 field2 PIC 9(7).
01 field3 pic 99.99999.
procedure division.
MOVE 4512345 TO field2.
MOVE FIELD2 TO FIELD3.
STOP RUN.
 
And what about this ?
COMPUTE FIELD3 = FIELD2 / 100000

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
shaily123 -

COBOL aligns the (implied) decimal points when doing the move. So a PIC 9(7) has no digits after the implied decimal point and will NEVER have anything but zeros after an actual decimal point in a picture.

Perhaps you should define FIELD2 with more precision, e.g. PIC 99V9(5) (and then move 45.12345 to it).

Regards.

Glenn

(Note that using 1234567 in your test will provide more information than 4512345 as its not clear which '45' is being shown in the result.)
 
Try this:
Code:
01 yr-fld   pic 9(007)
01 new-fld  redefines
   yr-fld   pic 99V9(5).
01 ed-fld   pic 99.9(5).

move new-fld to ed-fld


Regards, Jack.

"A problem well stated is a problem half solved" -- Charles F. Kettering
 
I think compute has an on overflow condition. You would not want to overflow the field. It will cause unexpected results.

If you do not like my post feel free to point out your opinion or my errors.
 
The example is not a compute. It is a MOVE. But you are right, shaily123 is looking at the rightmost 2 digits of the original 4512345.

Solution COMPUTE FIELD3 = FIELD2 / 100000 is very inefficient.

Slade's solution is the true-COBOL-like solution because it does not cost extra computer-power; just using WORKING-STORAGE possibilities.
 
Just do a redefine of the same data!
10 field-1 pic 9(07).
10 filler redefines field-1.
15 field-1-b pic 99999v99.

Now you dont have to have a move to refer to the data.


If you do not like my post feel free to point out your opinion or my errors.
 
I think Slade understood the problem better.
 
CROX,

Correct, SLADE got it right for you.

Steve N.
State of Ohio, MIS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top