Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA

Posted: Tue Jan 10, 2006 3:50 am Post subject: Re: Whats the solution for this REDEFINE question

Hi mijanurit,

Both vinodmaanju and gowtham_1982 are correct. the 9(5) field will contain the same hex value as the X(5) field. the difference come when you try to use the field.

First, you understand the hex representation of the numbers?

Shown below are 0-9 0 = x?F0?, 1 = x?F1? etc.

Code:

0123456789
FFFFFFFFFF
0123456789

Given a PIC 9(5) value 12345

This is an unsigned field where the hex value will be ?F1F2F3F4F5?. When addition is performed on this only the low order 4 bits of each byte are considered for the magnitude of the value. The high order 4 bits do not play any part, the sign is assumed to be + (positive).

Given a PIC S9(5) value +12345

This is a signed field where the hex value will be ?F1F2F3F4C5?. ?F1F2F3F4D5? if the value was -12345. When addition is performed only the low order 4 bits are considered for the magnitude of the number and the high order 4 bits of the last byte is considered for the sign.

Normally in a PIC S9(?) field the sign 4 bits will be ?C? = ?+? and ?D? = ?-?.

Now, when addition is performed on a PIC 9(?) or S9(?) field. The field is converted to COMP-3, the addition performed, and converted back to zoned decimal.

When you convert a zoned decimal number to a PIC 9(?) COMP-3 (unsigned) anything can be in the sign bits (x?0? ? x?F?) When converted, the COMP-3 sign bits will always be x?F? and when converted back to the zoned decimal format the sign bits x'F' will remain.

When you convert a zoned decimal number to a PIC S9(?) COMP-3 (Signed) only x?A? ? x?F? can be in the sign bits.
x?A?,x?C?,x?E?,x?F? will be ?+? and x?B?, x?D? will be ?-?. When converted the sign bits will always be either x?C? or x?D?. Anything other than x?A? ? x?F? will cause an 0C7 abend. The sign bits of s successfull add x'C' or 'D' will remain when converted back to zoned decimal.

In both cases, signed and unsigned, anything in the low order 4 bits of each byte other than x?0? ? x?9? will cause an 0C7 abend.

That?s why, when you redefine a PIC X(5) VALUE = ?123 3? as a PIC 9(5) or as a PIC S9(5) the space is converted to a 0 (zero). The hex value of the space is x?40?. This is not the sign byte, so the high order 4 bits the ?4? is ignored, and the low order 4 bits '0' are x?0? ? x?9?.

The ?123 3? is converted to VALUE 12303. x?F1F2F3F0F3? for PIC 9(5) and x?F1F2F3F0C3? for S9(5)

And that?s why you will get an 0C7 abend if your try ?123=3? because the ?=? = x?7E?. The 'E' is not x'0' - x'9'

Or when you try ?1234.? Where ?.? = x?90? and if you try to add to an S9(5) you get an 0C7. The '9' is the sign bits and not one of the allowed values. And converts to ?12340? if you add to an 9(5) because the sign bits are ignored.