A logical expression resolves to true or false and is used as the criteria in an if or while statement.
An elementary logical expression is composed of an operand, a comparison operator, and a second operator, as shown in this syntax diagram and the subsequent table:
First operand | Comparison Operator | Second operand |
---|---|---|
numeric expression | One of these:
=, != , <, >, <=, >= | numeric expression |
string expression | One of these:
=, != , <, >, <=, >= | string expression |
Value of type NUM or CHAR, as described for the second operand | One of these:
=, != , <, >, <=, >= | Value of type NUM or CHAR, which can be any of these:
|
searchValue | in | arrayName; for details, see in. |
item not in SQL record | One of these:
| One of these:
|
item in an SQL record | One of these:
| One of these:
The trunc test can resolve to true only when the database column is longer than the item. The value for the test is false after a value is moved to the item or after the item is set to null. |
textField (the name of a field in a text form) | One of these:
| One of these:
|
sysVar.eventKey | One of these:
| For details, see sysVar.eventKey. |
sysVar.systemType | One of these:
| For details, see sysVar.systemType.
You cannot use is or not to test a value returned by sysLib.getVAGSysType. |
record name | One of these:
| An I/O error value appropriate for the record organization. See I/O error values. |
The next table lists the comparison operators, each of which resolves to true or false.
Operator | Purpose |
---|---|
= | The equal operator indicates whether two operands have the same value. |
!= | The not equal operator indicates whether two operands have different values. |
< | The less than operator indicates whether the first of two operands is numerically less than the second. |
> | The greater than operator indicates whether the first of two operands is numerically greater than the second. |
<= | The less than or equal to operator indicates whether the first of two operands is numerically less than or equal to the second. |
>= | The greater than or equal to operator indicates whether the first of two operands is numerically greater than or equal to the second. |
in | The in operator indicates whether the first of two operands is a value in the second operand, which references an array. For details, seein. |
is | The is operator indicates whether the first of two operands is in the category of the second. For details, see the previous table. |
not | The not operator indicates whether the first of two operands is not in the category of the second. For details, see the previous table. |
The next table and the explanations that follow tell the compatibility rules when the operands are of the specified types.
Primitive type of first operand | Primitive type of second operand |
---|---|
BIN | BIN, DECIMAL, NUM, NUMC, PACF |
CHAR | CHAR, HEX, MBCHAR, NUM |
DBCHAR | DBCHAR |
DECIMAL | BIN, DECIMAL, NUM, NUMC, PACF |
HEX | CHAR, HEX |
MBCHAR | CHAR, MBCHAR |
NUM | BIN, CHAR, DECIMAL, NUM, NUMC, PACF, |
NUMC | BIN, DECIMAL, NUM, NUMC, PACF |
PACF | BIN, DECIMAL, NUM, NUMC, PACF |
UNICODE | UNICODE |
Details are as follows:
A CHAR-to-NUM comparison works as follows:
You can build a more complex expression by using either an and (&&) or or operator (||) to combine a pair of more elementary expressions. In addition, you can use the not operator (!), as described later.
If a logical expression is composed of elementary logical expressions that are combined by or operators, EGL evaluates the expression in accordance with the rules of precedence, but stops the evaluation if one of the elementary logical expressions resolves to true. Consider an example:
item01 = item02 || 3 in array03 || x = y
If item01 does not equal item02, evalution proceeds. If the value 3 is in array03, however, the overall expression is proven to be true, and the last elementary logical expression (x = y) is not evaluated.
Similarly, if elementary logical expressions are combined by and operators, EGL stops the evaluation if one of the elementary logical expressions resolves to false. In the following example, evaluation stops as soon as item01 is found to be unequal to item02:
item01 = item02 && 3 in array03 && x = y
You may use paired parentheses in a logical expression for any of these purposes:
In reviewing the examples that follow, assume that value1 contains "1", value2 contains "2", and so on:
/* = true */ value5 < value2 + value4 /* = false */ !(value1 is numeric) /* = true when the generated output runs on Windows 2000, Windows NT, or z/OS UNIX System Services */ sysVar.systemType is WIN || sysVar.systemType is USS /* = true */ (value6 < 5 || value2 + 3 >= value5) && value2 = 2
Related concepts
Java access functions
Modified data tag and modified property
Related tasks
Syntax diagram
Related reference
case
Exception handling
Expressions
I/O error values
if, else
in
Items
Numeric expressions
Operators and precedence
Primitive types
String expressions
sysVar.eventKey
sysLib.getVAGSysType
sysVar.systemType
while
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.