A logical expression resolves to true or false and is used as a criterion in an if or while statement or (in some situations) in a case 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 |
---|---|---|
datetime expression | One of these: ==, != , <, >, <=, >= | datetime expression The first and second expressions must be of compatible types. In the case of datetime comparisons, the greater than sign (>) means later in time; and the less than (<) sign means earlier in time. |
numeric expression | One of these: ==, != , <, >, <=, >= | numeric expression |
string expression | One of these: ==, != , <, >, <=, >= | string expression |
string expression | like | likeCriterion, which is a character field or
literal against which string expression is compared, character position
by character position from left to right. Use of this feature is similar to
the use of keyword like in SQL queries. escChar is a one-character field or literal that resolves to an escape character. For further details, see like operator. |
string expression | matches | matchCriterion, which is a character field or
literal against which string expression is compared, character position
by character position from left to right. Use of this feature is similar to
the use of regular expressions in UNIX® or Perl. escChar is a one-character field or literal that resolves to an escape character. For further details, see matches operator. |
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. |
field not in SQL record | One of these:
|
One of these:
|
field 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 field. The value for the test is false after a value is moved to the field or after the field is set to null. |
textField (the name of a field in a text form) | One of these:
|
One of these:
|
ConverseVar.eventKey | One of these:
|
For details, see ConverseVar.eventKey. |
sysVar.systemType | One of these:
|
For details, see sysVar.systemType. You cannot use is or not to test a value returned by VGLib.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 is used in an expression that resolves to true or false.
Operator | Purpose |
---|---|
== | The equality 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, see in. |
is | The is operator indicates whether the first of two operands is in the category of the second. For details, see the previous table. |
like | The like operator indicates whether the characters in the first of two operands is matched by the second operand, as described in like operator. |
matches | The matches operator indicates whether the characters in the first of two operands is matched by the second operand, as described in matches operator |
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, FLOAT, MONEY, NUM, NUMC, PACF, SMALLFLOAT |
CHAR | CHAR, DATE, HEX, MBCHAR, NUM, TIME, TIMESTAMP |
DATE | CHAR, DATE, NUM, TIMESTAMP |
DBCHAR | DBCHAR |
DECIMAL | BIN, DECIMAL, FLOAT, MONEY, NUM, NUMC, PACF, SMALLFLOAT |
HEX | CHAR, HEX |
MBCHAR | CHAR, MBCHAR |
MONEY | BIN, DECIMAL, FLOAT, MONEY, NUM, NUMC, PACF, SMALLFLOAT |
NUM | BIN, CHAR, DATE, DECIMAL, FLOAT, MONEY, NUM, NUMC, PACF, SMALLFLOAT, TIME |
NUMC | BIN, DECIMAL, FLOAT, MONEY, NUM, NUMC, PACF, SMALLFLOAT |
PACF | BIN, DECIMAL, FLOAT, MONEY, NUM, NUMC, PACF, SMALLFLOAT |
TIME | CHAR, NUM, TIME, TIMESTAMP |
TIMESTAMP | CHAR, DATE, TIME, TIMESTAMP |
UNICODE | UNICODE |
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.
field01 == field02 || 3 in array03 || x == y
If field01 does not equal field02, 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 field01 is found to be unequal to field02:
field01 == field02 && 3 in array03 && x == y
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
Modified data tag and modified property
Related tasks
Syntax diagram for EGL statements and commands