How to compare a PL8 field

High Level Assembler(HLASM) for MVS & VM & VSE

How to compare a PL8 field

Postby lakshmi.guna » Thu Mar 25, 2010 10:24 am


I have to compare first two positions of a PL8 field CTLNO# with '95' and '96'. Currently my piece of code is like below:

BE exit routine
BE exit routine

The declarations are like below:
CP95 DC PL1'95' *PACKED 95*
CP96 DC PL1'96' *PACKED 96*

But, with this code it is not comparing the first two positions of CTLNO with 95 or 96. Can anyone help me out....
Posts: 1
Joined: Thu Mar 25, 2010 10:10 am
Has thanked: 0 time
Been thanked: 0 time

Re: How to compare a PL8 field


Re: How to compare a PL8 field

Postby Robert Sample » Thu Mar 25, 2010 5:22 pm

Oh, my -- how many errors can you make in a short assembler code segment?

1. A PL1 field can only hold values from 0 to 9 -- one byte minus the half-byte for the sign leaves one half byte, which can hold just one digit.
2. Compare Logical Character doesn't do well with packed data -- that is why the CP (Compare Packed or Compare Decimal) instruction was created.
3. A PL8 field is going to be right justified unless you've messed up the code, so comparing the first two bytes via the CLC won't give you much of a match. Unless the value is something like 951234123412345, that is.
4. Why are you not studying -- carefully -- the generated code in the Assembler listing to see these types of things?
Robert Sample
Global moderator
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Re: How to compare a PL8 field

Postby Scott Lippincott » Wed Jul 28, 2010 9:41 am

First, a PL8 field with valid packed data has 15 digits and a trailing sign nibble. The value is right-justified.
For example:
The number +123451234567890 is stored in 8 bytes as x'123451234567890C'.
The value -95365 is stored in 8 bytes as x'000000000095365D'.

If you wanted an 8 digit number(+12345678), it would require a 5 byte packed field with a capacity of 9 digits x'012345678C' (number of digits in a packed field is always odd, so storing 8 digits in 5 bytes results in a leading zero)

I'm not sure what you mean by "first 2 positions of a PL8 field" This could be interpreted as 2 digits(one byte), or two bytes(with a value of x'9596').

If you meant that you wanted to test the first 2 digits of a 15-digit packed field, you CAN compare the leftmost byte of the field with CLI or CLC instructions.
ZAP CTLNO,=P'950000000000000'
BE . . .
BE . . .
CON9596 DS 0CL2
CON95 DC X'95' DC PL1'95' is invalid(value exceeds field size); DC P'95' is a 2 byte field with a value of x'095c'
CON96 DC X'96'

If you meant the first two bytes of the packed field. Using the storage defined above:
CLC CON9596,CTLNO (using the CON9596 as the first operand causes the length of the compare to be 2 bytes)
BE . . .
CLC CTLNO(2),CON9596 (length must be coded, or the length used would be the length of the first operand 8 bytes)
BE . . .
This all works ONLY if the digits you are testing for in the packed field are in a fixed position, and the pair(s) of digits exist in the same byte(s).
Scott Lippincott
Posts: 5
Joined: Wed Jul 28, 2010 7:30 am
Has thanked: 0 time
Been thanked: 0 time

Re: How to compare a PL8 field

Postby steve-myers » Thu Jul 29, 2010 4:28 pm

I would love to have the original statement of this problem rather than lakschmi.guni's interpretation of the problem. A PL8 field is very rare, except when used with the CVD and CVB instructions. Fifteen digits are rare, too, unless you're talking about the national debt of the United States, so I think something got missed here.
Global moderator
Posts: 1885
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 197 times

Return to Assembler


  • Related topics
    Last post