Re: COMP and COMP-3 fields

From: Arnold Trembley (arnold.trembley_at_worldnet.att.net)
Date: 05/25/04


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/



Relevant Pages

  • Re: Comping for your meal
    ... the chain store was closing one of its outlets. ... There were big signs everywhere insisting that all sales were final, that there were no returns, to check carefully before making purchases because everything was as-is, etc. ... I know restaurant owners comp meals because they're afraid they'll get a bad reputation from patrons who will tell all their friends that they had a bad time. ...
    (rec.food.cooking)
  • ~~~~~~~~~~~~~~ COMP USA ~~~~~~~~~~~~~~
    ... 17 hp notebook comp usa ... comp usa brevard florida ... comp usa closing chino store ... comp usa hp laptops ...
    (de.etc.schreiben.prosa)
  • Re: COMP and COMP-3 fields
    ... >> stored in the following declarations and how? ... > Assuming IBM mainframe COBOL, which seems likely given the COMP-3, ... COMP declaration if i have to store a value of 45000.... ...
    (comp.lang.cobol)
  • Re: why does my comp remember names?
    ... WildCat had this to say: ... My reply is at the bottom of your sent message: ... > get my comp to not store all these names or remember them,Fraustrated ...
    (microsoft.public.windowsxp.security_admin)
  • Re: move of COMP to DISPLAY
    ... the COMP field is signed or non-signed). ... ('02 Standard), you CAN get "incompatible data" for a binary ... anomaly in AcuCOBOL. ...
    (comp.lang.cobol)