Professional Documents
Culture Documents
USAGE Clause in Cobol
USAGE Clause in Cobol
USAGE Clause in Cobol
Control how the computer internally stores your numeric data items by coding the USAGE clause
in your data description entries. The numeric data you use in your program will be one of the
formats available with COBOL:
External decimal
= (USAGE DISPLAY)
External floating-point = (USAGE DISPLAY)
Internal decimal
= (USAGE PACKED-DECIMAL)
Binary
= (USAGE BINARY)
Internal floating-point = (USAGE COMP-1, USAGE COMP-2)
COMP and COMP-4 are synonymous with BINARY
COMP-3 is synonymous with PACKED-DECIMAL.
Regardless of what USAGE clause you use to control the computer's internal representation of
the value, you use the same PICTURE clause conventions and decimal value in the VALUE
clause except for floating point data.
1. External Decimal (USAGE DISPLAY) Items:
When you code USAGE DISPLAY or omit the USAGE clause, each position (or byte) of storage
contains one decimal digit. This corresponds to the format used for printing or displaying output,
meaning the items are stored in displayable form.
What USAGE DISPLAY Items Are For?
External decimal items are primarily intended for receiving and sending numbers between
your program and files, terminals, and printers. However, it is also acceptable to use external
decimal items as operands and receivers in your program's arithmetic processing, and it is often
convenient to program this way.
2. External Floating-Point (USAGE DISPLAY) Items:
Displayable numbers coded in a floating-point format are called external floating-point items.
Like external decimal items, you define external floating-point items explicitly with USAGE
DISPLAY or implicitly by omitting the USAGE clause.
In the following example, Compute-Result is implicitly defined as an external floating-point item.
Each byte of storage contains one character (except for V).
05
Compute-Result
Pic -9v9(9)E-99.
The VALUE clause is not allowed in the data description for external floating-point items. Also,
the minus signs (-) do not mean that the mantissa and exponent will always be negative numbers,
but that when displayed the sign will appear as a blank for positive and a minus sign for negative.
If a plus sign (+) were used, positive would be displayed as a plus sign and negative as a minus
sign.
Just as with external decimal numbers, external floating-point numbers have to be converted
(automatically by the compiler) to an internal representation of the numeric value before they can
be operated on. External floating-point numbers are always converted to internal long floatingpoint format.
Binary format occupies 2, 4, or 8 bytes of storage and is handled for arithmetic purposes as a
fixed-point number with the leftmost bit being the operational sign. For byte-reversed binary data,
the sign bit is the leftmost bit of the rightmost byte.
How Much Storage BINARY Occupies
A PICTURE description with 4 or fewer decimal digits occupies 2 bytes;
with 5 to 9 decimal digits, 4 bytes;
with 10 to 18 decimal digits, 8 bytes.
Binary items with 9 or more digits require more handling by the compiler. Testing them for the
SIZE ERROR condition and rounding is more cumbersome than with other types.
What to Use BINARY For?
Binary items are well suited for containing subscripts, switches, and arithmetic operands or
results.
However, you might want to use packed decimal format instead of binary because:
Binary format is not as well suited for decimal alignment as packed decimal format.
Binary format is not converted to and from DISPLAY format as easily as packed decimal
format.
Compute-result
Usage Comp-1
Value 06.23E-24.
Floating-point format is well suited for containing arithmetic operands and results and for
maintaining the highest level of accuracy in arithmetic.
_________________________________________________________________
| Internal Representation of Numeric Items
|
|
|