RAMESH KRISHNA REDDY mainframe discussion forum - cobol, db2,cics,jcl,file-aid,changeman,interview questions
Online Tutorials   | PREV | TOP | NEXT



Author : Vasanta T.


COMP COMP-1 COMP-2 COMP-3 COMP:Normally, a computer can store data in more than one internal form. In COBOL, a programmer is allowed to specify the internal form of the data item so as to facilitate its use in the most efficient manner. There are only two general forms of internal representation namely COMPUTATIONAL and DISPLAY. Only numeric data items can be specified as USAGE IS COMPUTATIONAL and the name itself suggests a data item specified as USAGE IS COMPUTATIONAL can take part in arithmetic operations more efficiently and any data item can be specified as USAGE IS DISPLAY. If we omit Usage clause compiler assume DISPLAY as default. In COMP usage Data is stored as Pure Binary format internally. Depending on the size of the data item, it can be stored either in a half-word (2 bytes with range �32,768 to +32767) or full- word (4 bytes with range �2,147,483,648 to 2,147,483,647). The PICTURE Clause of a COMPUTATIONAL data item should not contain any character other than 9 or S.Example : 01 WS--DS-HDR-LEN PIC S9(02) COMP.Which occupies 2 bytes and data stored as Pure binary format internally. Data name length Length in COBOL 9(01) to 9(04) 2 bytes 9(05) to 9(09) 4 bytes S9(10) to S9(18) 8 bytes COMP-1:In this case the data item will be represented in one word in the floating point form the number is actually represented in hexadecimal format and is suitable for arithmetic operations. The PICTURE Clause cannot be specified for COMP-1 items. COMP-1 takes 4 bytes of storage. COMP-2:This is same as COMP-1, except that the data is represented internally in two words. The advantage is that this increases the precision of the data, which means that more significant digits are available. Similar to COMP-1, The PICTURE Clause cannot be specified for COMP-2 items also. COMP-1 takes 8 bytes of storage.COMP-2 is more precision than COMP-1. Interview Question : Why COMP-1, COMP-2 don�t have PIC clause ?PIC creates relation between data name and data type. Whereas here data is numeric and length is predefined as one word floating for COMP-1 and double word floating for COMP-3. So no relation is required using PIC clause. COMP-3:In this case the data is represented in the decimal form, but one digit takes half a byte. The sign is stored separately as the rightmost half a byte character. Find Comp-3 storage in bytes: Length of variable/2, if this is not pure number then it takes immediate next number of bytes.For example S9(06) : which takes 4 bytes. � for sign (S) and variable length is 6 which takes 3 bytes. total is 3 � so its immediate number is 4. Additional added � byte is called slack byte.COMP-3 Picture clause Number of bytes occupied by the fieldS9(1) COMP-3 1 S9(2) COMP-3 2S9(3) COMP-3 2 S9(4) COMP-3 3 S9(5) COMP-3 3 S9(6) COMP-3 4S9(7) COMP-3 4 S9(8) COMP-3 5S9(9) COMP-3 5 S9(10) COMP-3 6 S9(11) COMP-3 6 S9(12) COMP-3 7 S9(13) COMP-3 7 S9(14) COMP-3 8 S9(15) COMP-3 8 S9(16) COMP-3 9 S9(17) COMP-3 9 S9(18) COMP-3 10 1. The USAGE Clause can be specified on data items defined with any level number. 2. The USAGE of a group item is valid for all its sub items.Question : How to read COMP-3 value in a sequential file?You need to use HEX ON commmand to see COMP-3 values in PS When you use this command it will show two lines per each record. You need to read the comp-3 value from left, top to bottom (in two lines) and then move to second character read top to bottom. COMP-3 Example : +87634 will be displayed as 864 73C -4567 will be displayed as 057 46D last characters represents sign. if last character is C or F, that denotes a positive sign. If last character is D , that denotes a negative sign.Question : Conversion of comp-3 to character Displaying COMP-3 characters: Before displaying COMP-3 Move the data to usage display variable then display. If it holds Sign then Use SIGN LEADING SEPARATE which uses one extra byte for sign and sign will be displayed separately. 01 WS-NUMBER PIC S9(03) COMP-3. 01 WS-NUMBER1 PIC S9(03) SIGN LEADING SEPARATE.MOVE WS-NUMBWER TO WS-NUMBER1DISPLAY WS-NUMBER1 displays data properly.Question : Can i Move LOW-VALUES TO COMP-3 variable?Moving LOW-VALUES is not possible. This will give compiler error.



Previous chapter in COBOL tutorialStarting of COBOL tutorialNext chapter in COBOL tutorial

Visit COBOL books section in this site for good books

Home | Donations | Online Tutorials | Books | Entertainment | Contactme | privacy |  sql tutorial | jcl interview questions | JCL Tutorial | JCL Tutorial - chapter1 | JCL Tutorial - chapter2 | JCL Tutorial - chapter3 | JCL Tutorial - chapter4 | JCL Tutorial - chapter5 | JCL Tutorial - chapter6 | JCL Tutorial - chapter7 | JCL Tutorial - chapter8 | JCL Tutorial - chapter9 | JCL Tutorial - chapter10 | JCL Tutorial - chapter11