A complex condition is formed by combining simple conditions, combined conditions, and/or complex conditions with logical operators, or negating these conditions with logical negation.
Each logical operator must be preceded and followed by a space. The following chart shows the logical operators and their meanings.
Table 24. Logical Operators and Their Meanings
| Logical Operator | Name | Meaning |
|---|---|---|
| AND | Logical conjunction | The truth value is true when both conditions are true. |
| OR | Logical inclusive OR | The truth value is true when either or both conditions are true. |
| NOT | Logical negation | Reversal of truth value (the truth value is true if the condition is false). |
Unless modified by parentheses, the following precedence rules (from highest to lowest) apply:
The truth value of a complex condition (whether parenthesized or not) is the truth value that results from the interaction of all the stated logical operators on either of the following:
A complex condition can be either of the following:
A simple condition is negated through the use of the logical operator NOT. The negated simple condition gives the opposite truth value of the simple condition.
Negated Simple Condition - Format >>-NOT--simple-condition---------------------------------------><
Two or more conditions can be logically connected to form a combined condition.
Combined Conditions - Format
.----------------------.
V |
>>-condition-1----+-AND-+--condition-2-+-----------------------><
'-OR--'
The condition to be combined may be any of the following:
Table 25. Combined Conditions--Permissible Element Sequences
| Combined condition element | Leftmost | When not leftmost, can be immediately preceded by: | Rightmost | When not rightmost, can be immediately followed by: |
|---|---|---|---|---|
| simple-condition | Yes |
OR NOT AND ( | Yes |
OR AND ) |
|
OR AND | No |
simple-condition ) | No |
simple-condition NOT ( |
| NOT | Yes |
OR AND ( | No |
simple-condition ( |
| ( | Yes |
OR NOT AND ( | No |
simple-condition NOT ( |
| ) | No |
simple-condition ) | Yes |
OR AND ) |
Parentheses are never needed when either ANDs or ORs (but not both) are used exclusively in one combined condition. However, parentheses may be needed to modify the implicit precedence rules to maintain the correct logical relation of operators and operands.
There must be a one-to-one correspondence between left and right parentheses, with each left parenthesis to the left of its corresponding right parenthesis.
The following table illustrates the relationships between logical
operators and conditions C1 and C2.
Table 26. Logical Operators and Evaluation Results of Combined Conditions
| Value for C1 | Value for C2 | C1 AND C2 | C1 OR C2 | NOT (C1 AND C2) | NOT C1 AND C2 | NOT (C1 OR C2) | NOT C1 OR C2 |
|---|---|---|---|---|---|---|---|
| True | True | True | True | False | False | False | True |
| False | True | False | True | True | True | False | True |
| True | False | False | True | True | False | False | False |
| False | False | False | False | True | False | True | True |
Related Information:
If parentheses are used, logical evaluation of combined conditions proceeds in the following order:
If parentheses are not used (or are not at the same level of inclusiveness), the combined condition is evaluated in the following order:
The component conditions of a combined condition are evaluated from left to right. If the truth value of one condition is not affected by the evaluation of further elements of the combined condition, these elements are not evaluated. However, the truth value of the condition will always be the same (as if the condition had been evaluated in full), as described earlier in this paragraph.
Values are established for arithmetic expressions and functions if and when the conditions containing them are evaluated. Similarly, negated conditions are evaluated if and when it is necessary to evaluate the complex condition that they represent.
For example:
NOT A IS GREATER THAN B OR A + B IS EQUAL
TO C AND D IS POSITIVE
is evaluated as if parenthesized as follows:
(NOT (A IS GREATER THAN B)) OR (((A+B) IS EQUAL
TO C) AND (D IS POSITIVE))
The order of evaluation in this example is as follows:
When relation-conditions are written consecutively without intervening parentheses,
any relation-condition after the first can be abbreviated in one of two ways:
Abbreviated Combined Relation Conditions - Format
>>-relation-condition------------------------------------------->
.-------------------------------------------------------------.
V |
>----+-AND-+-+----+-+----------+-+----------------------+-object-+-><
'-OR--' '-IS-' | (1) | +-GREATER-+------+-----+
'-NOT------' | '-THAN-' |
+->--------------------+
+-LESS--+------+-------+
| '-THAN-' |
+-<--------------------+
+-EQUAL--+----+--------+
| '-TO-' |
+-=--------------------+
+-| greater or equal |-+
+->=-------------------+
+-| less or equal |----+
'-<=-------------------'
greater or equal:
|--GREATER--+------+--OR EQUAL--+----+--------------------------|
'-THAN-' '-TO-'
less or equal:
|--LESS--+------+--OR EQUAL--+----+-----------------------------|
'-THAN-' '-TO-'
Notes:
An object is any data item or expression that can be compared to the subject of the preceding relation condition.
In any consecutive sequence of relation-conditions, both forms of abbreviation can be specified. The abbreviated condition is evaluated as if:
The resulting combined condition must comply with the rules for element sequence in combined conditions, as shown in Table 27.
The word NOT is considered part of the relational operator in the forms NOT GREATER THAN, NOT >, NOT LESS THAN, NOT <, NOT EQUAL TO, and NOT =.
NOT in any other position is considered a logical operator (and thus results in a negated relation-condition).
The following examples illustrate abbreviated combined relation conditions,
with and without parentheses, and their unabbreviated equivalents.
Table 27. Abbreviated Combined Relation Conditions
| Abbreviated Combined Relation Condition | Equivalent |
|---|---|
|
A = B AND NOT < C OR D | ((A = B) AND (A NOT < C)) OR (A NOT < D) |
| A NOT > B OR C | (A NOT > B) OR (A NOT > C) |
| NOT A = B OR C | (NOT (A = B)) OR (A = C) |
| NOT (A = B OR < C) | NOT ((A = B) OR (A < C)) |
| NOT (A NOT = B AND C AND NOT D) | NOT ((((A NOT = B) AND (A NOT = C)) AND (NOT (A NOT = D)))) |
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.