10.12.2012 Views

Application Programming and SQL Guide - Kmlinux

Application Programming and SQL Guide - Kmlinux

Application Programming and SQL Guide - Kmlinux

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

|<br />

|<br />

|<br />

|<br />

v DEC31 rules allow a maximum precision of 31 digits in the result. DEC31 rules<br />

are in effect if any of the following conditions is true:<br />

– Either oper<strong>and</strong> of the operation has a precision greater than 15 digits.<br />

– The operation is in a dynamic <strong>SQL</strong> statement, <strong>and</strong> any of the following<br />

conditions is true:<br />

- The current value of special register CURRENT PRECISION is DEC31 or<br />

D31.s. s is a number between one <strong>and</strong> nine <strong>and</strong> represents the minimum<br />

scale to be used for division operations.<br />

- The installation option for DECIMAL ARITHMETIC on panel DSNTIP4 is<br />

DEC31, D31.s, or 31; the installation option for USE FOR<br />

DYNAMICRULES on panel DSNTIP4 is YES; <strong>and</strong> the value of CURRENT<br />

PRECISION has not been set by the application.<br />

- The <strong>SQL</strong> statement has bind, define, or invoke behavior; the statement is in<br />

an application precompiled with option DEC(31); the installation option for<br />

USE FOR DYNAMICRULES on panel DSNTIP4 is NO; <strong>and</strong> the value of<br />

CURRENT PRECISION has not been set by the application. See “Using<br />

DYNAMICRULES to specify behavior of dynamic <strong>SQL</strong> statements” on page<br />

487 for an explanation of bind, define, <strong>and</strong> invoke behavior.<br />

– The operation is in an embedded (static) <strong>SQL</strong> statement that you precompiled<br />

with the DEC(31), DEC31, or D31.s option, or with the default for that option<br />

when the install option DECIMAL ARITHMETIC is DEC31 or 31. s is a number<br />

between one <strong>and</strong> nine <strong>and</strong> represents the minimum scale to be used for<br />

division operations. See “Step 1: Process <strong>SQL</strong> statements” on page 462 for<br />

information about precompiling <strong>and</strong> for a list of all precompiler options.<br />

Recommendation: Choose DEC31 or D31.s to reduce the chance of overflow, or<br />

when dealing with a precision greater than 15 digits. s is a number between one<br />

<strong>and</strong> nine <strong>and</strong> represents the minimum scale to be used for division operations.<br />

Avoiding decimal arithmetic errors: For static <strong>SQL</strong> statements, the simplest way<br />

to avoid a division error is to override DEC31 rules by specifying the precompiler<br />

option DEC(15). In some cases you can avoid a division error by specifying D31.s.<br />

This specification reduces the probability of errors for statements that are<br />

embedded in the program. s is a number between one <strong>and</strong> nine <strong>and</strong> represents the<br />

minimum scale to be used for division operations.<br />

If the dynamic <strong>SQL</strong> statements have bind, define, or invoke behavior <strong>and</strong> the value<br />

of the installation option for USE FOR DYNAMICRULES on panel DSNTIP4 is NO,<br />

you can use the precompiler option DEC(15), DEC15, or D15.s to override DEC31<br />

rules.<br />

For a dynamic statement, or for a single static statement, use the scalar function<br />

DECIMAL to specify values of the precision <strong>and</strong> scale for a result that causes no<br />

errors.<br />

Before you execute a dynamic statement, set the value of special register<br />

CURRENT PRECISION to DEC15 or D15.s.<br />

Even if you use DEC31 rules, multiplication operations can sometimes cause<br />

overflow because the precision of the product is greater than 31. To avoid overflow<br />

from multiplication of large numbers, use the MULTIPLY_ALT built-in function<br />

instead of the multiplication operator.<br />

Chapter 1. Retrieving data 17

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!