7/30/2019 JCL BASICO UNIDAD 6
1/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved.
7/30/2019 JCL BASICO UNIDAD 6
2/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 2 of 55
UNIT Conditional Processing
IF/THEN/ELSE/ENDIF Construct
Nesting Conditional Constructs
Topics:
7/30/2019 JCL BASICO UNIDAD 6
3/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 3 of 55
Unit Introduction
Steps in a job can be conditionally executed by using the IF/THEN/ELSE/ENDIF statement construct.
The IF/THEN/ELSE/ENDIF statement construct allows the execution of job steps based on return codes,
abend conditions, system completion codes from a previous job or procedure step.
This construct provides greater functionality than the COND statement and is easier to use, read and
understand.
To keep the examples in this unit simple,
the DD statements are not shown unless
they are referenced directly.
Introduction
Unit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
4/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 4 of 55
At the end of this unit, you will be able to:
Identify the various types of job conditions that anIF/THEN/ELSE/ENDIF statement construct can test
Code IF/THEN/ELSE/ENDIF statement constructs
Correct invalid IF/THEN, ELSE, and ENDIF JCL
statements
State reasons why IF/THEN/ELSE/ENDIF JCL errors
occur
State the advantages of using the IF/THEN/ELSE/ENDIF
statement construct instead of the COND parameter
Unit Objectives
Introduction
Unit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
5/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 5 of 55
UNIT Conditional Processing
IF/THEN/ELSE/ENDIF Construct
Nesting Conditional Constructs
Topics:
7/30/2019 JCL BASICO UNIDAD 6
6/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 6 of 55
At the end of this topic, you will be able to:
Identify the various types of job conditions that anIF/THEN/ELSE/ENDIF statement construct can test
Code IF/THEN/ELSE/ENDIF statement constructs
Correct invalid IF/THEN, ELSE, and ENDIF JCL
statements
State reasons why IF/THEN/ELSE/ENDIF JCL errors
occur
Topic Objectives
Introduction
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
7/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 7 of 55
Syntax for the IF/THEN/ELSE/ENDIF Statement Construct
What is the syntax for an IF/THEN/ELSE/ENDIF statement construct?
The syntax for coding an IF/THEN/ELSE/ENDIF statement construct is:
//name IF (relational-expression) THEN
//name JCL statement(s) to be executed when relational-expression is true
//name ELSE
//name JCL statement(s) to be executed when relational-expression is false
//name ENDIF
The IF/THEN/ELSE/ENDIF statement construct can be coded anywhere in the job after the JOB statement.
The name field in the IF/THEN/ELSE/ENDIF statement
construct is optional but if specified it must follow the
coding rules for names in JCL statements.
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
8/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 8 of 55
What are the rules for valid name fields?
Even though the name field is optional, if one is
coded then it must follow the normal coding rules
for names in JCL statements, such as:
The name must begin in position 3. If
you do not code a name then leave theposition blank
The name must be unique within the job
The first character of the name has to bealphabetical or national and it cannot bea number
The remaining characters can bealphanumeric or national
The name field must be followed by atleast one space
The Name Field
//CHECK1 IF (relational-expression) THEN
//UNIQUE IF (relational-expression) THEN
//PROG#1 IF (relational-expression) THEN
// CHECK1
//TOOMANYCHARS
//CHECK#2IF
Valid JCL Names
Invalid JCL Names
(Does not begin in position 3)
(More than eight characters)
(Needs blank space after name)
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
9/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 9 of 55Concepts
What is the Operation Field?
The operation field contains the operators IF, ELSE, or ENDIF.
What are the characteristics of the IF statement?
The IF statement always precedes a relational-expression and the identifier THEN.
Following the IF statement are all of the JCL statements to be executed when the relational-expression is true.
If there are none, then the IF statement should be followed immediately by the ELSE statement.
The Operation Field The IF Statement
// UNIQUE NAME IF RELATIONAL-EXPRESSION COMMENT
Identifier
Field
Name
Field
Operation
Field
Relational-Expression
Field
Comment
Field
... JCL statement to be executed when the expression is TRUE
THEN
Identifier
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
10/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 10 of 55Concepts
What are the characteristics of the ELSE statement?
Following the ELSE statement are all the JCL statements to be executed when the relational-expression is
false. If there are none, then the ELSE statement can be omitted.
The ELSE statement has no parameters.
Anything following the ELSE operator is considered a comment.
The Operation Field The ELSE Statement
// UNIQUE NAME
Identifier
Field
Name
Field
Operation
Field
Comment
Field
ELSE
... JCL statement to be executed when the expression is FALSE
COMMENT
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
11/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 11 of 55Concepts
What are the characteristics of the ENDIF statement?
The required ENDIF statement signifies the end of the IF/THEN/ELSE/ENDIF statement construct.
There must be at least one EXEC statement following either the IF statement or the ELSE statement.
Anything coded after the ENDIF statement is considered a comment by the operating system.
The Operation Field The ENDIF Statement
// UNIQUE NAME
Identifier
Field
Name
Field
Operation
Field
Comment
Field
ENDIF COMMENT
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
12/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 12 of 55
Place the conditional statements in the proper order.
A. // ENDIF
B. //COND IF ABC>5 THEN
C. //STEP2 EXEC PGM=DELFILE
D. // ELSE
E. //STEP1 EXEC PROC=PRINT
Are We on Track?
Review
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
13/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 13 of 55
What is the relational-expression field?
The relational-expression field follows the IF
statement and specifies the condition that is
evaluated at execution.
Depending on the values in the expression, theresult of the condition is either true or false.
In the example, the first statement tests for a
return code of less than eight. Hence the
relational-expression is RC
7/30/2019 JCL BASICO UNIDAD 6
14/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 14 of 55
Relational-expressions can be continued on more
than one line.
To continue the expression, break the expression
on a valid blank space and continue on the next
line using columns 4 through 16.
The Relational-Expression Field (contd)
Comments cannot be placed on the line you are
continuing as the system will try to evaluate the
comments as part of the expression.Continued
//TESTRC IF (ABEND | RC
7/30/2019 JCL BASICO UNIDAD 6
15/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 15 of 55
The Relational-Expression Field (contd)
A relational-expression can consist of any of the following, alone or in combination:
Comparison operators
Logical operators
NOT operators
Relational-expression keywords
The system evaluates comparison operators
after any NOT operators and before any logical
operators.
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
16/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 16 of 55
What are the characteristics of a Comparison
Operator?
Comparison operators compare a relational-
expression keyword to a numeric value. The
result of the comparison is either true or false.
The comparison operators are either alphabetic or
arithmetic.
Comparison Operators
GT or >
GE or >=
NG or >
EQ or =
NE or =
LT or .
At least one space is required both before and
after alphabetic comparison operators, such as
EQ or GT.
Comparison Operators An Example
The use of parentheses in the relational-
expression is optional, but it is useful when
coding combinations of expressions.
//TESTIT IF (RC=8) THEN
//TESTIT IF RC EQ 8 THEN
Spaces are
not required
Spaces are
required
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
18/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 18 of 55
Complete the JCL statement up to THEN operator to check if the return code is equal to 8,using parentheses.
//TESTIT _____________________
Are We on Track?
Review
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
19/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 19 of 55
Logical Operators
The logical operators include:
AND (&)
OR (|)
NOT ()
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
20/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 20 of 55
What are the characteristics of the AND
operator?
The AND (&) operator returns a value only if both
relational-expressions are true.
For example, to test if a return code is between 8and 24:
//TEST1 IF (RC>8 & RC=8 & RC
7/30/2019 JCL BASICO UNIDAD 6
21/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 21 of 55
What are the characteristics of the OR
operator?
The OR (|) operator returns a true value if either of
the relational-expression is true.
For example, to test if a return code is eitherequal to 8 or 16:
//TEST2 IF (RC>8 | RC8 | RC
7/30/2019 JCL BASICO UNIDAD 6
22/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 22 of 55
What are the characteristics of the NOT
operator?
The NOT () operator reverses the testing of a
relational-expression. The system evaluates the
NOT operator before any comparisons or logical
operators.
For example, to test if a return code is not equal
to 12:
//TEST3 IF (RC=12) THEN
Logical Operators- NOT
The NOT operator does not require a space to
separate it from the expression it is reversing.
RC = 8
IF (RC>12) THEN
Concepts
Topic: IF/THEN/ELSE/ENDIF Construct
The
condition
is true
Unit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
23/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 23 of 55Review
Complete the following JCL statement using the AND (&) operator to test if the return code isbetween 8 and 24.
//TEST1 IF (_________________) THEN
Are We on Track?
Review
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
24/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 24 of 55Review
Complete the following JCL statement using the OR (|) operator to test if the return code isequal to 8 or 16.
//TEST2 IF (_________________) THEN
Are We on Track?
Review
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
25/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 25 of 55Review
Complete the following JCL statement using the NOT () operator (with parentheses) to testif the return code is not greater than 8 and less than 24.
//TEST3 IF __________________ THEN
Are We on Track?
Review
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
26/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 26 of 55
Relational-Expression Keywords
What are the characteristics of relational-expression keywords?
Relational-expression keywords are used to test a return code, abend condition or abend completion code, or
to test if a step began executing. The relational-expression keywords are:
RC
ABEND
ABEND
ABENDCC
RUN
RUN
Preceding the keyword with a step name relates the expression to a specific job step.
Syntax:stepname.keyword
Preceding the keyword with both a step name and procedure step name relates the expression to a specific
procedure step.
Syntax: stepname.procstepname.keyword
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
27/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 27 of 55
What are the characteristics of the RCkeyword?
RC represents the highest return code received
from a previous job step.
In the example, the first statement checks if theprevious job step had a return code greater than
4.
The second statement tests if a prior job step
named COMPILE produced a return code greater
than 4.
The third one checks if a specific procedure,
PROG1 in the job step COMPILE, produced a
return code greater than 4.
Relational-Expression Keywords - RC
//TESTRC IF (RC>4) THEN
//TESTRC IF (COMPILE.RC>4) THEN
//TESTRC IF COMPILE.PROG1.RC>4 THEN
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
28/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 28 of 55
What are the characteristics of the ABENDkeyword?
The keyword ABEND tests for abnormal
termination from any previous job step.
The syntax used for ABEND is:
//name IF ABEND THEN
Or
//name IF ABEND = TRUE THEN
Both these statements will test for an abnormaltermination in any of the previous steps.
Relational-Expression Keywords - ABEND
Both formats can be preceded with a step name or
procedure step name to check specific job steps or
procedure steps for abnormal termination.
//TEST IF ABEND THEN
//TEST IF TEST1.ABEND = TRUE THEN
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
Concepts
7/30/2019 JCL BASICO UNIDAD 6
29/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 29 of 55
What are the characteristics of the ABENDkeyword?
The keyword ABEND checks for abnormal
termination from any previous job step.
The syntax used for ABEND is:
//name IF ABEND THEN
Or
//name IF ABEND = FALSE THEN
Both these statements will test to ensure anabnormal termination did not occur in any of the
previous steps.
Relational-Expression Keywords - ABEND
Both formats can be preceded with a step
name or procedure step name to ensure that
abnormal termination did not occur in specific
job steps or procedure steps.
//TEST IF ABEND THEN
//TEST IF TEST1.ABEND = FALSE THEN
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
30/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 30 of 55Review
Complete following JCL statement using the ABEND operator to test for an abnormaltermination in a prior job step named TEST1.
//TST4ABND IF (_________________) THEN
Are We on Track?
Review
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
31/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 31 of 55Review
Complete the following JCL statement using the ABEND operator to test that an abnormaltermination did not occur in a prior job step named TEST1.
//TST4ABND IF (_________________) THEN
Are We on Track?
Review
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
32/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 32 of 55
What are the characteristics of the ABENDCC keyword?
The relational-expression keyword ABENDCC tests for a specific system abend completion code or user
defined abend completion code from any previous job step.
Relational-Expression Keywords - ABENDCC
Both formats can be preceded with a step name
or procedure step name to test the abend code
from specific job steps or procedure steps.
ABENDCC = Sxxx ABENDCC = Uxxxx
S = Abnormal system
completion code
U = Abnormal user-
defined completion code
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
7/30/2019 JCL BASICO UNIDAD 6
33/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 33 of 55
The first statement tests for an abnormal systemcompletion code of 0C1 in the previous job step.
The second statement tests for an abnormal
user-defined completion code of U0100 in a prior
job step named RUNPGM in the previous job
step.
ABENDCC An Example
//TST4ABND IF ABENDCC = S0C1 THEN
//TST4ABND IF RUNPGM.ABENDCC =
// U0100 THEN
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
/OS MVS JCL I t d ti
7/30/2019 JCL BASICO UNIDAD 6
34/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 34 of 55
Relational-Expression Keywords - RUN
What are the characteristics of the RUN keyword?
The keyword RUN tests to make sure that a specific job step or procedure step has been executed.
The syntax used for RUN is:
//name IF stepname.RUN THEN
Or
//name IF stepname.RUN = TRUE THEN
A step name or both step name and procedure step
name must precede the RUN keyword.
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
/OS MVS JCL I t d ti
7/30/2019 JCL BASICO UNIDAD 6
35/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 35 of 55
Relational-Expression Keywords - RUN
What are the characteristics of the RUN keyword?
The keyword RUN tests to see if a specific job step or procedure step failed to execute.
The syntax used for RUN is:
//name IF stepname.RUN THEN
Or
//name IF stepname.RUN = FALSE THEN
A step name or both step name and procedure step name
must precede the RUN keyword.
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
/OS MVS JCL I t d ti
7/30/2019 JCL BASICO UNIDAD 6
36/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 36 of 55
In this example, the RUN keyword tests if a stepcalled LINK did not execute:
//JOB1 JOB 777,SMITH
//COMPILE EXEC PGM=COMPILE
//LINK EXEC PGM=LINK,
// COND=(8,LT,COMPILE)//TST4RUN IF LINK.RUN THEN
//TEST EXEC PGM=RECOVER
Relational-Expression Keywords - RUN An Example
If LINK does not
execute then run
RECOVER
IF LINK.RUN THEN
EXEC PGM=RECOVER
LINK
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
/OS MVS JCL I t d ti
7/30/2019 JCL BASICO UNIDAD 6
37/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 37 of 55Review
Complete the following JCL statement using the RUN operator to test if a step namedCOMPILE executed successfully.
//TST4RUN IF (_________________) THEN
Are We on Track?
Review
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
/OS MVS JCL I t d ti
7/30/2019 JCL BASICO UNIDAD 6
38/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 38 of 55Review
Complete the following JCL statement using the RUN operator to test if a step namedCOMPILE did not execute successfully.
//TST4RUN IF (_________________) THEN
Are We on Track?
Review
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
z/OS MVS JCL Introduction
7/30/2019 JCL BASICO UNIDAD 6
39/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 39 of 55
What is the Then clause?
The THEN clause in an IF/THEN/ELSE/ENDIF statement construct contains the JCL statements that exist
between the IF/THEN statement and either:
A corresponding ELSE statement (if one is specified) or
A corresponding ENDIF statement
The purpose of the THEN clause is to provide a route of execution if the condition specified in the IF
statement tests true. If no JCL statements are specified, then the THEN clause becomes a null THEN clause.
The THEN Clause
// UNIQUE NAME IF RELATIONAL-EXPRESSION COMMENT
Identifier
Field
Name
Field
Operation
Field
Relational-Expression
Field
Comment
Field
... JCL statement to be executed when the expression is TRUE
THEN
Identifier
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
z/OS MVS JCL Introduction
7/30/2019 JCL BASICO UNIDAD 6
40/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 40 of 55
The THEN Clause An Example
To illustrate the working of the THEN clause consider the following JCL code:
//TESTRC IF (RC>=8) THEN
//ERROR EXEC PGM=DELFILES
// ENDIF
//STEP2 EXEC PGM=IEBCOPY
The THEN clause contains one JCL statement named ERROR. The program DELFILES, specified in the
ERROR EXEC statement, will not execute unless the return code from any previous step is greater than or
equal to 8.
Irrespective of the value of the return code, the program IEBCOPY specified in STEP2 will run as it is not part
of the IF/THEN/ELSE/ENDIF statement construct.
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
z/OS MVS JCL Introduction
7/30/2019 JCL BASICO UNIDAD 6
41/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 41 of 55
What is the ELSE clause?
The ELSE clause in an IF/THEN/ELSE/ENDIF statement construct contains the JCL statements that exist
between the ELSE keyword and a corresponding ENDIF statement.
The purpose of the ELSE clause is to provide a route of execution if the condition specified in the IF statement
tests false. If no JCL statements are specified, then the ELSE clause becomes a null ELSE clause.
The ELSE Clause
// UNIQUE NAME
Identifier
Field
Name
Field
Operation
Field
Comment
Field
ELSE
... JCL statement to be executed when the expression is FALSE
COMMENT
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
z/OS MVS JCL Introduction
7/30/2019 JCL BASICO UNIDAD 6
42/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 42 of 55
The ELSE Clause An Example
To illustrate the working of the ELSE clause consider the following JCL code:
//TESTRUN IF STEP1.RUN THEN
//GOOD EXEC PGM=CREATE
// ELSE
//ERROR EXEC PGM=DELFILES
// ENDIF//STEP2 EXEC PGM=COMPRESS
The THEN clause contains one JCL statement named GOOD. The Program CREATE, specified in the
GOOD EXEC statement, will not be executed unless STEP1 has been executed successfully.
If STEP1 failed to execute, then a program DELFILES (specified in the statement named ERROR) will beexecuted as it is contained under the ELSE clause.
Irrespective of whether STEP1 was executed successfully or not, the program COMPRESS specified in
STEP2 will run as if it is not part of the IF/THEN/ELSE/ENDIF statement construct.
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
z/OS MVS JCL Introduction
7/30/2019 JCL BASICO UNIDAD 6
43/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 43 of 55Concepts
What is the ENDIF clause?
To end an IF/THEN/ELSE/ENDIF statement construct an ENDIF clause must be coded.
One ENDIF clause is required for each IF statement coded.
The ENDIF Clause
// UNIQUE NAME
Identifier
Field
Name
Field
Operation
Field
Comment
Field
ENDIF COMMENT
Concepts
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
z/OS MVS JCL Introduction
7/30/2019 JCL BASICO UNIDAD 6
44/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 44 of 55Review
Complete following JCL statement up to THEN by checking if the return code is equal to 8using parentheses.
//TST4RUN IF _________________
//GOOD EXEC PGM=CREATE
Are We on Track?
Review
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
z/OS MVS JCL Introduction
7/30/2019 JCL BASICO UNIDAD 6
45/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 45 of 55Review
Complete following JCL statement using the ELSE clause including the identifier field.
//TST4RUN IF (RC=8) THEN
//GOOD EXEC PGM=CREATE
__________
//ERROR EXEC PGM=DELFILES
Are We on Track?
Review
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
z/OS MVS JCL Introduction
7/30/2019 JCL BASICO UNIDAD 6
46/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 46 of 55Review
Complete following JCL statement using the ENDIF clause including the identifier field.
//TST4RUN IF (RC=8) THEN
//GOOD EXEC PGM=CREATE
// ELSE
//ERROR EXEC PGM=DELFILES
__________
//STEP2 EXEC PGM=COMPRESS
Are We on Track?
Review
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
z/OS MVS JCL Introduction
7/30/2019 JCL BASICO UNIDAD 6
47/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 47 of 55
IF/THEN/ELSE/ENDIF Construct This specifies conditional execution of job steps within a job
Glossary
Glossary
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
z/OS MVS JCL Introduction
7/30/2019 JCL BASICO UNIDAD 6
48/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 48 of 55
Now that you have completed this topic, you should be able to:
Identify the various types of job conditions that anIF/THEN/ELSE/ENDIF statement construct can test
Code IF/THEN/ELSE/ENDIF statement constructs
Correct invalid IF/THEN, ELSE, and ENDIF JCLstatements
State reasons why IF/THEN/ELSE/ENDIF JCL errors
occur
Topic Summary
Summary
Topic: IF/THEN/ELSE/ENDIF ConstructUnit: Conditional Processing
z/OS MVS JCL Introduction
7/30/2019 JCL BASICO UNIDAD 6
49/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 49 of 55
UNIT Conditional Processing
IF/THEN/ELSE/ENDIF Construct
Nesting Conditional Constructs
Topics:
z/OS MVS JCL Introduction
7/30/2019 JCL BASICO UNIDAD 6
50/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 50 of 55
At the end of this topic, you will be able to:
Code nested conditional constructs
Explain why using conditional statement constructs is
preferable to using the COND parameter
Topic Objectives
Introduction
Unit: Conditional Processing Topic: Nesting Conditional Constructs
z/OS MVS JCL Introduction
7/30/2019 JCL BASICO UNIDAD 6
51/55
z/OS MVS JCL Introduction
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 51 of 55
In a nested conditional construct the THEN clauseor the ELSE clause (or both) will contain an
additional IF/THEN/ELSE/ENDIF construct.
Each additional construct will have its own
corresponding IF/THEN,ELSE and ENDIF
statements.
The IF/THEN/ELSE/ENDIF statement construct
can be nested up to 15 levels.
The example shows a nested conditional
construct where the value of return code of a
program determines the next step.
Nesting Conditional Constructs
//COMPPGM EXEC PGM=COMPILE
//CHKCOMP IF (COMPPGM.RC4) THEN
//DELPGM EXEC PGM=DELETE
// ELSE
//RUNPGM EXEC PGM=MYPROG// ENDIF
// ENDIF
//COMPLIB EXEC PGM=COMPRESS
Concepts
Unit: Conditional Processing Topic: Nesting Conditional Constructs
z/OS MVS JCL Introduction
7/30/2019 JCL BASICO UNIDAD 6
52/55
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 52 of 55
In the outer IF/THEN/ELSE/ENDIF construct, theCHKCOMP statement checks to see if the return
code from the step named COMPPGM is less
than or equal to 4.
If the COMPPGM return code is less or equal to
4, then the LNKPGM step runs.
Next the inner IF/THEN/ELSE/ENDIF construct is
invoked, if the return code from LNKPGM step is
greater than 4, the DELETE program (in the
DELPGM step) executes.
If the return code from LNKPGM is less than or
equal to 4, step RUNPGM will be run.
Step COMPLIB will be executed regardless of any
conditional testing.
Nesting Conditional Constructs An Example
//COMPPGM EXEC PGM=COMPILE
//CHKCOMP IF (COMPPGM.RC4) THEN
//DELPGM EXEC PGM=DELETE
// ELSE
//RUNPGM EXEC PGM=MYPROG// ENDIF
// ENDIF
//COMPLIB EXEC PGM=COMPRESS
Concepts
Unit: Conditional Processing Topic: Nesting Conditional Constructs
7/30/2019 JCL BASICO UNIDAD 6
53/55
z/OS MVS JCL Introduction
7/30/2019 JCL BASICO UNIDAD 6
54/55
Copyright IBM Corp., 2000, 2004. All rights reserved. Page 54 of 55
Now that you have completed this topic, you should be able to:
Code nested conditional constructs
Explain why using conditional statement constructs is
preferable to using the COND parameter
Topic Summary
IntroductionSummary
Unit: Conditional Processing Topic: Nesting Conditional Constructs
z/OS MVS JCL Introduction
7/30/2019 JCL BASICO UNIDAD 6
55/55
Now that you have completed this unit, you should be able to:
Identify the various types of job conditions that anIF/THEN/ELSE/ENDIF statement construct can test
Code IF/THEN/ELSE/ENDIF statement constructs
Correct invalid IF/THEN, ELSE, and ENDIF JCLstatements
State reasons why IF/THEN/ELSE/ENDIF JCL errors
occur
State the advantages of using the IF/THEN/ELSE/ENDIF
statement construct instead of the COND parameter
Unit Summary
Unit: Conditional Processing