Re: COMP and COMP-3 fields
From: Arnold Trembley (arnold.trembley_at_worldnet.att.net)
Date: 05/25/04
- Next message: Mike Cowlishaw: "Re: Alternative COBOL "telco" source program"
- Previous message: Richard: "Re: R: GOBACK (was: Perform Thru/Go to vs. Perform - Compile Speed"
- In reply to: Roger: "Re: COMP and COMP-3 fields"
- Next in thread: Harley: "Re: COMP and COMP-3 fields"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 25 May 2004 21:33:44 GMT
Roger wrote:
> (snip)
>
> I still have few questions, in the program i am debugging it is right
> now able to store 18981 in the S9(04)comp field.
>
> So, can you please let me know how do i find out what should be the
> COMP declaration if i have to store a value of 45000....
Again, assuming an IBM mainframe COBOL compiler and a TRUNC(OPT)
compile time option, then PIC 9(4) COMP will probably work, but it is
a bit risky. Note carefully that the picture MUST BE unsigned. You
can never store 45000 into a PIC S9(4) COMP field because 45000 has
the leftmost bit ON, which will convert it to a negative number. With
S9(4) COMP, an assembler program can store values ranging from -32767
to +32767.
You would probably be better off with a picture clause that requires a
32-bit binary fullword, i.e. PIC S9(9) COMP.
>
> Also i heard that in S9(04) we can store a value of up to 65635
> eventhough we declared as s9(04) COMP....this is because COMP fields
> do not care the sign field if it is having positive value...
No, this will never be true. In a halfword (16 bits) the leftmost bit
is always the sign. So any binary representation greater than X'8000'
must be negative. The largest positive number you can represent in
PIC S9(4) COMP is X'7FFF' in hexadecimal, which is +32767 in decimal.
Negative numbers would be in the range X'8000' thru X'FFFF' in two's
complement form.
For an unsigned picture clause, i.e. PIC 9(4) COMP, the largest number
that can be stored is X'FFFF', which is +65535 decimal, but you could
never store a negative number into an unsigned COMP field.
Again, this is based only on my experience with IBM mainframe COBOL
compilers, with system 360/370 binary numbers in 16-bit halfwords.
I hope that helps!
-- http://arnold.trembley.home.att.net/
- Next message: Mike Cowlishaw: "Re: Alternative COBOL "telco" source program"
- Previous message: Richard: "Re: R: GOBACK (was: Perform Thru/Go to vs. Perform - Compile Speed"
- In reply to: Roger: "Re: COMP and COMP-3 fields"
- Next in thread: Harley: "Re: COMP and COMP-3 fields"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|