Boolean expressions yield a value of either true or false. They are formed by combining data items, arithmetic expressions, and strings using relational and logical operators.
The following diagrams illustrate the syntax of a Boolean expression:
<Boolean expression>
──┬───────┬─<Boolean primary>──────────────────────────────────────────► ├─ NOT ─┤ └─ ^ ─┘ ►─┬───────────────────────────────────────────┬────────────────────────┤ │ ┌◄──────────────────────────────────────┐ │ └─┴─┬─ AND ─┬─┬───────┬─<Boolean primary>─┴─┘ └─ OR ──┘ ├─ NOT ─┤ └─ ^ ─┘
<Boolean primary>
──┬─ TRUE ─────────────────────────────────────────┬───────────────────┤ ├─ FALSE ────────────────────────────────────────┤ ├─<arithmetic compare>───────────────────────────┤ ├─<string compare>───────────────────────────────┤ ├─ ( <Boolean expression> ) ─────────────────────┤ ├─<Boolean item name>─┬─┬────────────────────────┤ └─<field bit name>────┘ └─ ( <subscript list> ) ─┘
<subscript list>
┌◄──────── , ────────┐ ──┴─<unsigned integer>─┴───────────────────────────────────────────────┤
<arithmetic compare>
──<arithmetic expression>─┬─ LSS ─┬─<arithmetic expression>────────────┤ ├─ < ─┤ ├─ LEQ ─┤ ├─ <= ─┤ ├─ EQL ─┤ ├─ = ─┤ ├─ NEQ ─┤ ├─ ^= ─┤ ├─ GEQ ─┤ ├─ >= ─┤ ├─ GTR ─┤ └─ > ─┘
<string compare>
──<alpha item name>─┬─ LSS ─┬─┬─<alpha item name>─┬────────────────────┤ ├─ < ─┤ └─<string>──────────┘ ├─ LEQ ─┤ ├─ <= ─┤ ├─ EQL ─┤ ├─ = ─┤ ├─ NEQ ─┤ ├─ ^= ─┤ ├─ GEQ ─┤ ├─ >= ─┤ ├─ GTR ─┤ └─ > ─┘
Examples
The following examples illustrate valid Boolean expressions:
AGE GEQ 21 DEPT NEQ "PAYROLL" REAL-ITEM > 0 AND NOT BOOLEAN-ITEM OR NUMBER-ITEM * REAL-ITEM LEQ 1500
Precedence for Boolean Expressions
The sequence in which operations are performed is determined by the precedence of the operators involved. The order of precedence is as follows:
-
Arithmetic expression
-
Arithmetic compare, string compare
-
NOT
-
AND
-
OR
Restrictions for Boolean Expressions
When operators have the same precedence, the operations are performed in order from left to right. Parentheses can be used to override the usual order of evaluation.
Occurring data items must be fully subscripted. Subscripts must be unsigned integer constants.
For variable-format data sets, expressions in the fixed part can refer only to items in the fixed part. Expressions in the variable part can refer to items in either the fixed part or in the same variable part, but they cannot refer to items in other variable parts.
Virtual items must not be referenced in expressions.
When comparing alpha items, the comparison is based on the number of characters contained in the alpha item or string having the shorter length.
Example
In the following data set declaration, the Boolean expression A EQL B is true if the four leftmost characters of A and B are the same:
D DATA SET ( A ALPHA(6); B ALPHA(4); ) VERIFY A EQL B;