Conditional Statements


Conditional statements are used to control the execution flow within a job based on certain conditions. They allow us to specify when a particular job step should be executed or skipped. Conditional statements are typically used to add flexibility and automation to our batch-processing jobs.

There are three primary types of conditional statements in JCL -

IF Statement The "IF" statement is used to execute a step conditionally based on the condition coded. It defines a condition with the return code or condition code of the previous steps. If the condition is true, then the step that follows the IF statement gets executed, and if the condition is false, the step execution gets skipped.
Syntax -
//[stepname] IF  [(relational-expression)] THEN [comments]
    .
    .    Set of statements for condition true
    .
//[stepname] [ELSE   [comments]]
    .
    .    Set of statements for condition false
    .
//[stepname] ENDIF   [comments]
  • Stepname - Stepname is used to identify the step uniquely in the JCL. Stepname is optional.
  • Operation (IF..THEN, ELSE, ENDIF) - Operation field consists of IF, ELSE, or ENDIF keyword.
  • relational-expression - A relational expression followed by IF condition specifies the condition that the system evaluates.
  • Comment - Comment used to make a note of the current statement.
Example - Executing STEP02 when STEP01 abended or RC > 8.
//Jobcard
//STEP01   DD PGM=PROG1
//IFSTEP2  IF ( ABEND | STEP01.RC > 8 ) THEN
//STEP02   EXEC PGM=PROG2
//IFSTEP2E ENDIF
//STEP03   EXEC PGM=PROG3
COND Parameter The COND parameter is used to specify a condition under which a particular job step should be executed or skipped. It allows us to control the flow of execution within a job based on the result code (return code) of a previous job step or based on other conditions.
Syntax -
COND=EVEN
COND=ONLY
COND=(return-code|RC,operator|RO)
COND=(return-code|RC,operator|RO[,step-name1][.proc-step-name1])
  • COND=ONLY - can be coded only at step level and is used to execute the current step when the previous step execution is unsuccessful.
  • COND=EVEN - can be coded only at step level and is used to execute the current step when the previous step execution is successful or unsuccessful.
  • COND=(return-code|RC,operator|RO) - can be coded at job level and step level. It is used to execute the current step based on the previous step return code (RC). If COND=(RC,RO) is true, the step with COND parameter execution will be bypassed.
  • COND=(return-code|RC,operator|RO[,step-name1][.proc-step-name1]) - It is used to execute the current step based on the step-name1 return code (RC).
Example - Executing STEP3 based on the return code of STEP1.
//MTHEXMP1 JOB (META007),'PAWAN Y',NOTIFY=&SYSUID
//STEP1 EXEC PGM=P1 
//STEP2 EXEC PGM=P2 
//STEP3 EXEC PGM=P3,COND=(12,EQ,STEP1) 
//STEP4 EXEC PGM=P4
In this example, STEP3 will be executed when STEP1 return code is not equal to 12.
RD Parameter RD stands for restart definition. RD parameter used to - allow JES to perform an automatic job restart after the job failure, allow the operator to perform an automatic job or a checkpoint restart if a job fails.
Syntax -
RD={R }
{RNC}
{NR }
{NC }
  • R - Specifies restart, checkpoints.
  • RNC - Specifies restart, no checkpoints.
  • NR - Specifies no restart, checkpoints.
  • NC - Specifies no restart, no checkpoints.
Example - Automatic restart for job level and No restart at step level.
//MTHEXMP1 JOB (META007),'PAWAN Y',RD=R 
//*
//STEP01 EXEC ...
//STEP02 EXEC ...
//STEP03 EXEC ...
//STEP04 EXEC PGM=PROG04,RD.STEP02=NR
//STEP05 EXEC PGM=PROG05
RD=R specifies that the operator can perform automatic restart if the job fails. The RD parameter at the STEP04 is ignored.