Monday, September 26, 2011

COBOL : How COMP-5 field works


We can move maximum value of 18-9's to COMP-5 when compiler option ARITH is COMPAT.

If compiler option ARITH is EXTEND, then can move maximum value of 31-9's to COMP-5


E.g 01 ws-a PIC S9(10) COMP-5.

Eventhough pic clause has 9(10), cobol allows 18 digits to store. Note that picture clause of COMP-5 field is just to indicate the number of bytes to be allocated.

01 WS-B PIC X(08) VALUE X'031993AF1D7BFFFF'.
01 WS-A REDEFINES WS-B PIC S9(10) COMP-5.
01 WS-C PIC S9(18) COMP-3.
PROCEDURE DIVISION.
PARA.
MOVE WS-A TO WS-C.
DISPLAY '.' WS-C '.'
STOP RUN.

(Decimal value 223372036854775807 - Hex value 31993AF1D7BFFFF)

When COMP-5 field is moved to any other fields, all the content of COMP-5 fields is coneverted to number and it is moved to the other fields.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.