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

about comp

Status
Not open for further replies.

kurup

Programmer
Jun 1, 2001
32
0
0
IN
hi friends,
can anyone help me out in getting the differnce between declaring a variable comp,comp3 and binary
ie if i declare a variable as
01 var1 pic 9(3) comp
01 var1 pic 9(3) comp-3
01 var1 pic 9(3) binary
pls help me out
bye
 
A field defined as 9(3) COMP will take up 2 bytes - so will a field defiend as 9(4) COMP. This is because COMP fields are aligned to word and half-word boundaries. Anything up to 4 digits takes 2 bytes, from 5-9 will all take up 4 bytes, etc. It makes sense, then, to define COMP fields as 9(4) or 9(9), etc, because you'll be using the same space up as 9(3) and 9(7) respectively.
A packed decimal field has a simple formula for space used - take the total digits, add 1 and divide by 2. Therefore, 9(3) COMP-3 will take up 2 bytes. It also makes sense to define COMP-3 fields as an uneven number of digits, to make the best use of space.
A 'binary' field is the same as a COMP field.
 
The short answer is that COMP is a pure binary representation, whereas COMP-3 is packed decimal.

asides:

COMP-1 is single precision float and COMP-2 is double precision float.
 
As a good practice, given that it's operating system dependent, specify SYNC with
COMP fields to ensure bounary allignment: 05 AFIELD PIC S9(4) COMP SYNC. Also,
boundary allignment results in fewer generated instructions; so performanace is
an issue here, concerning COMP fields, as well as the DASD savings.
 
FYI - On IBM mainframes since the mid-60's COMP-3 is the format closest to DISPLAY that the hardware can actually do arithmetic on. The newer IBM compilers even seem to want to convert COMP fields to COMP-3 before doing calculations. Conversly, PC's can *only* do arithmetic with COMP fields(or COMP-1/COMP-2) so they must convert COMP-3's to COMP before they can add 1 to the field or do any other arithmetic on it. They have to include COMP-3 simply because they're so popular in the mainframe world.

You'll never notice the difference in execution speed if you use the 'wrong' format, but its still nice to know if you are obsessive about your tools.
 
You will notice the difference in execution speed if you do a lot of computing. There is an optimization manual from IBM which says exactly how big the difference is on the mainframe.

On the PC the comp-5 (Intel format) is the fastest with my compiler: CA-REALIA.

Regards,

Crox
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top