2. This COND parameter can also be used to skip a step based on the return code from a previous step or steps in PROC.
3. You can use the COND parameter to run a job even though, any of the previous steps have Abended (Abend means Abnormal Termination).
4. With the COND parameter, you can also run a step only and only if any of the previous steps have Abended.
Let us understand COND in JCL with lots of examples-
The ‘COND’ parameter defines the conditional processing in JCL and this is an important parameter in JCL.
You can set the COND parameter at –
- JOB level – In JOB Statement(JOB card).
- STEP level – In EXEC statement.
In most cases, it is a good practice to code the COND parameter at STEP Level but based on your requirement, you can code this at JOB level or STEP level or at both the places.
Here, RC is Return code and OP is Operator and STEPNAME is the name of the step.
Also, please note that you can also give space in place of a comma between RC, OP, and STEPNAME.
For Example – COND=(RC,OP) is same as COND=(RC OP).
RC can take any value from 0 to 4095 but in most of the cases, ‘RC’ will take a number from 0 to 16 as below –
- 0 – Successful execution of a program – Normal execution
- 4 – Successful execution of a program with some warning
- 8 – Error
- 12 – Severe Error
- 16 – Fatal Error
‘OP’ can be any one of these –
- EQ – Equal to
- NE – Not Equal to
- LT – Less than
- LE – Less than or Equal to
- GT – Greater than
- GE – Greater than or Equal to
Let us take some examples-
|Type 1||COND=(0,EQ)||Is return code 0 equals the return code from the previous step? If this condition is true then bypass this step.|
|Type 2||COND=(4,EQ,STEP10)||Is return code 4 equals the return code from the previous step? if this condition is true then bypass this step.|
|Type 3||COND=EVEN||Run this steps even though, any of the previous step has Abended.|
|Type 4||COND=ONLY||Run this step only if any of the previous steps has abended.|
COND Parameter at JOB level
If you code a COND parameter at JOB level, then this condition will test against the return code of all the steps of the JCL.
Explanation of COND=(0 NE)
In this case, the COND parameter at the JOB level is –
COND=(0 NE) will test –
Is return code of 0 not equal to the return code of any of the steps in JCL? If this is true, then terminate this JCL. So, if any of the steps (i.e. STEP01, STEP02 or STEP03) has a return code of Non-Zero, then this condition will be true and the Job will be terminated.
COND Parameter at STEP Level
If you code a COND parameter at EXEC level, then this condition will test against the return code of the previous step.
Now, how do you make sure that the return code of this step should test against the return code of which the previous step?
Let us see the answer for this important question –
COND=(0 GE) will test –
Is return code of 0 Greater than or Equal to the return code of STEP01? If this is true, then STEP02 will be bypassed and will not run.
COND=(4 EQ) will test –
Is return code of 4 Equals the return code of STEP02? If this is true, then STEP03 will be bypassed and will not run.
COND=(0,LE,STEP01) will test –
Is return code of 0 Less than or Equal to the return code of STEP01? If this is true, then STEP04 will be bypassed and will not run.
Here, you have to note that the condition at STEP04 is tested against the return code of STEP01.
If you want to execute a particular step even if any of the previous steps have Abended, then you should use – COND=EVEN in that step.
COND=EVEN will test –
Here, STEP03 will run even if STEP01 or STEP02 has Abended. So, irrespective of whether STEP01 or STEP02 has Abended or not, STEP03 will run.
If you want to execute a particular step only and only if any of the previous steps have Abended, then you should use – COND=ONLY in that step.
Example of JCL COND=ONLY
COND=ONLY will test –
Here, STEP03 will run only if STEP01 or STEP02 has Abended. So, if STEP01 or STEP02 did not Abend then STEP03 will not run.
- There can be multiple COND Parameter in JCL but a maximum of 8 COND parameter is allowed.
- COND parameter can be used at JOB level or STEP level or at both the places.
IF condition in JCL
IF-ELSE-IF and IF is a better way to control the conditional processing of a JCL. In JCL IF condition is better than the COND parameter because of 2 reasons –
- And the IF condition in JCL is easy to code as compared to the COND parameter.
- Sometimes, JCL programmers with less experience find COND parameter little confusing and boring and it is easier to read and understand IF-ELSE-END-IF condition in JCL.
//IFSTMT1 IF STEP01.RC = 0 THEN //STEP02 EXEC PGM=IFCOND2 //STEP03 EXEC PGM=IFCOND3
This will check if the Return Code(RC) from STEP01 is 0, if yes then execute STEP02 and STEP03.
//IFSTMT2 IF STEP05.RC = 04 THEN //STEP06 EXEC PGM=IFCOND6 // ELSE //STEP07 EXEC PGM=IFCOND7 // ENDIF
This will check if the Return Code(RC) from STEP05 is 04, if yes then execute STEP06, else execute STEP07.