Logical expressions

Logical expressions determine the path your program logic takes through conditional and looping statements like if, while, for, and case.

The following table summarizes the operators and operands for elementary logical expressions. Elementary expressions consist of an operand, a comparison operator, and a second operand.

Table 1. Elementary logical expressions
First operand Comparison Operator Second operand
date/time expression ==, != , <, >, <=, >= date/time expression

The first and second expressions must be of compatible types. See Assignment compatibility in EGL.

For date/time comparisons, the greater than sign (>) means later in time; and the less than (<) sign means earlier in time.

numeric expression ==, != , <, >, <=, >= numeric expression
string expression ==, != , <, >, <=, >= string expression

See Assignment compatibility in EGL.

string expression like regular expression

A character field or literal that string expression is compared to, character position by character position from left to right. regular expression can contain wildcard and escape characters.

string expression matches regular expression ,

A character field or literal that string expression is compared to, character position by character position from left to right. regular expression can contain wildcard and escape characters. Regular expression rules differ between the like and the matches operators.

NUM or CHAR value ==, != , <, >, <=, >= NUM or CHAR value
searchValue in arrayName

For more information, see in operator.

variable in basic record
  • is
  • not
Either:
  • blanks. Keyword for testing whether the value of a character variable is or is not blanks only.
  • numeric. Keyword for testing whether the value of a character variable (except DBCHAR type) is or is not numeric.
sysVar.systemType
  • is
  • not
For more information, see systemType.
record name
  • is
  • not
An I/O error value appropriate for the record organization. See I/O error values.

Complex logical expressions

You can use "and" (&&) and "or" operators (||) to build complex expressions by combining pairs of more elementary expressions. In addition, you can use the "not" operator (!) to reverse the value of an expression (changing TRUE to FALSE and FALSE to TRUE).

If a logical expression contains elementary logical expressions that are the operands of one or more "or" operators, EGL evaluates the expression in accordance with the rules of precedence. The evaluation stops if one of the elementary logical expressions resolves to TRUE. Consider the following example:
  var01 == var02 || 3 in array03 || x == y

If var01 does not equal var02, evaluation proceeds. If the value 3 is in array03, the overall expression is TRUE, and EGL does not need to evaluate the last elementary logical expression (x == y).

Similarly, if elementary logical expressions are combined by "and" operators, EGL stops the evaluation as soon as one of the elementary logical expressions resolves to FALSE. In the following example, evaluation stops as soon as var01 is found to be unequal to var02:

  var01 == var02 && 3 in array03 && x == y
You can use paired parentheses in a logical expression for any of these purposes:
  • To change the order of evaluation.
  • To clarify your meaning.
  • To make possible the use of the "not" operator (!), which resolves to a Boolean value (TRUE or FALSE) opposite to the value of a logical expression, contained in parentheses, that immediately follows.

Compatibility

Table 2. Compatibility considerations for logical expressions
Platform Issue
COBOL generation COBOL does not offer a way to compare MBCHAR or DBCHAR to UNICODE or STRING.
JavaScript generation The following types are not supported: ArrayDictionary, BIN (with decimal places), BLOB, CHAR, CLOB, DBCHAR, HEX, INTERVAL, MBCHAR, NUMC, STRING (with a size limit), PACF, UNICODE, and structured Record parts.
VisualAge® Generator compatibility mode You cannot use is or not to test a value returned by vgLib.getVAGSysType().

Feedback