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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How does "comp-X" work ? 3

Status
Not open for further replies.

santi

Technical User
Apr 5, 2001
2
AR
Hi all!
I have two questions...
Do you know what Cobol does with the optional parameter COMP-5 and 1 ?? I know that in this line:** 01 counter PIC 9(4) VALUE 1234 COMP-3 ** it compresses to 3bytes but I dont know about COMP-5 and 1.

The other question is about memory. How is it possible for Cobol not to occupy memory space for decimals and signed numbers. I mean, in the number -584.735 the sign and decimal point don t occupy memory. Is this correct??
 
Hi,

in CA-REALIA COBOL the comp-5 means a binairy local definition, the so called intel format. In the Intel format, the highest byte is in front.

For example:

pic s9(4) comp-5 value +1

contains x"0100".

pic s9(4) comp value +1

contains x"0001".

so the bytes are in reversed order.

regards,

Crox
 
Hi Santi,

First the signs:

In binary(comp) a halfword +1 would look like:
B'00...001' or X'00'

a halfword -1 would look like:
B'11...111' or x'FF'

In packed decimal (comp-3) a 1 byte +1 would look like:
X'1C' or X'1F' ( The F denotes unsigned, but is treated
arithmetically as positive)

a 1 byte - would look like:
X'1D'

So that explains why the compiler doesn't need an extra memory position for the sign (sign is separate is the exception).

Now, how does it know about the decimal places if the decimal isn't inclused in the field?

When the comiler generates the assembler language code for each COBOL statement, it uses the field definitions coded by the programmer (pic, comp, v, etc) to select the appropriate assembler instructions and techniques to scale the results.

Let me know if this helps or you have any further questions.

Jack.
 
Hi Santi,

That s/b X'01' not X'00'

Sorry, Jack.
 
Thanks all for the help you gave. Very clear explanations.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top