In calculations involving many large fields, you can control your results better by breaking the expression into parts, calculating each part as a separate result field. Then you can use these result fields in an expression to calculate the result field you want. You can specify length and decimal positions for the intermediate result fields to minimize the length of the final result field.

For example:

X12 = (1.2998 − P − Q)/((R + S) * (T − U)) + 6

Instead of defining result field X12 in one step as above, you could do it in three:

X12PART1 = 1.2998 − P − Q

X12PART2 = (R + S) * (T − U)

X12 = X12PART1/X12PART2 + 6

If the user knows that X12PART1, for example, is always a number between 0 and 1.2998, the user can specify 5 for Len and 4 for Dec (on the Define Result Fields display) for X12PART1. This decreases the length of X12.

Length and decimal positions used for internal numeric calculations in Query for iSeries

The following formulas define the maximum length and decimal positions used internally by Query for decimal calculations for numeric result fields. The maximum length and decimal positions do not necessarily correspond with the presentation length and decimal positions assigned by Query. The symbols p and d denote the length and decimal positions of the first operand. The symbols p1 and d1 denote the length and decimal positions of the second operand.

Addition and subtraction in Query for iSeries

The maximum length for the result field:

min(31,max(p-d,p1-d1)+max(d,d1)+1).

The maximum decimal positions:

max(d,d1).

Multiplication in Query for iSeries

The maximum length for the result field:

min(31,p+p1)

The maximum decimal positions:

min(31,d+d1).

Division in Query for iSeries

The maximum length for the result field:

31

The maximum decimal positions:

31-p+d-d1.

Chapter 17. Additional information about Query for iSeries for programmers 189

Page 201
Image 201
IBM SC41-5210-04 manual Addition and subtraction in Query for iSeries, Multiplication in Query for iSeries