PACK is a SS2 instruction which is designed to convert data from character or zoned decimal format to packed decimal format. The operation proceeds by transferring the contents of operand 2 to operand 1. Bytes in operand 1 and 2 are referenced from right to left within the fields. The rightmost byte of operand 2 is referenced first, and the zone and numeric parts of the byte are reversed and placed in the rightmost byte of operand 1. Then the numeric parts of the next two bytes of operand 2 are placed in the next byte of operand 1. This process continues by “packing” the numeric parts of operand 2 into operand 1, always moving from right to left, taking two bytes and packing into one byte. The example below illustrates this idea. The first field, AZONED, contains zoned decimal data, while the second field, APK, shows the results of executing “PACK APK,AZONED”. We assume the following definitions,
AZONED DC ZL7’7893023’
APK DS PL4
Since PACK is SS2, each operand contributes a 4-bit length which is stored in the second byte of the object code as pictured at the top of this page. The maximum length in the object code is B’1111’ = 15. Since the assembler always decrements lengths by 1, packed fields are limited to a maximum of 16 bytes. It is also important to note that the lengths of both fields are used to execute this instruction. For instance, if APK was defined as PL3, the high-order digits in the packed field (those on the left) are truncated.
On the other hand, if there are too few bytes in operand 2, zeros will be padded on the left in operand 1 as illustrated below. Assume APK was defined as PL6.
Some unrelated PACK’s:
A DC C’12345’ = X’F1F2F3F4F5’
B DC Z’1234’ = X’F1F2F3C4’
C DC C’ABC’ = X’C1C2C3’
D DC X’12ABCDEF’ = X’12ABCDEF’
P DS PL3
Q DS PL2
R DS PL4
PACK P,A P = X’12345F’ SIGN UNCHANGED
PACK Q,A Q = X’345F’ LEFT TRUNCATION
PACK R,A R = X’0012345F’ PAD ZEROES
PACK P,B P = X’01234C’
PACK Q,B Q = X’234C’ LEFT TRUNCATION
PACK R,B R = X’0001234C’ PAD ZEROES
PACK P,C P = X’00123C’ PACK WILL PROCESS
ANY DATA WITHOUT
PACK P,D P = X’02BDFE’ IT WILL PACK...
1. PACK works with any kind of data. That does not mean that you will compute correct results. It simply means that the program will not abend because of the data contents in a field you are packing. Packed decimal problems show up when arithmetic instructions are executed.