Using the expression language
An expression is a sequence of operands, operators, and parentheses that the runtime system can evaluate as a single value.
Operators
Operator | Description | Example | Precedence |
---|---|---|---|
|
Arithmetic: Modulus |
|
8 |
|
Multiplication |
|
7 |
|
Division |
|
7 |
|
Addition |
|
7 |
|
Subtraction |
|
6 |
|
Concatenation |
|
5 |
|
Relational/Boolean: Less than |
|
4 |
|
Less then or equal to |
|
4 |
|
Greater than |
|
4 |
|
Greater than or equal to |
|
4 |
|
Equal to |
|
4 |
|
Not equal to |
|
4 |
|
Logical inverse (NOT) |
|
3 |
|
Logical intersection (AND) |
|
2 |
|
Logical union (OR) |
|
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.
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.
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".
FGL Variables
The data types of FGL variables are taken into account when constructing expressions. For every FGL variable an object is created that is either an instance of a FGLNumericVariable or an FGLStringVariable. These objects hold the value of the FGL variable, and at the same time they contain a member variable value which also contains the value. For this reason, it is legal to write "order_line.itemprice" in your expression as a shortcut for "order_line.itemprice.value". Both types of objects have these specific member variables defined as in Table 2.
Name | Description |
---|---|
value |
The value of the FGL variable. |
fglValue
(FGLNumericVariable only) |
The value of the field as formatted by the DVM. |
name |
A String specifying the name of the field. |
caption |
A String specifying the title of the field. |
type |
A String specifying the RTL type of the field. |
isoValue |
The locale and formatting-independent representation of the value of the variable. |
The conversion table lists FGL data types and the type into which they are converted within an RTL expression, as in Table 3.
FGL type | Corresponding RTL type |
---|---|
CHAR, VARCHAR, STRING, TEXT, DATE, DATETIME, and INTERVAL | FGLStringVariable |
INTEGER, SMALLINT, FLOAT, SMALLFLOAT, DECIMAL and MONEY | FGLNumericVariable,
limited to 15 significant digits. The value of a number larger than 15 digits will be
truncated, and the resulting number is rounded. For example, 12345678901234567 will
be rounded to 123456789012346 . |
To avoid problems with inaccurate totals on a report due to rounding, do not perform RTL arithmetic on either the individual values or the total value; calculate the value of the item in the BDL program instead, before passing the value to the report.
Examples
For the purpose of these examples, order_line
has been replaced with
order
.
- 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 Word Box, we must convert the result to a String. See Example 1 in the Using RTL Classes section.
- 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.
- To set the font of a report item to italic when the BDL 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 returnTRUE
if the lineitemprice exceeds 20).
A numeric value by itself is not a boolean value as it is in some programming languages.