Sie sind auf Seite 1von 4

How to use IF-ELSE-ENDIF in JCL Statements

Sometimes in a JCL the requirements are such that the processing of subsequent
steps depend on whether the previous step is successfully executed or not. For example if
a step of JCL Abends, we do not want to execute the rest of the steps. There are three
ways to code JCL to execute job steps conditionally.
COND parameter on the jobs JOB statement - in this case, job is terminated if
the specified condition occur
COND parameter on EXEC statement - in this case, the job step is bypassed if
the specified condition occur
Using IF-ELSE-ENDIF statements to control job step execution
IF-ELSE-ENDIF statements are introduced in the Version 4 of MVS\ESA to replace the
confusing COND parameter for conditional testing. These statements allow coding in
same way as in COBOL or any other high level programming language
RETURN CODE (RC)
When a program completes executes, it passes a value called RETURN CODE
back to MVS. Return codes are usually generated by a system utility program, such as
compiler but user-written program can also generate return code. In either case, return
codes usually have these values
RC=0
RC=4
RC=8
RC=12
RC=16
Return codes are the most common values used to determine whether next step should be
executed or not
SYNTAX
Following is the syntax for coding IF-ELSE-ENDIF statements in a JCL
//[name] IF (expression) THEN
//
// steps to be executed when the IF condition is true
//
//[name] ELSE
//
// steps to be executed when the IF condition is false
//
//[name] ENDIF

If the [name] parameter is omitted then column 3 should be left blank. Operation
field (IF,ELSE, OR ENDIF) can be started anywhere after column 3. The IF and ENDIF
statements are always required to set up conditional processing, but ELSE statement can
be omitted if not needed.
The <expression> in the IF statement can be a relational expression or can contain
specific values to be tested. A relational expression contains operators and keywords.
Any of the below operators can be used either their symbol or letter equivalents
Operator
And
Or
Logical Not
Greater than
Less than
Not greater than
Not less than
Equal to
Not equal to
Greater than or equal to
Less than or equal to

Symbol
&
|

>
<
>
<
=
=
>=
<=

Letter Equivalent
AND
OR
NOT
GT
LT
NG
NL
EQ
NE
GE
LE

Keywords for the expression can be


RC
stepname.RC
ABEND
stepname.ABEND
ABEND
stepname. ABEND
stepname.RUN
stepname. RUN
ABENDCC=Sxxx
ABENDCC=Uxxx

The highest return code issued by any job step previously executed
The return code issued by the specified job step
True if an abend has occurred
True if the specified job step has abended
True if an abend has not occurred
True if the specified job step has not abended
True if the specified job step started execution
True if the specified job step did not started execution
True if most recent system abend code equals the specified abend
code
True if most recent user abend code equals the specified abend
code

Using IF-ELSE-ENDIF statements in a job stream


//STEP1
//INFILE

EXEC PGM= EXAMPLE1


DD
DSNAME=N020202.EX1.INPUT

//OUTFILE DD DSNAME=N020202.EX1.OUTPUT
//SYSOUT DD SYSOUT=*
// IF STEP1.RC > 4 THEN
//STEP2
EXEC PGM= EXAMPLE2
//INFILE
DD
DSNAME=N020202.EX2.INPUT
//OUTFILE DD DSNAME=N020202.EX2.OUTPUT
//SYSOUT DD SYSOUT=*
// ELSE
//STEP3
EXEC PGM= EXAMPLE3
//INFILE
DD
DSNAME=N020202.EX1.OUTPUT
//OUTFILE DD DSNAME=N020202.EX3.OUTPUT
//SYSOUT DD SYSOUT=*
// ENDIF
If the STEP1 is executed successfully then STEP3 will be executed which uses
the output file of STEP1 but if the STEP1 ends abnormally the STEP2 will be executed.
How to use the operators and keywords
The following examples describes how to use the above listed operators and keywords

IF RC > 0 THEN
This condition evaluates to true if any previous job step has issued a return code
greater than 0

IF STEP1.RC = 8 THEN
This condition evaluates to true if the return code for the job step STEP1 is 8

IF STEP1.RC = 0 AND STEP2.RC < 8 THEN


This condition evaluates to true if the return code of STEP1 is 0 and the return
code of STEP2 is less than 8

IF ABEND
This condition evaluates to true if there is abend in any of the previous steps

IF STEP1.ABEND
This condition evaluates to true if STEP1 ends abnormally

IF ABEND
This condition evaluates to true if there is no abend in any of the previous steps

IF STEP1. ABEND
This condition evaluates to true if STEP1 ends normally

IF STEP1.CPYINPUT.RUN
This condition evaluates to true if procedure step named CPYINPUT in STEP1
started execution

The usage of IF-ELSE-ENDIF is very easy almost like writing a COBOL code compared
to using COND parameter in the JCL which is very confusing. With IF-ELSE-ENDIF, we
can make our JCL simple, easy to read and still put all types of conditions as we could
with COND parameter.

Das könnte Ihnen auch gefallen