Вы находитесь на странице: 1из 3

Computational Data Representation (USAGE Clause)

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.

3.Binary (BINARY, COMP, or COMP-4) Items:


BINARY, COMP and COMP-4 are synonyms on all platforms.

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.

4. Packed Decimal (PACKED-DECIMAL or COMP-3) Items:


Packed decimal format occupies 1 byte of storage for every two decimal digits you code in the
PICTURE description, except that the right-most byte contains only 1 digit and the sign. This
format is most efficiently used when you code an odd number of digits in the PICTURE
description, so that the left-most byte is fully used. Packed decimal format is handled as a fixedpoint number for arithmetic purposes.
Why Use Packed Decimal ?
Packed decimal format requires less storage per digit than DISPLAY format requires.
Packed decimal format is better suited for decimal alignment than binary format.
Packed decimal format is converted to and from DISPLAY format more easily than binary
format.
Packed decimal format is well suited for containing arithmetic operands or results.

5. Floating-Point (COMP-1 and COMP-2) Items:


COMP-1 refers to short (single-precision) floating-point format, and COMP-2 refers to long
(double-precision) floating-point format, which occupy 4 and 8 bytes of storage, respectively. The
leftmost bit contains the sign; the next seven bits contain the exponent; the remaining 3 or 7 bytes
contain the mantissa.
On MVS & VM, COMP-1 and COMP-2 data items are stored in S/370 hexadecimal format.
A PICTURE clause is not allowed in the data description of floating-point data items, but you can
provide an initial value using a floating-point literal in the VALUE clause:
05

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
|

|
|

|__________ __________________________ ________ __________________|


| Numeric | PICTURE and USAGE and
|
|
|
| Type
| Optional SIGN Clause
| Value | Internal Represt.|
|__________|__________________________|________|__________________|
| External | PIC S9999 DISPLAY
| + 1234 |
F1 F2 F3 C4
|
| Decimal |
| - 1234 |
F1 F2 F3 D4
|
|
|
|
1234 |
F1 F2 F3 C4
|
|
___________________________|________|__________________|
|
| PIC 9999 DISPLAY
|
1234 |
F1 F2 F3 F4
|
|__________________________|________|__________________|
|
| PIC S9999 DISPLAY
| + 1234 |
C1 F2 F3 F4
|
|
| SIGN LEADING
| - 1234 |
D1 F2 F3 F4
|
|__________________________|________|__________________|
|
| PIC S9999 DISPLAY
| - 1234 | 4E F1 F2 F3 F4
|
|
| SIGN LEADING SEPARATE
| - 1234 | 60 F1 F2 F3 F4
|
|
| PIC S9999 DISPLAY
| + 1234 | F1 F2 F3 F4 4E
|
|
| SIGN TRAILING SEPARATE
| + 1234 | F1 F2 F3 F4 60
|
|__________|__________________________|________|__________________|
| Binary
| PIC S9999 BINARY
| + 1234 |
04 D2
|
|
|
COMP
| - 1234 |
FB 2E
|
|
|
COMP-4
|
|
|
|
|__________________________|________|__________________|
|
| PIC 9999 BINARY
| + 1234 |
04 D2
|
|
|
COMP
| - 1234 |
04 D2
|
|
|
COMP-4
|
|
|
|__________|__________________________|________|__________________|
| Internal | PIC S9999 PACKED-DECIMAL | + 1234 |
01 23 4C
|
| Decimal |
COMP-3
| - 1234 |
01 23 4D
|
|
|__________________________|________|__________________|
|
| PIC 9999 PACKED-DECIMAL | + 1234 |
01 23 4F
|
|
|
COMP-3
| - 1234 |
01 23 4F
|
|__________|__________________________|________|__________________|
| Internal | COMP-1
| + 1234 | 43 4D 20 00
|
| Floating |
| - 1234 | C3 4D 20 00
|
| Point
|
|
|
|
|__________|__________________________|________|__________________|
| Internal | COMP-2
| + 1234 |43 4D 20 00 00 00 00 00 |
| Floating |
| - 1234 |C3 4D 20 00 00 00 00 00 |
| Point
|
|
|
|
|__________|____________________|________|________________________|
| External | PIC +9(2)9(2)E+99 DISPLAY| + 1234 | 43 F1 F2 4B F3
|
| Floating |
|
|
F4 C5 4E F0 F2|
| Point
|
|________|__________________|
|
|
| - 1234 | 60 F1 F2 4B F3
|
|
|
|
|
F4 C5 4E F0 F2|
|__________|__________________________|________|__________________|

Вам также может понравиться