Packed Decimal
About
The numeric digits are packed (2 digits per byte) with the last half of the last byte 'F' (for unFormatted).
Signed fields have a 'C' (for Credit / +) or 'D' (for Debit / -) as the last half of the last byte.
To calculate the size of the packed decimal field required to store an x digit number use: (x + 1) / 2
To calculate the number of digits a packed decimal field of size x will store use: (x * 2) - 1
Limits:
COBOL programs can only handle a maximum of 18 digits by default, although this can be extended to 31 via the 'ARITH(EXTEND)' compiler option.
Other:
Also known as 'PD'.
Implied decimal places.
Use:
Mainly used on OS/390, although they can be used elsewhere.
Fastest data type for calculations on OS/390.
Examples
Unsigned
12345 is encoded in hex as 135 24F 12345.67 is encoded in hex as 1357 246F
Signed
+12345 is encoded in hex as 135 24C -12345.67 is encoded in hex as 1357 246D
Packed Decimal field sizes
No. of digits | No. of bytes | No. of digits | No. of bytes | |
---|---|---|---|---|
1 | 1 | 17 | 9 | |
2 | 2 | 18 | 10 | |
3 | 2 | 19 | 10 | |
4 | 3 | 20 | 11 | |
5 | 3 | 21 | 11 | |
6 | 4 | 22 | 12 | |
7 | 4 | 23 | 12 | |
8 | 5 | 24 | 13 | |
9 | 5 | 25 | 13 | |
10 | 6 | 26 | 14 | |
11 | 6 | 27 | 14 | |
12 | 7 | 28 | 15 | |
13 | 7 | 29 | 15 | |
14 | 8 | 30 | 16 | |
15 | 8 | 31 | 16 | |
16 | 9 |