Operators and precedence

The following table lists the EGL operators in order of decreasing precedence. Some operators have multiple meanings, depending on context. EGL sometimes uses special characters to represent type extensions (see Type extension characters) and delimiters (see Delimiters).

This table does not include the assignment operator (=) or complex assignment operators (such as +=). For more information on these special cases, see Assignments.

Operators (separated by commas) Meaning
. The member access operator (a dot) provides access to members of an entity, such as fields within records, functions within libraries, or properties within variables. Multiple levels of qualification are permitted. Members become more specific as you move from left to right.
@ The @ operator indicates that a name refers to a property rather than a field.
new The new operator calls the constructor function (a special function that creates a new variable) for a reference variable (a variable that contains an address rather than a value). Except in the case of some ExternalType parts, this is a default constructor that takes no parameters; see "new operator."
[] The array access operator (brackets) separates an index value from an array name, or a substring value from a character variable name. a[x] is an array subscript and b[x:y] is a substring.
+, - Unary plus (+) or minus (-) is a sign that precedes an operand or parenthesized expression, not an operator between two expressions.
** ** is the exponent operator, which can be read as "to the power of." For example c = a**b means that c is assigned the value of a to the power of b. The first operand (a in the example above) is a FLOAT that cannot have a negative value. The second operand (b in the example above) is a FLOAT literal or variable, positive, negative or 0.
*, /, &, |, xor Multiplication (*), integer division (/), and three bitwise operators are of equal precedence. Division of integers can result in a fractional value; for example, 7/5 yields 1.4.

Each of the bitwise operators and (&) , or (|), and exclusive or (xor) perform a bitwise operation on two operands, returning a value of type INT. Either operand may be of type HEX(2), HEX(4), HEX(8), INT, or SMALLINT. The operation begins by converting any HEX or SMALLINT operand to type INT. In the case of HEX, the operation left-pads the operand's value with zeros until the length is 4 bytes.

% % is the remainder operator. It resolves to the modulus when the first of two operands or numeric expressions is divided by the second. For example, 7%5 yields 2.
+, - Addition (+) and subtraction (-) are binary operations (requiring two operands) of equal precedence.
as The casting operator specifies a type (second operand) for the first operand; see as operator.
::, ?:, + EGL uses two operators exclusively for concatenation (:: and ?:). The plus sign is also used as a concatenation operator. For distinctions between them, see Concatenation operators.
==, !=, <, >, <=, >=, isa Logical operators for Boolean comparison are of equal precedence; each expression that contains one of these operators evaluates to either TRUE or FALSE.
! ! is the not operator, which EGL evaluates to a Boolean value (true or false) opposite to the value of a logical expression that immediately follows. That subsequent expression must be in parentheses.
is, not, in, like, matches These logical operators used for comparison are of equal precedence; each expression that contains one of these operators is evaluated as true or false. See "in operator," "like operator," "matches operator."
&&, and && (also spelled out as and) means "both must be true." An expression resolves to TRUE if both logical expressions on either side of the and operator are true; otherwise, the expression resolves to FALSE.
||, or || (also spelled out as or) means "one or the other or both." An expression resolves to FALSE if both logical expressions on either side of the or operator are false; otherwise, the expression resolves to TRUE.


Failure to observe the rules of precedence can cause unexpected errors, as in the following examples.

In the first example, the developer wrongly assumes that subtraction has precedence over multiplication:
n NUM(3) = 100 - 98 * 100;
EGL parses the right side of the equation as 100 - (98 * 100), giving a result that is too large for a NUM(3):
EGL0049E An overflow error occurred when assigning a value of -9,700 to n.
In the second example, the developer intends the following expression to be true if element is not a member of the array myArray :
if (!element in myArray)

Instead, the "not" operator takes precedence over the in operator, so EGL searches the array for a false value, which is not what the developer expected.

In both cases, using parentheses to force the intended precedence not only prevents these errors, but makes the code more readable:
n NUM(3) = (100 - 98) * 100;
if (!(element in myArray))


Table 1. Compatibility considerations for operators
Platform Issue
COBOL generation vs. Java™ generation The remainder operator (%) produces consistent results between COBOL and Java when both operands are integers. When the operands contain decimals, however, the two languages use different rounding algorithms and remainders can differ between the two.
JavaScript generation The three bitwise operators (& | Xor) are not supported; nor is the in operator.