Packed Decimal

Packed Decimal Numbers
Packed-decimal format means that each byte of storage (except for the low order byte) can contain two decimal numbers. The low-order byte contains one digit in the leftmost portion and the sign (positive or negative) in the rightmost portion. The standard signs are used: hexadecimal F for positive numbers and hexadecimal D for negative numbers. The packed-decimal format looks like this:

'''Figure 86. Packed-Decimal Format'''



The sign portion of the low-order byte indicates whether the numeric value represented in the digit portions is positive or negative.

Determining the Digit Length of a Packed-Decimal FieldUse 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 30.

Packed fields can be up to 16 bytes long. Table 12 shows the packed equivalents for zoned-decimal fields up to 30 digits long:

'''Table 12. Packed Equivalents for Zoned-Decimal Fields up to 30 Digits Long'''

Characteristics of a Packed Decimal Number

 * 1) variable length (the length is contained in the instruction)
 * 2) no boundary alignment
 * 3) 2 decimal digits per byte (except the low order byte)
 * 4) low order byte contains one decimal digit and sign
 * 5) the sign nibble is:
 * 6) x'C' = positive
 * 7) x'D' = negative
 * 8) x'F' = unsigned bit (assumed positive)
 * 9) also called Binary Coded Decimal (BCD)
 * 10) maximum size of a packed decimal is 31 digits or 16 bytes
 * Note:
 * Only 30 digits are allowed. If you use positional notation for 16-byte packed fields, you must use the PACKEVEN keyword or otherwise define the field as having 30 digits.