View previous topic :: View next topic
|
Author |
Message |
Ritesh Chopra
New User
Joined: 15 Oct 2007 Posts: 13 Location: India
|
|
|
|
Can anyone please tell me what is difference between COMP and COMP-4 usage. As per my understanding both are binary. And please also mention what are the appropriate places to use them ?
Thanks in advance. |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Your understanding is correct, both are same.
Infact 'BINARY' is another keyword to declare a COMP variable. |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
Back to top |
|
|
Ritesh Chopra
New User
Joined: 15 Oct 2007 Posts: 13 Location: India
|
|
|
|
Thanks abhijit but I have many programs which use COMP-4 specifically, I just wanted to know that why are we moving to COMP-4 if COMP is the same. |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
I will try to keep this as simple as possible-
Usually DCLGEN generates COMP-4 variable declarations for smallint, int etc. from a Db2 Table.
There are two possible orders in which bytes can be stored in memory.
Either you store byte containing the MSB as the leftmost byte (Big endian) or at the rightmost byte (little endian). IBM processors use big endian and intel machines use little endian format to store numbers in memory.
Big endian machine store MSB in lower address im memory and little endian machine stores MSB in higher address in memory.
( Left and Right does not make much sense if you really think..I tend to go too much in my Electronics engineering but I must stop here. )
There is also COMP-5, which we must know to understand COMP behaviour-
COMP-5 always represents Native binary, so it will be depending upon the platform you use.Compiler flag determines whether plain
COMP was COMP-4 or COMP-5 (native).
The TRUNC(BIN) compiler option causes all binary data items (USAGE BINARY, COMP, COMP-4) to be handled as if they were declared USAGE COMP-5.
This kind of compiler option will be available across all ANSI compliant platforms which support cobol. So lets conclude saying that COMP-4 is just for ANSI compliance and there is no difference between Binary and Comp-4.
Experts, please correct /add to what I have written. |
|
Back to top |
|
|
Ritesh Chopra
New User
Joined: 15 Oct 2007 Posts: 13 Location: India
|
|
|
|
Thanks Abhijit,
I would also like to know, Is there any relevance between ( big endian, small endian) and (COMP ,COMP-4) ? |
|
Back to top |
|
|
|