Page 1 of 1

Big Comp -3 field to small Comp - 3 field with Sign

PostPosted: Thu Jul 12, 2012 8:13 am
by zhinghur
Hi all,

I have a field defined in input file as S9(7)V99 COMP-3 and need to move in a report of PIC X(4). The input field will never have value more than 6 digit before decimal.

Its like, - INPUT
01 HOUR-FIELDS PIC S9(7)V99 COMP-3.


In Output file

01 HR-OUT PIC X(4).
01 HR-OUT-RD PIC S9(6)V99 COMP-3


If I redefine X(4) which is 1 byte less than original HOUR-FIELDS and redefine as shown above, will it work. If not, any other alternate way to handle this scenario.


NOTE : INPUT will have max of 8 digits including decimal not more than that.

Re: Big Comp -3 field to small Comp - 3 field with Sign

PostPosted: Thu Jul 12, 2012 8:26 am
by zhinghur
One more doubt as digits are right and characters left indented, which statement should be used if above is possible.

MOVE HOUR-FIELDS to HR-OUT, or
MOVE HOUR-FIELDS to HR-OUT-RD

Re: Big Comp -3 field to small Comp - 3 field with Sign

PostPosted: Thu Jul 12, 2012 9:20 am
by Anuj Dhawan
Though it's beginners's Forum, however, it sounds like you did enough labor in explaining the things - so did you also try it and test to see what happens?

Re: Big Comp -3 field to small Comp - 3 field with Sign

PostPosted: Thu Jul 12, 2012 5:02 pm
by Robert Sample
I think the first thing you need to do is to make crystal clear exactly what you are trying to do. You mentioned a report field of PIC X(4) -- does this mean you need to show the characters of the field since reports are usually read by humans? If so, you need to be mindful of Dolly Parton's advice ("you can't put 10 pounds of potatoes in a 5 pound sack") -- six characters before the decimal and two after the decimal means you need at least 8 characters to display the data for a human (9 if you count a decimal point, which you should). 4 characters will not allow anybody to look at the field and know what the data is without using a hexadecimal display.

If, on the other hand, your goal is merely to store the data in a 4-byte field, then you need to find the COBOL Language Reference manual and read up on internal formats for data. A PIC S9(6)V99 COMP-3 variable takes up 5 characters just like a PIC S9(7)V99 so you gain nothing by using a 4-byte variable, anyway. And using a 4-byte variable means you're going to lose two digits from the original value -- either the first two or the last two, most likely, depending upon exactly what you code up.

Re: Big Comp -3 field to small Comp - 3 field with Sign

PostPosted: Mon Jul 16, 2012 8:32 pm
by zhinghur
Thanks Robert. I wasn't able to reply earlier. You were right. I was able to fix it.

Re: Big Comp -3 field to small Comp - 3 field with Sign

PostPosted: Mon Jul 16, 2012 11:27 pm
by Robert Sample
Glad to hear you got it fixed.