COBOL COMP-3

COBOL COMP-2 COBOL Programming Construction

Advertisements


COMP-3 usage clause will be called as packed decimal form.

COMP-3 usage clause is applicable for numeric data type.

COMP-3 will store the data as packed. i.e. two digits in each byte.

COMP-3 data will be stored in memory as BCD (Binary Coded Decimal) Format.

COMP-3 data stored in memory higher to lower in the size of nibble (4 bits). i.e. The upper nibble stores the most significant digit and lower nibble stores the next digit and the upper nibble stores the next digit etc,.

COMP-3 allows Signed packed decimal item where the sign will store on least significant digit (rightmost lower nibble).

In COMP-3 Sign always table one nibble so always even number of nibbles allocated.


PictureNumber of Bytes
9½ Byte

The formula for memory calculation of the COMP-3 data item which declared with N bytes is


No. of Bytes occupied = (n + 1)/2.

PICTURE clause required for COMP-3 declaration.


Practicle Example:


Code:


 IDENTIFICATION DIVISION.                                         
 PROGRAM-ID. COMP3.                                              
 ENVIRONMENT DIVISION.                                            
 DATA DIVISION.                                                   
 WORKING-STORAGE SECTION.                                         
 01 COMP3-NM1             PIC 9(04) USAGE COMP-3 VALUE '2561'.    
 01 COMP3-NM2             PIC S9(04) USAGE COMP-3 VALUE '2561'.   
 PROCEDURE DIVISION.                                              
     DISPLAY 'COMPUTATION-3..'.                                   
     DISPLAY 'COMPUTATION3 - NUMERIC [9(04)-> 2 BYTES]'.          
     DISPLAY COMP3-NM1.                                           
     DISPLAY 'COMPUTATION3 - NUMERIC [S9(04)-> 3 BYTES]'.         
     DISPLAY COMP3-NM2.                                           
     STOP RUN.                                                    


Differences between COMP & COMP-3:


COMPCOMP-3
Size depends upon the range.1 digit = ½ byte.
COMP internally stores in binary.COMP-3 internally stores in packed decimal form.
COMP is used only for whole numbers.COMP-3 used for whole & decimal values.
S is not considered in COMP.S is considered in COMP-3.

COBOL COMP-2 COBOL Programming Construction

Advertisements