Order of precedence

The following list describes the precedence order of expression elements. The order of precedence defines in which order the elements of an expression are evaluated.

For example, the MOD operator has a higher precedence as the * operator. When computing an expression like ( 33 MOD 2 * 5 ), the runtime system first evaluates (33 MOD 2) = 1 and then evaluates (1 * 5) = 5. The order of evaluation can be changed this by using parentheses: ( 33 MOD ( 2 * 5 ) ) = 3.

Table 1. Order of precedence list
P Syntax Element A Description Example
14
CAST(v AS type)
N Type casting
CAST(var AS 
fgl.FglRecord)
14
INSTANCEOF
L Type checking
var INSTANCEOF 
java.lang.Boolean
13
UNITS
L Single-qualifier interval
(integer) UNITS DAY
12
+
R Unary plus
+ number
12
-
R Unary minus
- number
11
**
L Exponentiation
x ** 5
11
MOD
L Modulus
x MOD 2
10
*
L Multiplication
x * y
10
/
L Division
x / y
9
+
L Addition
x + y
9
-
L Subtraction
x - y
8
||
L Concatenation
"Amount:" || amount
7
LIKE
R String comparison
mystring LIKE "A%"
7
MATCHES
R String comparison
mystring MATCHES "A*"
6
<
L Less than
var < 100
6
<=
L Less then or equal to
var <= 100
6
>
L Greater than
var > 100
6
>=
L Greater than or equal to
var >= 100
6
==
L Equals
var == 100
6
<> or !=
L Not equal to
var <> 100
5
IS NULL
L Test for NULL
var IS NULL
5
IS NOT NULL
L Test for NOT NULL
var IS NOT NULL
4
NOT
L Logical inverse
NOT ( a = b )
3
AND
L Logical intersection
expr1 AND expr2
2
OR
L Logical union
expr1 OR expr2
1
ASCII()
R ASCII Character
ASCII(32)
1
CLIPPED
R Delete trailing blanks
DISPLAY string CLIPPED
1
COLUMN (reports)
R Begin line mode display
PRINT COLUMN 32, "a"
1
(integer) SPACES
R Insert blank spaces
DISPLAY "a" (5) SPACES
1
SQLSTATE
R SQL State Code
IF SQLSTATE="IX000"
1
SQLERRMESSAGE
R SQL Error Message
DISPLAY SQLERRMESSAGE
1
USING
R Format character string
TODAY USING "yy/mm/dd"
1
:=
L Assignment
var:= "abc"

In this table, the P column defines the precedence, from highest (14) to lowest (1). Note that some operators have the same precedence (i.e. are equivalent in evaluation order). The A column defines the direction of association (L=Left, R=Right, N=None).