what is the difference between comp and comp-3 in COBOL?

2 posts / 0 new
Last post
what is the difference between comp and comp-3 in COBOL?

Can anyone explain in detail the differences between the different usage types in cobol, i.e. COMP and COMP-3 ?

Joined: 06/09/2011 - 09:59
Addressing diffrence between COMP and COMP-3 question.

Point 1) Comp-3 is used to avoid rounding issues that occur when binary numbers are used to represent decimal fractions. This is especially important in systems that process large volumes of financial transactions/amounts (e.g. banking, credit cards, etc.).

Point 2) Use COMP-3 for any field where there is substantial arithmetic combined with substantial movement of the field to/from a DISPLAY item. If the field is not used with DISPLAY items, it may best be COMP. For example, to move it to a COMP field requires a PACK and a CVB instruction. To move a COMP field to a DISPLAY field requires a CVD and UNPACK. In each case, the intermediate result is a COMP-3 field. By using COMP-3 fields when DISPLAY NUMERIC fields provide/receive results, you avoid the extra conversions all the way to COMP.

Point 3) COMP-3 over COMP. Why? COMP-3 abends rather nicely with an 0C7 if you put rubbish in there, COMP does not. Also, when debugging a COMP-3 field, it is very easy to see what the value is when looking at it in hex. With COMP fields, you have to drag out a calculator and convert the hex value to find out the true value that is being used in a program.

Point 4) COMP is used for Binary Representation it allows only S and 9. Comp-3 is used for Packed Decimal values it allows S 9 V mostly it is useful for Decimal Calculation Values. 5)COMP stores the data in the binary format and COMP-3 stores the date in the BCD(Binary Coded Decimal)format. .

Log in or register to post comments
Sponsored Listing