USAGE & Data Representation

On ASCII platforms (GnuCOBOL on Linux) zoned decimal uses ASCII digits 0x30–0x39, with the sign of a negative number encoded in the last byte; binary items are big-endian for COMP/BINARY (matching IBM) but native-endian for COMP-5.

9.1 USAGE options

DISPLAY (default) One byte per digit/character (zoned decimal for numbers)

Text, file fields readable by humans, edited output COMP / COMPUTATIONAL / BINARY

Binary: 2 bytes (1–4 digits), 4 bytes (5–9), 8 bytes (10–18) Counters, subscripts, lengths COMP-3 / PACKED-DECIMAL

Two digits per byte + sign nibble: ceil((digits+1)/2) bytes

Money and quantities — the mainframe workhorse (hardware decimal instructions)

4-byte floating point (single precision) Scientific values (rare in business)

8-byte floating point (double precision) Native binary — full range of the binary size, not limited by the PIC digits

Interfacing with C, APIs, system services Binary displacement for a table index

USAGE INDEX variables for saving index values Linked lists, APIs, SET ADDRESS OF

FUNCTION-POINTER / PROCEDURE-POINTER Entry point addresses UTF-16 characters (PIC N) UTF-8 (IBM 6.3+) UTF-8 data (PIC U) Unicode text in UTF-8

9.2 How +1234 is stored (IBM z/OS, EBCDIC)

PIC S9(4) DISPLAY F1 F2 F3 C4 (sign in the zone of the last byte: C=+, D=−, F=unsigned) PIC S9(4) SIGN LEADING SEPARATE 4E F1 F2 F3 F4 (4E = +) PIC S9(5) COMP-3 PIC S9(4) COMP PIC S9(8) COMP

On ASCII platforms (GnuCOBOL on Linux) zoned decimal uses ASCII digits 0x30–0x39, with the sign of a negative number encoded in the last byte; binary items are big-endian for COMP/BINARY (matching IBM) but native-endian for COMP-5.

9.3 Choosing a USAGE

Money: PIC S9(n)V99 COMP-3 (exact, compact, fast on Z). Use an odd number of digits (e.g., S9(7)V99 = 9 digits = 5 bytes) because the sign nibble makes odd digit counts fill bytes exactly.

Counters and subscripts: PIC S9(4) COMP or PIC S9(8) COMP (or COMP-5 to avoid truncation logic). Data exchanged in text files or displayed: DISPLAY.

Avoid COMP-1/COMP-2 for money — binary floating point cannot represent 0.10 exactly.

9.4 Binary truncation (IBM TRUNC option)

PIC S9(4) COMP occupies a halfword that can hold up to 32767, but the PICTURE says 4 digits. With IBM TRUNC(STD) (the default) results are truncated to 9999; TRUNC(BIN) uses the full binary range; TRUNC(OPT) lets the compiler pick whichever is faster (only safe if values never exceed the PICTURE). COMP-5 always behaves like TRUNC(BIN). GnuCOBOL has a matching -fbinary-truncate / -fno-binary-truncate option.

9.5 SIGN, SYNCHRONIZED, JUSTIFIED

Examples: PIC S9(5) SIGN IS LEADING SEPARATE, PIC S9(8) COMP SYNCHRONIZED, PIC X(10) JUSTIFIED RIGHT.

SIGN ... SEPARATE stores the sign as its own +/- character — the safest format for files exchanged with other systems.

SYNCHRONIZED aligns binary items on natural boundaries (may insert slack bytes).

JUSTIFIED RIGHT right-aligns alphanumeric moves (truncating on the left).