Determining the Digit Length of a Packed-Decimal Field
Use the following formula to find the length in digits of a packed-decimal
field:
Number of digits = 2n - 1,
...where n = number of packed input record positions used.
This formula gives you the maximum number of digits you can represent in packed-decimal format; the upper limit is 63.
Packed fields can be up to 32 bytes long. Table 1 shows the
packed equivalents for zoned-decimal fields up to 63 digits long:
Zoned-Decimal
Length in Digits |
Number of Bytes
Used in Packed-Decimal Field |
---|---|
1 | 1 |
2, 3 | 2 |
4, 5 | 3 |
⋮ | ⋮ |
28, 29 | 15 |
30, 31 | 16 |
⋮ | ⋮ |
60, 61 | 31 |
62, 63 | 32 |
For example, an input field read in packed-decimal format has a length of five bytes (as specified on the input or definition specifications). The number of digits in this field equals 2(5) - 1 or 9. Therefore, when the field is used in the calculation specifications, the result field must be nine positions long. The PACKEVEN keyword on the definition specification can be used to indicate which of the two possible sizes you want when you specify a packed subfield using from and to positions rather than number of digits.