×

Good News Everybody!

The new search engine is LIVE!

Please report any problems to david (at) midrange.com.




Hi all,

I've checked the archives and the SQL Reference but I'm unable to come to
the correct definition of a host variable which is Fetched Into.
I'm on V7R1. While testing I am running the program in debug to check for
and correct any errors/warnings.

My cursor is created from

SELECT sum(dhqtss * dhpack)
FROM dsthstp
WHERE dhitm# = ?
AND dhcus# = ?
AND dhindt >= ?

Both fields dhqtss and dhpack are defined as 5p 0 in the file DSTHSTP.

I then create a cursor from the above SQL statement and Fetch from the
cursor into a host variable shippedUnits. My problem is with the
definition of shippedUnits.

When I change the definition of shippedUnits to 31p 0 (the max from the
manual) there is no warning. But when I change the definition to 11p 0
(what I thought should be the min) I get the warning.

I was calculating the precision as follows. Please let me know where I am
going wrong.

First dhqtss (5p 0) and dhpack (5p 0) are multiplied together which I
think produces a result of 10p 0.
(From the SQL reference)
<snip>Multiplication
The precision of the result of multiplication is min (mp,p+p') and the
scale is
min(ms,s+s').
</snip>

The SUM function is then used which is understand to be basically
addition.

(From the SQL reference)
<snip>Addition and subtraction
The scale of the result of addition and subtraction is max (s,s'). The
precision is
min(mp,max(p-s,p'-s') +max(s,s')+1).
</snip>
So I would think the precision is 10 + 1 or 11 which leads to 11p 0.

I think it's the SUM function that I'm not calculating correctly. This is
my thought process but obviously it is incorrect. Can someone please
point out where I'm going wrong so I don't make this error again in the
future.
Thanks,

Robert Rogerson

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2026 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.