Numbers: USAGE, COMP and COMP-3

USAGE DISPLAY

By default a numeric field is stored as text, one character per digit. USAGE DISPLAY is fine for reports and screens, but slow for arithmetic.

01 WS-COUNT PIC 9(4) USAGE DISPLAY. 01 WS-TOTAL PIC 9(7)V99.

USAGE COMP

USAGE COMP (COMPUTATIONAL) stores the number as a binary integer. Arithmetic on COMP fields is fast, and the PICTURE still controls how many digits you can hold:

01 WS-COUNT PIC 9(4) USAGE COMP. 01 WS-INDEX PIC S9(9) USAGE COMP.

USAGE COMP-3

USAGE COMP-3 stores a packed decimal: two digits per byte plus a sign nibble. It is the classic choice for money on mainframes because it keeps exact decimal values with no rounding surprises:

01 WS-SALARY PIC 9(7)V99 USAGE COMP-3.

The code on this page was run with GnuCOBOL 3.2.0 on Alpine Linux 3.24.3 (x86_64) in a Docker container.

Article author: Arthur Isaev