COND in JCL

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 –

  1. JOB level – In JOB Statement(JOB card).
  2. 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.

Syntax:

  1. COND=(RC,OP)
  2. COND=(RC,OP,STEPNAME)
  3. COND=EVEN
  4. COND=ONLY

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-

TypesCondition exampleExplanation
Type 1COND=(0,EQ)Is return code 0 equals the return code from the previous step? If this condition is true then bypass this step.
Type 2COND=(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 3COND=EVENRun this steps even though, any of the previous step  has Abended.
Type 4COND=ONLYRun 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.

Example

//MATEKSD JOB MSGLEVEL=(1,1),NOTIFY=&SYSUID,
//*           COND=(0,NE)
//* EXAMPLE TO SHOW COND AT JOB LEVEL IN JCL
//*
//STEP01   EXEC PGM=CONDPGM1
//STEP02   EXEC PGM=CONDPGM2,COND=(0,EQ)
//STEP03   EXEC PGM=CONDPGM3,COND=(4,EQ)

Explanation of COND=(0 NE)

In this case, the COND parameter at the JOB level is –
COND=(0,NE)

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

Example

//MATEKSD JOB MSGLEVEL=(1,1),NOTIFY=&SYSUID
//*
//* EXAMPLE TO SHOW COND AT EXEC LEVEL IN JCL
//*
//STEP01   EXEC PGM=CONDPGM1
//STEP02   EXEC PGM=CONDPGM2,COND=(0,GE)
//STEP03   EXEC PGM=CONDPGM3,COND=(4,EQ)
//STEP04 EXEC PGM=CONDPGM4,COND=(0,LE,STEP01)

Explanation

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.

JCL COND=EVEN

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.

Example

//MATEKSD JOB MSGLEVEL=(1,1),NOTIFY=&SYSUID
//*
//* EXAMPLE TO SHOW COND=EVEN IN JCL
//*
//STEP01   EXEC PGM=CONDPGM1
//STEP02   EXEC PGM=CONDPGM2
//STEP03 EXEC PGM=CONDPGM4,COND=EVEN

Explanation

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.

JCL COND=ONLY

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

//MATEKSD JOB MSGLEVEL=(1,1),NOTIFY=&SYSUID
//*
//* EXAMPLE TO SHOW COND=ONLY IN JCL
//*
//STEP001  EXEC PGM=ONLY3PGM
//STEP002  EXEC PGM=ONLY2PGM
//STEP003 EXEC PGM=ONLY1PGM,COND=ONLY

Explanation

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.

Note:

  • 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.

Example

//MATEKSD JOB MSGLEVEL=(1,1),NOTIFY=&SYSUID
//*
//* EXAMPLE TO SHOW IF CONDITION IN JCL
//*
//STEP01   EXEC PGM=IFCOND1
//IFSTMT1 IF STEP01.RC = 0  THEN
//STEP02   EXEC PGM=IFCOND2
//STEP03   EXEC PGM=IFCOND3
//        ENDIF
//STEP04   EXEC PGM=IFCOND4
//STEP05   EXEC PGM=IFCOND5
//IFSTMT2 IF STEP05.RC = 04 THEN
//STEP06   EXEC PGM=IFCOND6
//        ELSE
//STEP07   EXEC PGM=IFCOND7
//        ENDIF
//STEP08   EXEC PGM=IFCOND8
//*

Explanation

//IFSTMT1 IF STEP01.RC = 0  THEN
//STEP02   EXEC PGM=IFCOND2
//STEP03   EXEC PGM=IFCOND3
// ENDIF

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.

Tutorials for all brains!