Using the expression language

An expression is a sequence of operands, operators, and parentheses that the runtime system can evaluate as a single value.

The RTL Expression language follows the Java™ syntax for expressions and evaluation semantics. Expressions can include these components:

Operators

Table 1. RTL Operators
Operator Description Example Precedence
%

Arithmetic: Modulus

x % 2
8
*
Multiplication
x * y
7
/
Division
x / y
7
+
Addition
x + y
7
-
Subtraction
x - y
6
+
Concatenation
string + string 
5
<

Relational/Boolean: Less than

numeric < 100
4
<=
Less then or equal to
numeric <= 100
4
>
Greater than
numeric > 100
4
>=
Greater than or equal to
numeric >= 100
4
==
Equal to
numeric == 100
4
!=
Not equal to
numeric <> 100
4
!
Logical inverse (NOT)
!(x = y )
3
&&
Logical intersection (AND)
expr1 && expr2
2
||
Logical union (OR)
expr1 || expr2
1

The first column in the table describes the precedence order of the operators, listed highest to lowest. For example, the % modulus operator has a higher precedence than the * operator. Parentheses can be used to overwrite the precedence of operators.

Conditional Expressions

Conditional expressions allow you to express IF/ELSE statements.

Syntax:
 Boolean-expression?expression-1:expression-2

The ? operator indicates that this expression is conditional; the return value is dependent on the result of the Boolean expression. If the Boolean expression is TRUE, the first expression is the return value; otherwise, the second expression is the return value.

You can use the null keyword in the ternary conditional operator. The “if then” and “if else” operands can be either expressions or the keyword null. A property whose RTL expression yields “null” is not set. This is useful in cases where a property should be set only when a certain condition is met. Consider the case where the background color of a WORDBOX should be set to red when a variable value x drops below a value of 10. The expression for this would be:
x<10?Color.RED:null

Operands

Operands include:

  • Literal values
  • Other expressions
  • FGL Variables
  • RTL Class Members
    • Objects
    • Methods (returning a single value)

A literal value for a string in an expression should be delimited by double quotes: "Test".

Examples

For the purpose of these examples, order_line has been replaced with order.

  1. To add 10% to the itemprice: order.itemprice*1.10

    The data item order_line.itemprice is converted to a Numeric type, so we can use the Numeric operators. In order to display the result of a Numeric expression in a WordBox, we must convert the result to a String. See Example 1 in the Using RTL Classes section.

  2. Let's add 10% to the item price conditionally, depending on the value: order.itemprice<100?order.itemprice*1.10:order.itemprice

    The condition in this Boolean expression tests whether the itemprice is greater than 100; if so, the value returned is 110% of the itemprice; otherwise, the value returned is simply the itemprice.

  3. To set the font of a report item to italic when the FGL variable order_line.lineitemprice exceeds $20, we must create an expression for the fontItalic property: order.lineitemprice>20

    The property fontItalic is of type boolean, so any RTL expression that we use for that property must return a boolean value (TRUE/FALSE). Any of the relational operators yields a boolean, so the type of the returned value of this expression is a boolean (The expression will return TRUE if the lineitemprice exceeds 20).

Note: A numeric value by itself is not a boolean value.