Everyone is so familiar with controlling execution of JCL job steps. Two ways we can do it. One is by COND and the other one is by IF/THEN/ELSE/ENDIF.
How to Control Steps Using IF/ELSE/THEN/ENDIF
We need to learn many points here. The following are typical questions you may face in interviews.
//RCTEST IF (STEP1.RC = 10) THEN //STEP3 EXEC //IFNOT ELSE // ENDIF //NEXTSTEP EXEC
Here,STEP1 is not executed/abnormally terminated, then, control will not go to THEN/ELSE. All the remaining steps will be flushed – in the same construct.
//RCTEST IF (STEP1.PROCSTEP2.RC = 10) THEN //STEP3 EXEC //IFNOT ELSE // ENDIF //NEXTSTEP EXEC
Here also,STEP1.PROCSTEP2 is not executed/abnormally terminated, then, control will not go to THEN/ELSE. All the remaining steps will be flushed – in the same construct.
Job level evaluation
If you do not code a stepname, the IF/THEN/ELSE/ENDIF statement construct evaluates the return code, abend condition, or run condition of every previous step in the job. If the condition (return code, abend condition, or run condition) is satisfied based on the steps in the job that have executed thus far, the system executes the THEN clause.
Step level evaluation
To test a single step, code the stepname of the step you want to test. To test a procedure step, code the stepname.procstepname of the procedure step you want to test. If the step or procedure step that you are evaluating did not execute, was cancelled or ended abnormally, the result of the evaluation is false.
Usually, if any step abends, the following steps automatically will be flushed. But with IF/THEN/ELSE/ENDIF – we can continue execution.
- //RCTEST IF (ABEND) THEN
- //RCTEST IF (ABEND=TRUE) THEN
****What we should/should not in THEN/ELSE:
Do not place :
- JOB statement
- JCLLIB statement
- JOBLIB statement
- SYSCHK (job level) statement
- XMIT JCL statement
The system processes the following statements regardless of the logic of the IF/THEN/ELSE/ENDIF statement construct. They can be placed in a THEN or ELSE clause, but they are not executed conditionally.
- PROC and PEND statements
- JES2 and JES3 statements and commands
- JCL command statements
- Comment (//*) statements
- INCLUDE statements
- Delimiter (/*) statements
- Null statements
- SET statements