COBOL - USAGE Clause - COMPUTATIONAL-5 or COMP-5 (native binary)



Desenvolvido por DORNELLES Carlos Alberto - Analista de Sistemas - Brasília DF. - cad_cobol@hotmail.com

COBOL - USAGE Clause - 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.

Note: The TRUNC(BIN) compiler option causes all binary data items (USAGE BINARY, COMP, COMP-4) to be handled as if they were declared with USAGE COMP-5.

Picture Storage representation Numeric values
S9(1) through S9(4) Binary half-word (2 bytes) -32768 through +32767
S9(5) through S9(9) Binary full-word (4 bytes) -2,147,483,648 through +2,147,483,647
S9(10) through S9(18) Binary double-word (8 bytes) -9,223,372,036,854,775,808 through +9.223,372,036,854,775,807
9(1) through 9(4) Binary half-word (2 bytes) 0 through 65535
9(5) through 9(9) Binary full-word (4 bytes) 0 through 4,294,967,295
9(10) through 9(18) Binary double-word (8 bytes) 0 through 18,446,744,073,709,551,615

The picture for a COMP-5 data item can specify a scaling factor (that is, decimal positions or implied integer positions).
In this case, the maximal capacities listed in the table above must be scaled appropriately.
For example, a data item with description PICTURE S99V99 COMP-5 is represented in storage as a binary half-word, and supports a range of values from -327.68 to +327.67.

Usage note:

When the ON SIZE ERROR phrase is used on an arithmetic statement and a receiver is defined with USAGE COMP-5, the maximum value that the receiver can contain is the value implied by the item's decimal PICTURE character-string.
Any attempt to store a value larger than this maximum will result in a size error condition.



© Copyright IBM.