TSO-ISPF JCL COBOL VSAM DB2 CICS IMS-DB Tools Articles Forum Quiz Interview Q&A

JCL - Conditional Processing


Before we start, We should know- What is COND in JCL?

  1. COND parameter is JCL can be used to skip a step based on the return code from the previous step or steps of the JCL.

  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.

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 –JOB Statement(JOB card).

  2. STEP level – 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:

COND[.procstepname]=(rc,logical-operator)
or
COND[.procstepname]=(rc,logical-operator[,stepname][.procstepname])
or
COND=EVEN
or
COND=ONLY

Description of parameters in syntax:

  • rc : This is the return code

  • logical-operator : This can be GT (Greater Than), GE (Greater than or Equal to), EQ (Equal to), LT (Lesser Than), LE (Lesser than or Equal to) or NE (Not Equal to).

  • stepname : This is the job step whose return code is used in the test.
Last two conditions (a) COND=EVEN and (b) COND=ONLY, have been explained below in this chapter.

As discussed earlier, COND can be coded either inside JOB statement or EXEC statement, and in both the cases, it behaves differently as explained below:

Let us take some examples on each type-

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.

Example 1: 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.

//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:

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.

Example 2: COND Parameter at STEP level.

When COND is coded in EXEC statement of a job step and found to be true, only that job step is bypassed, and execution is continued from next job step.

//CNDSAMP JOB CLASS=6,NOTIFY=&SYSUID
//*
//STP01 EXEC PGM=SORT
//* Assuming STP01 ends with RC0.

//STP02 EXEC PGM=MYCOBB,COND=(0,EQ,STP01)
//* In STP02, condition evaluates to TRUE and step bypassed.

//STP03 EXEC PGM=IEBGENER,COND=((10,LT,STP01),(10,GT,STP02))
//* In STP03, first condition fails and hence STP03 executes.
//* Since STP02 is bypassed, the condition (10,GT,STP02) in
//* STP03 is not tested.

Example 3: 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.

//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 – STEP03 will run even if STEP01 or STEP02 has Abended. So, irrespective of whether STEP01 or STEP02 has Abended or not, STEP03 will run.


Example 4: 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:

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


Tips:
  • 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 you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!

Are you looking for Job Change? Job Portal