Abbreviated combined relation conditions

When relation-conditions are written consecutively, any relation-condition after the first can be abbreviated by omission of the subject, or by omission of the subject and relational operator.

Format

Read syntax diagramSkip visual syntax diagramrelation-conditionANDORNOTrelational-operatorobject

In any consecutive sequence of relation-conditions, both forms of abbreviation can be specified. The abbreviated condition is evaluated as if:

  1. The last stated subject is the missing subject.
  2. The last stated relational operator is the missing relational operator.

The resulting combined condition must comply with the rules for element sequences in combined conditions, as shown in Combined conditions.

If NOT is immediately followed by GREATER THAN, >, LESS THAN, <, EQUAL TO, or =, then the NOT participates as part of the relational operator. NOT in any other position is considered a logical operator (and thus results in a negated relation condition).

Using parentheses

You can use parentheses in combined relation conditions to specify an intended order of evaluation. Using parentheses can also help improve the readability of conditional expressions.

The following rules govern the use of parentheses in abbreviated combined relation conditions:

  1. Parentheses can be used to change the order of evaluation of the logical operators AND and OR.
  2. The word NOT participates as part of the relational operator when it is immediately followed by GREATER THAN, >, LESS THAN, <, EQUAL TO, or =.
  3. NOT in any other position is considered a logical operator and thus results in a negated relation condition. If you use NOT as a logical operator, only the relation condition immediately following the NOT is negated; the negation is not propagated through the abbreviated combined relation condition along with the subject and relational operator.
  4. The logical NOT operator can appear within a parenthetical expression that immediately follows a relational operator.
  5. When a left parenthesis appears immediately after the relational operator, the relational operator is distributed to all objects enclosed in the parentheses. In the case of a "distributed" relational operator, the subject and relational operator remain current after the right parenthesis which ends the distribution. The following three restrictions apply to cases where the relational operator is distributed throughout the expression:
    1. A simple condition cannot appear within the scope of the distribution.
    2. Another relational operator cannot appear within the scope of the distribution.
    3. The logical operator NOT cannot appear immediately after the left parenthesis, which defines the scope of the distribution.
  6. Evaluation proceeds from the least to the most inclusive condition.
  7. 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. If the parentheses are unbalanced, the compiler inserts a parenthesis and issues an E-level message. However, if the compiler-inserted parenthesis results in the truncation of the expression, you will receive an S-level diagnostic message.
  8. The last stated subject is inserted in place of the missing subject.
  9. The last stated relational operator is inserted in place of the missing relational operator.
  10. Insertion of the omitted subject or relational operator ends when:
    1. Another simple condition is encountered.
    2. A condition-name is encountered.
    3. A right parenthesis is encountered that matches a left parenthesis that appears to the left of the subject.
  11. In any consecutive sequence of relation conditions, you can use both abbreviated relation conditions that contain parentheses and those that do not.
  12. Consecutive logical NOT operators cancel each other and result in an S-level message. Note, however, that an abbreviated combined relation condition can contain two consecutive NOT operators when the second NOT is part of a relational operator. For example, you can abbreviate the first condition as the second condition listed below.
    
    A = B and not A not = C
    A = B and not not = C
    

The following table summarizes the rules for forming an abbreviated combined relation condition.

Table 1. Abbreviated combined conditions: permissible element sequences
Combined condition element Left- most When not leftmost, can be immediately preceded by: Right- most When not rightmost, can be immediately followed by:
Subject Yes
NOT
(
No Relational operator
Object No
Relational operator
AND
OR
NOT
(
Yes
AND
OR
)
Relational operator No
Subject
AND
OR
NOT
No
Object
(
AND
OR
No
Object
)
No
Object
Relational operator
NOT
(
NOT Yes
AND
OR
(
No
Subject
Object
Relational operator
(
( Yes
Relational operator
AND
OR
NOT
(
No
Subject
Object
NOT
(
) No
Object
)
Yes
AND
OR
)

The following table shows examples of abbreviated combined relation conditions, with and without parentheses, and their unabbreviated equivalents.

Table 2. Abbreviated combined conditions: unabbreviated equivalents
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))))