Arithmetic operations in the expression handler - Connect_CDC - connect_cdc_mimix_share - 5.8

Connect CDC System Reference Guide

Product type
Product family
Connect > Connect CDC (MIMIX Share)
Product name
Connect CDC
Connect CDC System Reference Guide
First publish date

The Expression Handler has three types of variables for numeric literals used in arithmetic operations: integer, floating point, and decimal. Input values from the DBMS can come from columns that have more inclusive types, such as short, integer, long, float, double, and decimal.

The Expression Handler has a decimal type for representing fixed point numbers, numbers with precision and scale (that is, having a decimal point), that can participate in arithmetic calculations (add, subtract, multiply, and divide) and produce an exact result.

To represent decimal type in the grammar, the Expression Handler uses a DECIMAL type modeled on SQL:

<decimal type> ::= DECIMAL
         |  DECIMAL ( <precision> )
         |  DECIMAL ( <precision> , <scale> )

The following synonyms for DECIMAL are allowed: “DEC”, “decimal”, and “dec”. The default is DECIMAL(9,0) if DECIMAL is coded with no explicit precision and scale. The SQL standard states that scale is 0 and precision is implementation-defined in this case.

Note: The DB2 default is DECIMAL(5,0).

A DECIMAL type can be specified in any of the above forms along with the other existing types (BOOLEAN, CHARACTER, DOUBLE, and INTEGER) in the following places:

  • Definition of a user procedure input parameter

  • RETURNS clause, which indicates the datatype of the return value

  • Declaration of a variable in a complex expression, either unnamed or named (user procedure).

For example:

procedure pay_check ( decimal(9,2) salary, decimal(9,2) bonus )
returns decimal(9,2);
 declare decimal(9,2) total = 0.0;
 declare decimal(9,2) commission = 10.1;
  total = salary + bonus + salary*commission;
 return total;

Numeric values with a functional component include 2 types:

  • Floating point literals

  • with exponent indicator (“E”)

  • with float (“F”, “f”)

  • with double (“D”, “d”) suffix

  • A fixed point literal defined as a number with a decimal point; for example, 2.0, 0.1, or 2.1.   

They are processed as follows:

  • Floating point literals as type DOUBLE

  • Fix point literals as type DECIMAL

Note: The Expression Handler uses the BigDecimal type internally both to store and calculate values defined as decimal. This is effectively transparent to the user as far as coding an expression is concerned.
  • Use the following function to lop off the fractional portion of a decimal number with no rounding; that is, to convert the value 123.66 to 123:

  • Use the following function to add a decimal point to a decimal(5) number, and convert it to a decimal(3,2), with no rounding:

The method “todecimal(12367)/100.0;” transposes the input value of “12367” to an output value of “123.67”

  • If you are working with older applications, use the following function to convert a decimal(7) number that contains a date in the form CYYMMDD, into a date string in the standard format, YYYY-MM-DD:

procedure CYYMMDD(decimal(7) input_dec_date) returns char;
/* Inputs a date in special i5 format of CYYMMDD and */
/* returns a date in the standard Java format of yyyy-mm-dd”“yyyy-mm-dd”   */
declare int input_int_date = tointeger(input_dec_date);
declare char input_date;
declare char def_date = '1901-01-01';
declare char century;
declare char years;
declare char months;
declare char days;
declare char year;
declare char yyyymmdd;
/* negative numbers are invalid */
   if (input_int_date <= 0)
       return def_date;
/* also eliminate numbers with too many digits */
if (length(tostring(input_int_date)) > 7)
       return def_date;
/* convert the number to 0-padded string in form CYYMMDD */
/* split into parts */
century = substring(input_date, 1, 1);
years   = substring(input_date, 2, 2);
months  = substring(input_date, 4, 2);
days    = substring(input_date, 6, 2);
/* check for invalid months in a year */
if ( tonumber(months) gt 12 or tonumber(months) eq 0)
       return def_date;
/* check for invalid days in a month */
if ( tonumber(days) gt 31 or tonumber(days) eq 0)
       return def_date;
/* interpret century in AS/400 standard way */
        case  0:   
            year = '19';
        case  1:   
            year = '20';
        case  2:   
            year = '21';
        case  3:   
            year = '22';
        case  4:   
            year = '23';
        case  5:   
            year = '24';
        case  6:   
            year = '25';
        case  7:   
            year = '26';
        case  8:   
            year = '27';
        case  9:   
            year = '28';
           return def_date;
   year = concat(year, years);
   yyyymmdd = concat(year, months, days);
    return dateformat ( yyyymmdd , 'yyyy-MM-dd' , 'yyyyMMdd');