In COBOL, numeric data is defined with the PICTURE clause using the symbols 9 (digit) and S (sign), and optionally V (implied decimal point). The way the value is stored in memory is determined by USAGE (DISPLAY, COMP, COMP-3, etc.). This page explains numeric data types: integer vs decimal, signed vs unsigned, and how to choose the right PICTURE and USAGE for numbers.
Numbers in a program can be whole (like 1, 2, 100) or have a decimal part (like 3.14 or 99.99). COBOL lets you say "this is a whole number" (no decimal) or "this number has two digits after the decimal" (e.g. dollars and cents). You also say whether the number can be negative (like a balance that can go below zero). The type you choose affects how much space it uses and how the computer does math with it.
The PICTURE (or PIC) clause defines the shape and meaning of the data. For numeric fields you use 9 for digits and optionally S for sign and V for decimal position.
| Symbol | Meaning | Example |
|---|---|---|
| 9 | One numeric digit (0–9) | PIC 9(4) = four digits |
| S9 | Signed digit; field can be negative | PIC S9(5) = signed 5-digit integer |
| V | Implied decimal point (no storage) | PIC 9(3)V99 = 3 integer, 2 decimal places |
| P | Scaling (decimal positions at end) | PIC P(3) = scale factor (less common) |
The number in parentheses (e.g. 9(5)) means that many occurrences. So 9(5) is five digits; S9(7)V99 is seven digits before the decimal and two after, with sign.
123401 WS-COUNT PIC 9(5). *> Unsigned, 5 digits (e.g. 0 to 99999) 01 WS-AMOUNT PIC S9(7)V99. *> Signed, 7 digits + 2 decimals (e.g. -9999999.99 to 9999999.99) 01 WS-QUANTITY PIC S9(4). *> Signed integer, 4 digits 01 WS-RATE PIC 9(2)V99. *> Unsigned, 2 integer + 2 decimal (e.g. 0.00 to 99.99)
V stands for the implied (assumed) decimal point. It does not take any storage; it only tells the compiler and runtime where the decimal point is when interpreting the value. For example, PIC 9(3)V99 means three digits to the left of the decimal and two to the right. The value 12345 in that field is interpreted as 123.45. When you do arithmetic, the decimal alignment is handled according to the V position.
So 9(5)V2 and 9(7)V2 both have two decimal places; the first has five total digit positions (three integer, two decimal) and the second has seven (five integer, two decimal). The number of 9s (and S if present) determines the total digit capacity; V only fixes where the decimal point is.
PIC 9 means the field holds only non-negative values (zero and positive). PIC S9 means the field can hold negative values as well. The S is stored in a sign position: in DISPLAY it is combined with the rightmost digit (overpunch); in COMP it is the high-order bit; in COMP-3 it is the last half-byte (nibble). Use S9 for balances, adjustments, differences, or any value that can be negative.
The same PICTURE can be stored in different ways. USAGE (or the shorthand in the PICTURE) controls the internal format and size.
| USAGE | Storage | Typical use |
|---|---|---|
| DISPLAY | 1 byte per digit | I/O, screens, reports; human-readable |
| COMP / COMP-4 | 2, 4, or 8 bytes (binary) | Integer arithmetic, counters, IDs |
| COMP-3 | (n+1)/2 bytes (packed) | Money, quantities, exact decimal |
| COMP-1 / COMP-2 | 4 or 8 bytes (float) | Scientific; approximate; avoid for money |
Each digit is stored as a character (one byte per digit). The value is human-readable in memory. Good for data that comes from or goes to files or screens in character form. Arithmetic is possible but slower than COMP or COMP-3 because each digit is handled separately.
The value is stored in binary. Size depends on the number of digits: 1–4 digits use 2 bytes, 5–9 use 4 bytes, 10–18 use 8 bytes. Range for 2 bytes is -32,768 to 32,767; for 4 bytes roughly ±2 billion. No decimal places in storage; use COMP for integers (counters, IDs, subscripts). Fast for integer arithmetic.
Two decimal digits per byte (each half-byte holds one digit), with the sign in the last nibble (C for positive, D for negative). Exact decimal arithmetic; no rounding from binary. Standard for money and quantities. Size is (number of digits + 1) / 2 bytes (the +1 is for the sign). Example: S9(7)V99 has 9 digit positions, so (9+1)/2 = 5 bytes.
For whole numbers (no decimal part), use a PICTURE without V: e.g. 9(5) or S9(4). For values with decimal places (money, rates), use V: e.g. S9(7)V99. The number of 9s before V is the integer part; the number of 9s after V is the decimal part. Choose the sizes so the largest (and smallest, if signed) value you need fits.
1234567*> Integer: no V 01 WS-REC-COUNT PIC 9(6). *> 0 to 999999 01 WS-OFFSET PIC S9(4) COMP. *> -32768 to 32767 (2-byte binary) *> Decimal: with V 01 WS-BALANCE PIC S9(9)V99 COMP-3. *> Up to 9 digits + 2 decimals 01 WS-PERCENT PIC 9(2)V99. *> 0.00 to 99.99 (e.g. percentage)
For DISPLAY and COMP-3, the range is determined by the number of digits: n digits give 0 to 10^n - 1 (unsigned) or -(10^n - 1) to 10^n - 1 (signed). For COMP, the range is that of the binary size: 2-byte signed is -32,768 to 32,767; 4-byte is about ±2.1 billion. Be sure the values you store fit in the chosen PICTURE and USAGE.
Define a working-storage field for a customer balance that can be negative, up to 999,999.99. Use COMP-3.
Define a counter that will go from 0 to 99,999. Use COMP. How many bytes does it use?
Write a PICTURE for a signed quantity with 5 integer digits and 3 decimal places. Which USAGE would you use for a stock quantity?
1. What does the S in PIC S9(5) mean?
2. How is the decimal position defined for a numeric field?
3. PIC S9(5)V99 COMP-3 uses how many bytes?
4. Which USAGE is typically used for money amounts?