Try OpenEdge Now
skip to main content
BPM Events User's Guide
The rule language : Rule structure : Relational expressions and operands : Type conversions
 
Type conversions
Arithmetic expressions may combine subexpressions of any numeric type: real number (float) or integer (int). Enforce the conversion of any expression using such type conversion functions as toInt(), toString(), toDate(), toFloat().
Assume the attributes mydeadline and totalamount of the event evt1 contain respectively a String value representing a Java date of year 2000, and the String value "1050.25". The following conditional expressions are syntactically correct, and TRUE:

(toDate(evt1.mydeadline) < YEAR:2001)
(toInt(evt1.totalamount)
= 1050)

(toFloat(evt1.totalamount) >= 1000)
(evt1.totalamount
+ " dollars
" = "1050.25 dollars") (toInt(evt1.totalamount)
+ 100 = 1150)
Default conversions (or type inference) are automatically completed when the expected type is determined at compilation time, as in the case above where one operand of each expression shows the expected type (constants). Therefore, the corresponding pairs of conditions are equivalent:

(evt1.totalamount = 1050)
is
equivalent to:

(toInt(evt1.totalamount) = 1050)
(evt1.totalamount
> 1050.25 - evt2.rebate)

is equivalent to:
(toFloat(evt1.totalamount)
> 1050.25 - toFloat(evt2.rebate))

However, if an integer is divided by an integer, then the result is not a real number (float); it is an integer rounded to the integer value of the quotient.
Use conversion functions in the following situations:
*toInt() can take as argument an expression with:
*a String type, in which case the string is assumed to contain a valid numeric representation (int or float)
*a Date type, returning an integer that represents a date in terms of milliseconds.
*toFloat() can take:
*a String type, in which case the string is assumed to contain a valid numeric representation (int or float)
*an Int type, returning a Float (real) representation.
*toString() can take:
*a Date type, in which case the returned value is a string that represents the date in a readable format.
*an Int type or a Float type, returning a string representation.
*toDate() can take:
*a String type, in which case the string is assumed to contain a long integer which is a valid representation of a Java date (milliseconds since Jan 1st, 1970). Note that an expression like: toDate(toString(event1.date )) is not equivalent to: event1.date, as toString() converts the date in a different format intended for human readers.
*an Int type, returning a date representation. The Int type is assumed to contain a valid date representation.
As a good practice, we recommend that you always use type conversion functions when needed, and to not rely on implicit type conversions, except between numeric types such as float and int. Indeed, the default type conversions are handled as usually done in programming languages, and makes it possible to mix int types and float types in the same expression. For example, the following expression is correct, and results in a float value, because at least one of its operands is a float.
toInt(evt1.totalamount) + 250.75
The attribute totalamount of the event requires a conversion, as event attributes are always accessed as string values (except for the attribute date).
However, implicit type conversion is supported when the expected type is statically inferred, that is, at compile time. For example, the following expression compiles successfully and executes properly:
evt1.totalamount + 250.75.