Controlling how numeric data is stored
You can control how the computer stores numeric data items
by coding the USAGE clause in your data description
entries.
You might want to control the format for any of several reasons such as these:
- Arithmetic performed with computational data types is more efficient
than with
USAGE DISPLAYorUSAGE NATIONALdata types. - Packed-decimal format requires less storage per digit than
USAGE DISPLAYorUSAGE NATIONALdata types. - Packed-decimal format converts to and from
DISPLAYorNATIONALformat more efficiently than binary format does. - Floating-point format is well suited for arithmetic operands and results with widely varying scale, while maintaining the maximal number of significant digits.
- You might need to preserve data formats when you move data from one machine to another.
The numeric data you use in your program will have one of the following formats available with COBOL:
- External decimal (
USAGE DISPLAYorUSAGE NATIONAL) - External floating point (
USAGE DISPLAYorUSAGE NATIONAL) - Internal decimal (
USAGE PACKED-DECIMAL) - Binary (
USAGE BINARY) - Native binary (
USAGE COMP-5) - Internal floating point (
USAGE COMP-1orUSAGE COMP-2)
COMP and COMP-4 are
synonymous with BINARY, and COMP-3 is
synonymous with PACKED-DECIMAL.
The compiler converts displayable numbers to the
internal representation of their numeric values before using them
in arithmetic operations. Therefore it is often more efficient if
you define data items as BINARY or PACKED-DECIMAL than
as DISPLAY or NATIONAL.
For example:
05 Initial-count Pic S9(4) Usage Binary Value 1000.
Regardless of which USAGE clause
you use to control the internal representation of a value, you use
the same PICTURE clause conventions and decimal value
in the VALUE clause (except for internal floating-point
data, for which you cannot use a PICTURE clause).
Examples: numeric data and internal representation
Formats for numeric data
Data format conversions
Intermediate results and arithmetic precision