z/OS DFSMSdfp Storage Administration
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


IF statement

z/OS DFSMSdfp Storage Administration
SC23-6860-01

Use the IF statement for conditional statement execution. You must always follow an IF statement with a THEN clause. The THEN clause can be a single statement or a DO-END group of statements. You can optionally follow a THEN clause with an ELSE clause. If you specify the ELSE clause, you must follow it with either a single statement or a DO-END group of statements. If you want to specify the ELSE clause but do not want to follow it with an executable statement, follow it with an empty DO-END pair.

If the result of the IF statement comparison is true, the THEN clause is executed. If the result is false, the ELSE clause is executed. If you omit the ELSE, processing continues with the next sequential statement after the THEN clause.

IF relational expression THEN clause ELSE clause
  • relational expression can be a single comparison or it can be multiple comparisons joined by Boolean operators.
  • THEN is a mandatory keyword.
  • clause can contain a single statement, a DO-END group of statements, or a SELECT statement.
  • ELSE is an optional keyword.
  • An ELSE clause is mandatory if you specify the ELSE keyword.

For information on what constitutes a valid relational expression, refer to Comparison rules.

Figure 1 shows two examples of IF statements:
Figure 1. Examples of IF Statements
Example of a specified ELSE:          Example of a null ELSE:

IF &DSOWNER = 'BILL' THEN             IF &DSOWNER = 'BILL' THEN
  SET &STORCLAS = 'ONE'                     SET &STORCLAS = 'ONE'
ELSE                                  ELSE
  SET &STORCLAS = 'TWO'                     DO END
                                      SET &STORCLAS = 'TWO'

The statement on the left sets &STORCLAS equal to ONE or TWO, depending on the value of &DSOWNER

The statement on the right sets &STORCLAS equal to TWO, regardless of the value of &DSOWNER If &DSOWNER equals 'BILL', then &STORCLAS is set to 'ONE'. The ELSE clause is skipped, and execution falls to the next statement, which changes &STORCLAS to 'TWO'. If &DSOWNER does not equal 'BILL', execution falls to the ELSE, which results in no assignment to &STORCLAS Then execution proceeds to the next sequential statement, which sets &STORCLAS to 'TWO'.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014