Monday, August 29, 2011

Usage Clause in cobol or How cobol store data ?


DISPLAY Default. Number of bytes required equals to the size of the data item.If we don't mention anything then default Usage is Display.for eg

01 WS-VAR PIC X(10)

then by default it will take usage as Display and occupy 10 bytes in memory


*COMP/COMP3/COMP1/COMP2/COMP4/COMP5/BINARY :-All are called computational variables and only used with decimal datatypes only.

COMP Binary representation of data item.
PIC clause can contain S and 9 only.
S9(01) – S9(04) Half word.(2 byte/16bits)
S9(05) – S9(09) Full word.(4 byte/32bits)
S9(10) - S9(18) Double word.(8byte/64 bits)
Most significant bit is ON if the number is negative.


COMP-1: Single word floating point item. PIC Clause should not be specified.
The sign is contained in the first bit of the of the leftmost byte and the
exponent is contained in the remaining 7 bits of the first byte. The last
3 bytes contain the mantissa.

COMP-2: Double word floating-point item. PIC Clause should not be specified.
7 bytes are used for mantissa and hence used for high precision
calculation.


COMP-3: Packed Decimal representation. One digit takes half byte(Nible/4 bits).
PIC 9 (N) comp-3 data item would require (N + 1)/2 bytes. The sign is stored separately in the rightmost half-byte regardless of whether S is specified in the PICTURE or not.
C – Signed Positive D – Signed Negative F-Unsigned Positive.

comp 3 is most efficiently used when size is defined as a odd number.for eg

01 WS-NUM PIC S9(5) COMP-3.
It will take 3 bytes (half byte for sign)


INDEX It is used for preserve the index value of an array. It takes 4 bytes.
PIC Clause should not be specified. When the clause is specified for a group item, it applies to all elementary items contained in it. However, the group itself is not an index data item.


POINTER
4 Byte elementary item that can be used to accomplish limited base

addressing. It can be used only in – SET statement, Relation condition,
USING phrase of a CALL statement, an ENTRY statement or the
procedure division statement. A value clause for a pointer data item
can contain only NULL or NULLS.

SET identifier-1 TO address of identifier-2
SET ADDRESS OF identifier-2 TO identifier-1.

Identifier-1 is POINTER data item and identifier-2 is linkage section item.

cob_ques cob_fun

0 comments:

Post a Comment