WRKQRY's rounding process

Any IBM i topic that does not fit in another forum
Post Reply
sps
Posts: 5
Joined: Fri Jun 27, 2025 8:40 pm

WRKQRY's rounding process

Post by sps »

I extracted the SQL of a "summary only" WRKQRY using RTVQMQRY. The query has "Use Rounding" set to Y. I've done this before, and with some tweaking and using aggregate functions, have been able to replicate queries in SQL accurately. In this case, however, I kept running into errors when trying to run my SQL code--I discovered that one of the fields, regardless of the length it was prescribed to be in the wrkqry, was giving a result that was filled out with trailing 0's (i.e. 0.08 became 0.08000000000...etc with about 25 trailing zeros). Any subsequent calculations with that result caused overflow issues, translating the result into all plus signs, etc.

ROUND() didn't seem to have any impact; using it on the calculated result field resulted in the same trailing 0's, even though neither of the elements in the calculation nor the result field they were placed in were of that length. I worked around the issue by wrapping the troublesome field in DECIMAL() and limiting it to the length of the field indicated in WRKQRY's field definition. This works, and the data matches now...almost completely. There are very small differences (like .01) in a couple records, which leads me to believe that WRKQRY does some rounding or truncating somewhere in the process of its calculations that I can't peg down. Does anyone have any insight to offer here on what WRKQRY may be doing under the hood that could clarify this for me? Many thanks!
Post Reply