Use BINARY/COMP for counters, indexes, and flags. Use PACKED-DECIMAL/DISPLAY for currency and precise decimal math.
12301 I16 PIC S9(4) BINARY. *> ~2 bytes 01 I32 PIC S9(9) BINARY. *> ~4 bytes 01 I64 PIC S9(18) BINARY. *> ~8 bytes
Compiler options can influence exact mapping. Check documentation.
Digits | Bytes | Signed Range (approx) |
---|---|---|
1–4 | 2 | -32768 .. 32767 |
5–9 | 4 | -2,147,483,648 .. 2,147,483,647 |
10–18 | 8 | ~±9.22e18 |
1201 COUNT PIC 9(5) BINARY. *> Unsigned 01 OFFSET PIC S9(5) BINARY. *> Signed
Alignment affects how fields are placed in memory; aligned fields may be faster to access.
Mistake | Problem | Fix |
---|---|---|
Using BINARY for money | Rounding/inexact values | Use PACKED-DECIMAL |
Overflow | Negative wrap/abend | Use a wider type; validate inputs |
Usage | Meaning | Example |
---|---|---|
BINARY | Binary integer | PIC S9(9) BINARY |
COMP | Compiler-mapped binary | PIC 9(4) COMP |
COMP-5 | Native binary (compiler-specific) | PIC S9(9) COMP-5 |
1. Which usages indicate binary integers?
2. Best for money?
3. Why alignment matters?