z/OS ISPF Dialog Developer's Guide and Reference
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


IF statement and boolean operators

z/OS ISPF Dialog Developer's Guide and Reference
SC19-3619-00

You can combine two or more conditional expressions on the IF statement. ISPF evaluates the conditional expressions on the IF statement from left to right, starting with the first expression and proceeding to the next and subsequent expressions on the IF statement until processing is complete.

The use of the AND Boolean operator takes precedence over the OR Boolean operator as shown in these examples.

The number of conditional expressions you can specify on the IF statement is limited to 255.

The accepted symbols for the Boolean operators are:
  • & or AND (AND Boolean operator)

    AND processing returns a TRUE result for the IF statement only if all the conditional expressions evaluate as TRUE.

  • | or OR (OR Boolean operator)

    OR processing returns a TRUE result for the IF statement if any of the conditional expressions evaluate as TRUE. Also, for an IF statement to be evaluated as FALSE, all conditional expressions must be evaluated as FALSE.

    The Boolean operators must be separated by a preceding and following blank or blanks.

Examples of Boolean operators in the IF statement

  • Example 1: Comparison of two expressions using different Boolean operators in two separate IF statements.
    IF (VER (&vara,NB,ALPHA) & VER (&varb,NB,ALPHA))
    ⋮
    ELSE
      IF (&varc = 123 OR VER (&vard,NB,NUM))
    ⋮

    The first IF statement will be successful only if both VER expressions are satisfied, while the IF statement under the ELSE will be successful if either of the expressions on the IF statement are satisfied.

  • Example 2: Comparison of three expressions using the AND Boolean operator in the same IF statement, with additional OR Boolean operators.
    IF (VER (&vara,NB,ALPHA) & VER (&varb,NB,ALPHA) &
        &varc = abc,xyz | &vard = 123 | &vard = 456)
    ⋮
    ELSE
      .msg = nld123

    The IF statement will be successful if the comparisons of the first three expressions evaluate to TRUE, or if expressions four or five evaluate to TRUE.

  • Example 3: Comparison of two pairs of expressions using the AND Boolean operator combined on the same IF statement by the OR Boolean operator.
    IF (VER (&vara,NB,ALPHA) AND &varb = abc OR
        VER (&vara,NB,ALPHA) AND &varb = xyz)
    ⋮
    ELSE
      .msg = nld124
      .attr (vara) = 'color(yellow)'
      .attr (varb) = 'color(yellow)'

    Either of the pairs of expressions must evaluate to TRUE to achieve a successful IF statement.

  • Example 4: Comparison of three expressions showing that the AND operator has precedence.
    IF (Expression-1 OR Expression-2 AND Expression-3)
    ⋮
    ELSE
      .msg = nld125

Because the IF statement AND Boolean operator has precedence over the IF statement OR Boolean operator, specifying an IF statement similar to the one shown might not give you the results you expected.

If you expected the previous statement to be evaluated like this:
  IF ( (expression1 OR expression2) AND expression3)
You would need to write either two separate IF statements:
IF (Expression-1 OR Expression-2)
  IF (Expression-3)
⋮
  Else
    .msg = nld126
Or two separate comparison pairs:
IF (Expression-1 AND Expression-3 OR
          Expression-2 AND Expression-3)
⋮
Else
  .msg = nld127

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014