I was looking into the Z-ADD opcode and building an understanding of it. Suddenly I noticed that an operation extended H (Half adjust) can be used with it to make it Z-ADD(H)
but I am not getting any difference in Z-ADD and Z-ADD(H) results at my end. I wrote this program that uses Z-ADD and Z-ADD(H) opcode in calculation specs. The result is the same in both cases.
Dnum1 S 3P 0 inz(542)
Dres S 3P 0
C Z-ADD num1 res
C Z-ADD(H) num1 res
C res dsply
C return
Why do we use z-add(h) in the rpgle program? Please explain with an example so that I can understand how it works.
Z-Add(H)
is nothing but itsZ-ADD
withoperation extender H
added to Z-ADD which makes the result half-adjusted i.e. It rounds up the results. Factor 2 is added to a field of zeros. The result field contains the total. There is no use of Factor 1. Factor 2 and the result field must be in the numeric range and may include an array, an array element, a field, a named constant, a literal, a figurative constant, a subfield, or a table name. Sample code using Z-ADD(H) in rpgle.Due to the presence of operation extended (H) with Z-ADD the result field gets rounded up. The result field would contain 110.4579 which is the rounded result of 110.456789 since the result field is (8P,5) which is lesser than the number field (9P,6).