CP is a SS2 instruction which is used to compare packed decimal fields. This instruction sets the condition code to equal (condition code = 0), low (condition code = 1) or high (condition code = 2) based on a comparison of the two fields as decimal numbers, and indicates how the first operand compares to the second operand. The fields may be of equal or different sizes. The only restrictions on the field lengths is that they must be a maximum of 16 bytes in length (the typical restriction for SS2 fields). Consider the fields and instructions below.

 

APK DC P123 = X123C

BPK DC PL3100 = X00100C

CHX DC X123F

...

CP APK,BPK C.C.= HIGH

CP APK,CHX C.C.= EQUAL

CLC APK,CHX C.C.= LOW

 

In the first CP, the fields are compared arithmetically and it is found that +123 is greater than +100. In the second compare, the condition code is set to equal since +123 is equal to +123 (xF is a valid plus sign). The third compare is a logical compare rather than an arithmetic compare. Since x3C is lower than x3F in the EBCDIC collating sequence, the condition code is set to low.

After setting the condition code with a CP, the condition code can be tested with a branch instruction. The typical branch instructions you might use are BE or BNE, BL or BNL, and BH or BNH.

 

Some unrelated CPs:

QPK DC P12345 = X12345C

RPK DC P-32 = X032D

SZONED DC Z11 = XF1C1

...

Results:

CP QPK,=P20 C.C. = HIGH

CP RPK,=P20 C.C. = LOW

CP SZONED,=P999 ABEND - SZONED IS NOT PACKED

CP QPK,QPK C.C. = EQUAL

CP QPK,RPK C.C. = HIGH

CP RPK,QPK C.C. = LOW

CP QPK,=X324A C.C. = HIGH - LITERAL IS VALID PACKED DATA

CP QPK+2(1),RPK BAD IDEA, BUT IT DOES WORK C.C. = HIGH,