Packed Decimal


Input data is stored in EBCDIC, or zoned decimal. Before it can be used in computations, it must be converted to a numeric format. One of the numeric formats is packed decimal.

An EBCDIC, or zoned decimal, field is packed as follows:


Character EBCDIC Representation Packed Decimal Representation
1234 F1 F2 F3 F4 01 23 4F
47 F4 F7 04 7F
572150 F5 F7 F2 F1 F5 F0 05 72 15 0F
1A2B3C F1 C1 F2 C2 F3 C3 01 12 23 3C
abcd 81 82 83 84 01 23 48
1234 40 40 F1 F2 F3 F4 00 01 23 4F
1234 F1 F2 F3 F4 40 40 01 23 40 04

Packed Fields

Use data type P with DS and DC instructions to define packed fields. A packed field contains C or F in the sign position if the number is positive, or it contains D in the sign position if the number is negative. If the field is larger than necessary to hold the given value, then it is padded on the left with zeros. If the field is not large enough to hold the value given, then the high order digits are lost.

Instruction Storage Defined
A    DS   PL4 4 byte field for packed data
B    DC   P'24680' 24 68 0C
C    DC   P'-7543' 07 54 3D
D    DC   PL5'15672' 00 00 15 67 2C
E    DC   PL3'3150083' 50 08 3C

The PACK Instruction

The PACK instruction is an SS instruction that packs the value in the second operand and stores it in the first operand.

Given the following definitions:

ONE      DC     C'ABCDE'
TWO      DC     C'12345'
THREE    DC     C'297'
FOUR     DC     C'  311'
FIVE     DC     C'110  '
SIX      DC     CL8'80723745'
SEVEN    DC     CL11'12345678901'
EIGHT    DS     PL3
NINE     DS     PL6

The following table shows the results of PACK instructions. Each instruction starts with the initial data given above.

PACK Instruction Operand 1 Operand 2
  PACK  EIGHT,TWO 12 34 5F F1 F2 F3 F4 F5
  PACK  EIGHT,THREE 00 29 7F F2 F9 F7
  PACK  EIGHT,ONE 12 34 5C C1 C2 C3 C4 C5
  PACK  EIGHT,SIX 23 74 5F F8 F0 F7 F2 F3 F7 F4 F5
  PACK  EIGHT,FOUR 00 31 1F 40 40 F3 F1 F1
  PACK  EIGHT,FIVE 11 00 04 F1 F1 F0 40 40
  PACK  NINE,SIX 00 08 07 23 74 5F F8 F0 F7 F2 F3 F7 F4 F5
  PACK  NINE,SEVEN 12 34 56 78 90 1F F1 F2 F3 F4 F5 F6 F7 F8 F9 F0 F1
  PACK  NINE(4),TWO 00 12 34 5F xx xx F1 F2 F3 F4 F5
  PACK  EIGHT(3),TWO(5) 12 34 5F F1 F2 F3 F4 F5
  PACK  EIGHT(2),TWO(3) 12 3F xx F1 F2 F3 F4 F5
  PACK  EIGHT,TWO(4) 01 23 4F F1 F2 F3 F4 F5

Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2003