Two clauses decide what an elementary item is. PICTURE gives its shape (how many digits or characters,
where the decimal point sits, how it is edited when shown). USAGE gives its storage format
(text digits, binary, packed decimal, floating point, a pointer). Both are described here in full; where a
symbol or usage is not in the standard the compilers that have it are named.
Data categories
| Category | Picture holds | Used for |
|---|---|---|
| Alphabetic | A only | Letters and spaces |
| Alphanumeric | X, or a mix of A, 9 and X | Any characters |
| Alphanumeric-edited | X or A with B, 0, / | Formatted text |
| Numeric | 9, S, V, P | Arithmetic |
| Numeric-edited | 9 with Z * + - CR DB B 0 / , . $ and E | Reports, printed numbers |
| National, national-edited | N (2002; IBM) | Unicode text |
| DBCS | G (IBM), N with DISPLAY-1 | Double-byte text |
| Boolean | 1 (2002) | Bit strings |
| Index, pointer, object reference, function pointer | no picture | Addresses |
Every picture symbol
A repeat count may follow a symbol: 9(5) is 99999. Symbols are not case-sensitive.
| Symbol | Meaning |
|---|---|
9 | One digit. |
X | One character of any kind. |
A | One letter or space. |
N | One national character (two bytes in IBM and GnuCOBOL UTF-16 or one 2-byte DBCS character). |
G | One double-byte character (IBM, with DISPLAY-1). |
1 | One bit (boolean items). |
S | An operational sign; takes no space unless SIGN IS SEPARATE. Must be first. |
V | An implied decimal point (no space). 9(5)V99 holds 7 digits. |
P | A scaling position: an assumed digit beyond the field: PPP999 is .000nnn; 999PPP is nnn000. Only at the left or right end. |
Z | Digit position, leading zero replaced by a space. |
* | Digit position, leading zero replaced by an asterisk (cheque protection). |
+ - | Sign: + shows + or -; - shows - or a space. A run of them “floats” the sign to the first non-zero digit. |
CR DB | Credit or debit: two characters at the right end showing the letters when the value is negative, spaces otherwise. |
$ (or another currency sign) | Currency symbol; floats when repeated. CURRENCY SIGN IS … in SPECIAL-NAMES changes it (and, in 2002, WITH PICTURE SYMBOL chooses a different symbol). |
. | Decimal point, shown (with DECIMAL-POINT IS COMMA the comma is the decimal point and the full stop the separator). |
, | Thousands separator, inserted. |
B | Insert a space. |
0 | Insert a zero. |
/ | Insert a slash. |
E | External floating-point form (+9.99E+99). |
Examples of editing
| Picture | Value held | Shown |
|---|---|---|
9(5)V99 | 1234.5 | 0123450 (7 bytes; the point is not stored) |
ZZ,ZZ9.99 | 1234.5 | 1,234.50 |
ZZ,ZZ9.99 | 0 | 0.00 |
$$$,$$9.99 | 1234.5 | $1,234.50 |
***,**9.99 | 12.5 | *****12.50 |
-9(4) | -42 | -0042 |
9(4)- | -42 | 0042- |
+++9 | -5 | -5 (floating sign) |
9(4)CR | -42 | 0042CR |
99/99/9999 | 01022024 | 01/02/2024 |
XXBXXBXX | "ABCDEF" | AB CD EF |
9(3)B9(3)B9(4) | 5551234567 | 555 123 4567 |
PPP99 | .00012 | stored as 12 |
Only a numeric-edited item can be displayed this way; it cannot be used in arithmetic. De-edit it with MOVE to a plain numeric item,
or FUNCTION NUMVAL-C. BLANK WHEN ZERO on the data entry replaces an all-zero value by spaces.
USAGE clauses
| Usage | Storage | Notes |
|---|---|---|
DISPLAY (default) | One character per digit or letter | Text form. A signed number keeps its sign in the last (or first) digit as an overpunch, or as a separate character with SIGN IS SEPARATE. Also DISPLAY is the verb. |
BINARY, COMPUTATIONAL (COMP) | Two's-complement binary, big-endian on IBM, size by digits: 1 to 4 digits take 2 bytes, 5 to 9 take 4, 10 to 18 take 8 | The standard leaves COMP to the implementor; on IBM, Micro Focus and GnuCOBOL it is binary. Compiler options (TRUNC on IBM, binary-truncate on GnuCOBOL, BINSIZE) decide whether stores are cut to the picture’s digit count. |
COMP-4 / COMPUTATIONAL-4 | Same as BINARY on IBM and Micro Focus | |
COMP-5 | Native binary, in the machine’s byte order, no truncation to the picture | IBM, Micro Focus, GnuCOBOL. |
COMP-X | Unsigned binary of 1, 2, 4 or 8 bytes by the number of nines | Micro Focus, GnuCOBOL. |
COMP-1 | Single-precision floating point (4 bytes); no PIC | IBM hexadecimal float on mainframes unless FLOAT(IEEE); IEEE on other platforms. |
COMP-2 | Double-precision floating point (8 bytes); no PIC | Same. |
COMP-3, PACKED-DECIMAL | Packed decimal: two digits per byte and a sign in the last nibble (C or F positive, D negative); bytes = (digits + 2) div 2 | The usual form for money on mainframes. PIC S9(7)V99 COMP-3 takes 5 bytes. |
COMP-6 | Unsigned packed decimal, no sign nibble | Micro Focus, GnuCOBOL. |
COMP-0 COMP-N | Compiler-specific binary and character forms | Accepted by GnuCOBOL as synonyms of other usages for compatibility; not in the standard. |
BINARY-CHAR BINARY-SHORT BINARY-LONG BINARY-DOUBLE (each [SIGNED | UNSIGNED]) | 8, 16, 32, 64 bits | 2002 and later; no PIC. GnuCOBOL adds BINARY-C-LONG. |
FLOAT-SHORT FLOAT-LONG FLOAT-EXTENDED | IEEE-like 4, 8 and 16 byte floats | 2002 and later. |
FLOAT-BINARY-32 -64 -128, FLOAT-DECIMAL-16 -34 | IEEE 754-2008 binary and decimal floating point | 2014 standard; IBM and Micro Focus support decimal float. |
INDEX | An index (4 or 8 bytes) for tables | Used with SET and SEARCH; INDEXED BY makes one without a data entry. |
POINTER | An address (4 or 8 bytes) | Used with SET … TO ADDRESS OF, ALLOCATE, CALL. Compare with NULL. 2002 and several compilers. |
PROCEDURE-POINTER, FUNCTION-POINTER, PROGRAM-POINTER | Entry point of a program or function | Called with CALL pointer; SET p TO ENTRY "name". |
OBJECT REFERENCE [class] | A handle to an object | Object-oriented COBOL. |
NATIONAL | UTF-16 (IBM) or the platform national encoding | For PIC N items. |
DISPLAY-1 | DBCS | IBM. |
BIT | One bit per 1 in the picture | 2002; GROUP-USAGE IS BIT for a group. |
01 A PIC S9(4) DISPLAY. *> 4 bytes, sign overpunched
01 B PIC S9(4) BINARY. *> 2 bytes
01 C PIC S9(9) COMP. *> 4 bytes
01 D PIC S9(7)V99 COMP-3. *> 5 bytes
01 E USAGE COMP-2. *> 8-byte float
01 F USAGE POINTER.
01 G PIC N(10) USAGE NATIONAL. *> 20 bytes (UTF-16)
01 H USAGE BINARY-LONG UNSIGNED.
MOVE and arithmetic convert between usages automatically; the speed and the size of the data
file are why programmers choose one over another. Files written by one dialect are not always readable
by another because byte order, sign nibbles and the meaning of COMP differ.
Sign and decimal point
- A signed item has
Sin its picture.SIGN IS LEADINGorTRAILINGchooses the end that holds the sign, andSEPARATE CHARACTERmakes it a+or-byte of its own. DECIMAL-POINT IS COMMAinSPECIAL-NAMESswaps the roles of.and,in pictures and literals.CURRENCY SIGN IS literal(andNUMERIC SIGN ISin some dialects) change the editing characters.