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



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

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

Postby zhinghur » Thu Jul 12, 2012 8:13 am

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.
zhinghur
 
Posts: 48
Joined: Sun Nov 20, 2011 12:25 pm
Has thanked: 0 time
Been thanked: 0 time

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

Postby zhinghur » Thu Jul 12, 2012 8:26 am

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
zhinghur
 
Posts: 48
Joined: Sun Nov 20, 2011 12:25 pm
Has thanked: 0 time
Been thanked: 0 time

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

Postby Anuj Dhawan » Thu Jul 12, 2012 9:20 am

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?
Anuj
Anuj Dhawan
 
Posts: 273
Joined: Mon Feb 25, 2008 3:53 am
Location: Mumbai, India
Has thanked: 6 times
Been thanked: 4 times

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

Postby Robert Sample » Thu Jul 12, 2012 5:02 pm

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.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

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

Postby zhinghur » Mon Jul 16, 2012 8:32 pm

Thanks Robert. I wasn't able to reply earlier. You were right. I was able to fix it.
zhinghur
 
Posts: 48
Joined: Sun Nov 20, 2011 12:25 pm
Has thanked: 0 time
Been thanked: 0 time

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

Postby Robert Sample » Mon Jul 16, 2012 11:27 pm

Glad to hear you got it fixed.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post