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 ZL77893023

APK DS PL4

...

PACK APK,AZONED

 

 

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 B1111 = 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.

 

PACK APK,AZONE

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.

 

PACK APK,AZONED

 

 

 

Some unrelated PACKs:

A DC C12345 = XF1F2F3F4F5

B DC Z1234 = XF1F2F3C4

C DC CABC = XC1C2C3

D DC X12ABCDEF = X12ABCDEF

P DS PL3

Q DS PL2

R DS PL4

 

PACK P,A P = X12345F SIGN UNCHANGED

PACK Q,A Q = X345F LEFT TRUNCATION

PACK R,A R = X0012345F PAD ZEROES

PACK P,B P = X01234C

PACK Q,B Q = X234C LEFT TRUNCATION

PACK R,B R = X0001234C PAD ZEROES

PACK P,C P = X00123C PACK WILL PROCESS

ANY DATA WITHOUT

ABEND

PACK P,D P = X02BDFE 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.