Arithmetic definitions

<< Click to Display Table of Contents >>

Navigation:  Reference > Commands >

Arithmetic definitions

An arithmetic definition command takes one of the forms:

DI ivar = arithmetic expression,

DJ ivar = arithmetic expression,

D field = arithmetic expression,

DW wvar = arithmetic expression,

The arithmetic expression is computed and the result assigned to the variable. For examples of arithmetic expressions see the separate chapter.

If the data is CSV then the string definition which picks up raw data will start with $* which means the column with the header which is the same as the variable being defined.

If the destination is an ivar or a field, and the result of the arithmetic is not a whole number, then the result will be rounded before it is stored.

Use DJ if the largest number it will need to hold may exceed 9 digits.

In the case of fields, the code equivalents of the resulting value are then placed in the field. The value is placed with one digit (0-9) in each data location. Leading zeros are used. If the value is negative a minus sign (X code) will be placed in the first data location. If the resulting value is too large to fit in the field, then the character set by format OFO (Output Field Overflow) is put in all data locations of the field. If the value is undefined, the character set by format OFU (Output Field Undefined) is put in all data locations of the field.

IMPORTANT: Be very careful when using / (divide). Please study the following definitions:

ds $test=$sum/10,

di $test=$sum/10,

CL uses the type of variable being defined to determine what the expression is. In the first case above $test has one bit which is set true if $sum has the value 10. In the second case test is set to the value of $sum divided by 10. Similarly the following definition depends on the type of variable being defined:

=$stot/10+11,

If a field/ivar/wvar is defined with the above CL script will divide $stot by 10 and then add 11 to the result.

Examples of arithmetic definition commands:

d $123-125=765,

d $9165-9166=$tot*5,

d $101-101=$sum/10,

di $fred=u,

di $tot=2,

di $tot=$tot+1,

di $date=$dd+($mm*100)+($yy*1000),

dj $bignum = $ithis * $ithat * $iplus,

dw $daily=$sal/365.0-10.0,

dw $cell=#2a(r2,c0),

dw $tot=$wpart+($big/2.0),

 

di $area = $*,

dw $cost = $*,