Tuesday, December 6, 2011

Explanation for various COBOL data types

BINARY
   Specified for binary data items.  Such items have a decimal equivalent consisting of the decimal digits 0 through 9, plus a sign.  Negative numbers are represented as the two's complement of the positive number with the same absolute value.

Digits in PICTURE clause          Storage occupied
========================          ================
1 through 4                       2 bytes (halfword)
5 through 9                       4 bytes (fullword)
10 through 18                     8 bytes (doubleword)



PACKED-DECIMAL
   Specified for internal decimal items.  Such an item appears in storage in packed decimal format.  There are 2 digits for each character position, except for the trailing character position, which is occupied by the low-order digit and the sign.  Such an item can contain any of the digits 0 through 9, plus a sign, representing a value not exceeding 18 decimal digits.                                

COMPUTATIONAL-1 or COMP-1 (floating-point) 
   Specified for internal floating-point items (single precision).
   COMP-1 items are 4 bytes long.                                 

COMPUTATIONAL-2 or COMP-2 (long floating-point)
  Specified for internal floating-point items (double precision).
  COMP-2 items are 8 bytes long.                                 

Note: COMPUTATIONAL-1 and COMPUTATIONAL-2 items cannot have PICTURE strings.

COMPUTATIONAL-3 or COMP-3 (internal decimal)
  This is the equivalent of PACKED-DECIMAL.

COMPUTATIONAL-4 or COMP-4 (binary)  
  This is the equivalent of BINARY.

COMPUTATIONAL-5 or COMP-5 (native binary)
  These data items are represented in storage as binary data.  The data items can contain values up to the capacity of the native binary representation (2, 4 or 8 bytes), rather than being limited to the value implied by the number of nines in the picture for the item (as is the case for USAGE BINARY data).  When numeric data is moved or stored into a COMP-5 item, truncation occurs at the binary field size, rather than at the COBOL picture size limit.  When a COMP-5 item is referenced, the full binary field size is used in the operation.      

Picture                   Storage Representation
=======                   ======================
S9(1) through S9(4)       Signed Binary half-word  (2 bytes)
S9(5) through S9(9)       Signed Binary full-word  (4 bytes)
S9(10) through S9(18)     Signed Binary double-word(8 bytes)
9(1) through 9(4)         Binary half-word  (2 bytes)
9(5) through 9(9)         Binary full-word  (4 bytes)
9(10) through 9(18)       Binary double-word(8 bytes)

No comments:

Post a Comment

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