IF Statement Example


Scenario1 - Executing STEP02 when STEP01 abended or RC > 8.

Code -

----+----1----+----2----+----3----+----4----+----5----+
//Jobcard
//STEP01   DD PGM=PROG1
//IFSTEP2  IF ( ABEND | STEP01.RC > 8 ) THEN
//STEP02   EXEC PGM=PROG2
//IFSTEP2E ENDIF
//STEP03   EXEC PGM=PROG3

Scenario2 - Bypassing STEP02 when STEP01 successfully completed (not abended or RC < 8).

Code -

----+----1----+----2----+----3----+----4----+----5----+
//Jobcard
//STEP01   DD PGM=PROG1
//IFSTEP2  IF ¬ABEND THEN
//STEP02   EXEC PGM=PROG2
//IFSTEP2E ENDIF
//STEP03   EXEC PGM=PROG3

Scenario3 - Coding IF..ELSE condition with stepname.

Code -

----+----1----+----2----+----3----+----4----+----5----+
//Jobcard
//STEP01   DD PGM=PROG1
//IFSTEP2  IF ¬ABEND THEN
//STEP02   EXEC PGM=PROG2
//IFELSE2  ELSE
//STEP03   EXEC PGM=PROG3
//IFSTEP2E ENDIF
//STEP04   EXEC PGM=PROG4

Scenario4 - Coding IF..ELSE condition without stepname.

Code -

----+----1----+----2----+----3----+----4----+----5----+
//Jobcard
//STEP01  EXEC PGM=MTHPROG
//IFTEST  IF STEP01.RC=0 | ¬STEP01.RUN THEN
//STEP02  EXEC PGM=...
//STEP03  EXEC PGM=...
//STEP04  EXEC PGM=...
//        ELSE
//STEP05  EXEC PGM=...
//STEP06  EXEC PGM=...
//STEP07  EXEC PGM=...
//        ENDIF

Explaining Example -

  1. IFTEST will be checked before executing STEP03.
  2. STEP01.RC=0 tests false because STEP01 did not execute and cannot be correctly evaluated.
  3. ¬STEP01.RUN tests true; therefore, STEP03 and STEP04 will execute and STEP05, STEP06, and STEP07 will not execute.