Usage verb COMP,COMP1,COMP2,COMP3

Usage

     1.     How many different data USAGEs can be used in COBOL?
DISPLAY, COMP, COMP-3, INDEX, POINTER.
     2.     Explain the USAGE of COMP/COMP1/COMP2/COMP3
USAGE COMP
Maintained in binary
Only integral numbers
Depending on the size of the data item, stored either in half word or full word
Should be numeric only

    PIC              Length in bytes
    1         TO    4                   2       
    5         TO    9                   4       
    10        TO   18                 8

USAGE COMP1
One  word  in  floating  point  form
Number  represented  in  hexadecimal
Picture  clause  cannot  be  specified
Suitable  for  arithmetic  operations
    01        WS - NUM           PIC   S9(4)
            USAGE  COMP.

COMP-2  USAGE
Same as COMP-1 except that data represented internally in two words
Increases precision of the data. Picture  clause  cannot  be  specified.


COMP-3  USAGE
Internal Representation In Packed Decimal Form
Each digit and sign occupy 1/2 byte
Hexadecimal number C or F denotes positive sign
Hexadecimal number D denotes negative sign
     3.     What is a USAGE IS INDEX?
USAGE IS INDEX represents an index data item which is Full-Word binary and is used to save the value of the index. That Index Data Item can be set to the value of the Index thru the SET statement, ex. SET WS-IND-SAVE-FLD TO ITEM-IND. Index data item is not directly related to any table.   
     4.     PIC S9(4)COMP IS USED INPSPITE OF COMP-3 WHICH OCCUPIES LESS SPACE for this particular case and WHY?
9(4) COMP uses only 2 bytes.
9(4) COMP-3 uses 3 bytes.
3 bytes is more than 2 bytes. Hence COMP is preferred over COMP-3 in this case.
     5.     How to display the fields whose usage is COMP?
When we try to display a data item with usage as computational it does not give the desired display format because the data item is stored as packed decimal. So if we want this particular data item to be displayed, we have to move it into a data item whose usage is display and then have that particular data item edited in the format desired.
     6.     What is the maximum length of a field you can define using COMP-3?
10 Bytes (S9(18) COMP-3).
     7.     How is sign stored in Packed Decimal fields and Zoned Decimal fields?
Packed Decimal fields:   Sign is stored as a hex value in the last nibble (4 bits ) of the storage.
Zoned Decimal fields:    As a default, sign is over punched with the numeric value stored in the last bite.
     8.     How is sign stored in a comp-3 field? -
It is stored in the last nibble. For example if your number is +100, it stores hex 0C in the last byte, hex 1C if your number is 101, hex 2C if your number is 102, hex 1D if the number is -101, hex 2D if the number is -102 etc...     
     9.      How is sign stored in a COMP field ? -
In the most significant bit. Bit is on if -ve, off if +ve.
 10.     What is the difference between COMP & COMP-3  ?
COMP is a binary storage format while COMP-3 is packed decimal format.
 11.     How do you define a variable of COMP-1?  COMP-2?
No picture clause to be given. Example 01 WS-VAR USAGE COMP-1.
 12.     How many bytes does a S9(7) COMP-3 field occupy ?
Will take 4 bytes. Sign is stored as hex value in the last nibble.
General formula is INT((n/2) + 1)), where n=7 in this example.
 13.     How many bytes does a S9(7) SIGN TRAILING SEPARATE field occupy ?
Will occupy 8 bytes (one extra byte for sign).
 14.     How many bytes will a S9(8) COMP field occupy ?
4 bytes.
 15.     What is the maximum value that can be stored in S9(8) COMP?
99999999
 16.     What is the maximum size of a 01 level item in COBOL I?  in COBOL II?
In COBOL II: 16777215
 17.     What is COMP SYNC?
Causes the item to be aligned on natural boundaries. Can be SYNCHRONIZED LEFT or RIGHT.
For binary data items, the address resolution is faster if they are located at word boundaries in the memory.  For example, on main frame the memory word size is 4 bytes.  This means that each word will start from an address divisible by 4.  If my first variable is x(3) and next
one is s9(4) comp, then if you do not specify the SYNC clause, S9(4) COMP will start from byte 3 ( assuming that it starts from 0 ).  If you specify SYNC, then the binary data item will start from address 4. You might see some wastage of memory, but the access to this
computational field is faster.
 18.     Explain the usage of SIGN CLAUSE?
[SIGN  IS] [LEADING]   [SEPARATE CHAR ]        [TRAILING]

Specifies position and mode of representation
Picture string should contain ‘S’
Any input field for negative value should contain  ‘SEPARATE CHAR’
Only for numeric elementary items Usage should be DISPLAY
Default TRAILING without separate character

PIC             VALUE       SIGN           REPRESENTATION
S9(3)      -243    LEADING       K  4   3        
S9(3)      -243        TRAILING           2    4   L

0 comments:

Computers TopOfBlogs Technology Blogs Mainframe interview question and answers,mainframe jobs,cobol,vsam,jcl,cics,db2,rdbms,mvs,tso,ispf,ibm,hcl,tcs,cts,wibro Blog Directory