What is the difference between comp and comp-3 usage? Explain other COBOL usages?

Comp is a binary usage, while comp-3 indicates packed decimal. The other common usages are binary and display. Display is the default. 3/28/00 Dave Herrmann: 'I was reading your FAQ on Cobol, as an fyi Comp is defined as the fastest/preferred numeric data type for the machine it runs on. IBM Mainframes are typically binary and AS400's are packed.'

Showing Answers 1 - 14 of 14 Answers

mahinder

  • Dec 12th, 2005
 

hai

COMP

Comp is used for Binary Representation

it allows only S and 9 ...

s9(01) to s9(04) it takes 2 bytes memory

s9(05) to s9(09) it takes 4 bytes memory

s9(10) to s9(18) it takes 8 bytes memory

 

COMP-3

Comp-3 is used for Packed Decimal values

it allows S,9 ,V

mostly it is useful for Decimal Caluculation Values

it takes (n/2)+1 Bytes Memory

venkatesh

  • Aug 31st, 2007
 

Comp, Comp1, Comp2 are used when you going to use SYNC (When you want the storage should start only at the boundaries). In other cases it depends....Venkat

  Was this answer useful?  Yes

poojaDeep

  • Apr 16th, 2008
 

COMP Comp is used for Binary Representation it allows only
S and 9 ... s9(01) to s9(04) it takes 2 bytes memory
s9(05) to s9(09) it takes 4 bytes memory
s9(10) to s9(18) it takes 8 bytes memory
 
COMP-3 :- Comp-3 is used for Packed Decimal values it allows S,9 ,V mostly it is useful for Decimal Caluculation Values.
 
it takes (n/2)+1 Bytes Memory : for N= Even values
(n+1)/2 : For n=Odd

atherprvz

  • Sep 2nd, 2008
 

Binary representation of data item are called 'comp', while comp-3 is the packed decimal.
comp-1 & comp-2 are another usage. 

  Was this answer useful?  Yes

vjjammi

  • Aug 7th, 2010
 

Here are the details of the COMP, COMP-1, COMP-2, COMP-3.

When the usage of COMP is specified, the numeric data item is represented in the BINARY FORMAT. The item declared must be an INTEGER. Depending on the size of the data item, it can be stored as a half-word(16 bits) or a full word(32 bits).

The Picture Clause of the Data item must contain 9,S.

When the usage of COMP-1 is specifed, the data item is represented in one word in the floating point form. The number is actually represented in the Hexadecimal format(base 16). Such representations are actually suitable for Arthimetic operations. The Picture clause cannot be used for COMP-1.

When the usage of COMP-2 is specified, the data item is represented in two words in the floating point form and with more accuracy and more no. of siginficant digits. The number is also represented in the Hexadecimal format(base 16). The Picture cannot be specified for COMP-2.

When the usage of COMP-3 is specified, the data item is represented in the Packed-Decimal foramt. The Value is stored based on the concept of "1 Digit is going to take half-byte".
By storing the data item in Packed-Decimal formats, the space and the efficiency of the object program is optimized which would enable the programs for faster computations with less memory usage.
The General calculation for the amount of memory that a COMP-3 variable occupies is as below.

For even number of Digits, S9(N) - ((n/2)+1) bytes
For odd number of Digits, S9(N) - (n+1)/2) bytes

Hence, the following example gives you a more clearer idea.

If you trying to store 374 in the COMP, COMP-3, we will see the amount of memory used in both the cases..

No Usage:

01 I PIC 9(03)   VALUE is 374.   ----> Without a COMP - 3 Bytes(Stored in the EBCDIC format internally).

COMP

01 I PIC 9(3)  COMP VALUE is 374. ----> With COMP - 374 is represented in Binary as
101110110. Hence, this will stored in Binary as follows.

0000 0001 0111 0110 - 2 Bytes

COMP-3

01 I PIC 9(3) COMP-3 VALUE is 374. -----> With COMP-3 - 374 is represented in Decimal as 0011 0111 0100.
But this is stored as 0011 0111 0100 1111(The Last four bits of the right most byte represents the sign of the variable whether is declred in the Picture clause or not.

1111(C or F) represnts a postive sign. D denotes a negative sign.

Hence, this usage occupies two bytes also.

Hope you are clear with these details.

talluri

  • Jul 27th, 2011
 

COMP will doesn't occupy extra storage space for sign values & it's binary representation

COMP-3 will occupy one extra storage space & it's packed decimal representation

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions