Subject Re: Query giving "Unsuccessful execution caused by system error"
Author andrew_s_vaz
Hi Helen,

> Divide By Zero is a distinct arithmetic boo-boo that has its own
> exception. But your certainty about "illegal math" is an illusion.
>
> >It is working in the other app.
>
> "The other app" is using fixed decimal types too? Re-read
Alexandre's advice!

Interesting. This app was ported from Paradox, to DbIsam and now to
FB. Only in FB it gave me this error. I think that the others were
casting the results automatically. Even in Cobol back in the 80's I
was used to do this kind of stuff and get away with it. Go figure...

> >The types of data are:
> >
> >ITRPORCCOB DECIMAL(14,4),
> >ITRHON DECIMAL(14,4),
> >ITRMULTHON DECIMAL(14,4),
> >ITRDESCONTOTAB DECIMAL(14,4),
> >ITRVLRINDXFAT DECIMAL(14,4),
> >ITRMULTTAB SMALLINT
> >
> >as I need to work with BCD types. ITRMULTTAB is only a multiplier, so
> >it's a smallint.
> >
> >Are my definitions of BCD right? DECIMAL(14,4)?
>
> Scale of BCD numbers can be 1, 2, 3 or 4. If you only need 2, don't
use 4.

I really need 4, unfortunately. BCD is the only stuff I use for
monetary calculations and here I really use'em to full extent. Old
habits die hard.

>
> sum
> (
> (
> (
> (
> ( i.ItrHon * i.ItrMultHon /* result is now a (14,8) */
> * i.ItrVlrIndxFat) /* result is now a (14,12) */
> * (
> i.ItrPorcCob/100)) /* result is now an integer
> overflow: scale moves to 16, but the precision of the number is only
> 14. Actually, it's possible at this point that Firebird's
enforcement of
> precision will "forgive" here and accommodate this number as an
> (18,16). Then, it will be the next operation that blows it. */
>
> I'll leave you to muse upon the rest...
>
> * (1-(i.ItrDescontoTab/100)) )* i.ItrMultTab)) as
> VlrFat,
>
> If you don't have it already, pick up Geoff Worboys' white paper on
number
> types from www.ibobjects.com/TechInfo.html. It has helped a lot of
people
> (including me).

Great reading. Thanks. I'll remake the whole thing casting the interim
values and I bet the "problem" will disapear.

Andrew