Loading documents preview...
z/OS MVS JCL Introduction
© Copyright IBM Corp., 2000, 2004. All rights reserved.
z/OS MVS JCL Introduction
UNIT
Conditional Processing
Topics: IF/THEN/ELSE/ENDIF Construct Nesting Conditional Constructs
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 2 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing 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
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 3 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing Unit Objectives At the end of this unit, you will be able to: •
Identify the various types of job conditions that an IF/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
Introduction
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 4 of 55
z/OS MVS JCL Introduction
UNIT
Conditional Processing
Topics: IF/THEN/ELSE/ENDIF Construct Nesting Conditional Constructs
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 5 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Topic Objectives At the end of this topic, you will be able to: •
Identify the various types of job conditions that an IF/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
Introduction
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 6 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
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 //name //name //name //name
IF (relational-expression) THEN JCL statement(s) to be executed when relational-expression is true ELSE JCL statement(s) to be executed when relational-expression is false 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
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 7 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
The Name Field 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 the position blank
•
The name must be unique within the job
•
The first character of the name has to be alphabetical or national and it cannot be a number
Valid JCL Names //CHECK1 IF (relational-expression) THEN //UNIQUE IF (relational-expression) THEN //PROG#1 IF (relational-expression) THEN
Invalid JCL Names // CHECK1
(Does not begin in position 3)
//TOOMANYCHARS (More than eight characters)
Concepts
•
The remaining characters can be alphanumeric or national
•
The name field must be followed by at least one space
//CHECK#2IF
(Needs blank space after name)
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 8 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
The Operation Field – The IF Statement Identifier
Name
Operation
Relational-Expression
Field
Field
Field
Field
Comment Identifier
// UNIQUE NAME IF RELATIONAL-EXPRESSION THEN
Field
COMMENT
... JCL statement to be executed when the expression is TRUE 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.
Concepts
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 9 of 55
z/OS MVS JCL Introduction Topic: IF/THEN/ELSE/ENDIF Construct
Unit: Conditional Processing
The Operation Field – The ELSE Statement Identifier
Name
Operation
Comment
Field
Field
Field
Field
//
UNIQUE NAME
ELSE
COMMENT
... JCL statement to be executed when the expression is FALSE 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.
Concepts
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 10 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
The Operation Field – The ENDIF Statement Identifier
Name
Operation
Comment
Field
Field
Field
Field
//
UNIQUE NAME
ENDIF
COMMENT
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.
Concepts
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 11 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Are We on Track?
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
Review
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 12 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
The Relational-Expression Field What is the relational-expression field? The relational-expression field follows the IF statement and specifies the condition that is evaluated at execution.
//TESTRC IF RC<8 THEN
Relational-Expression Field
Depending on the values in the expression, the result of the condition is either true or false. //TESTRC IF (RC<8) THEN In the example, the first statement tests for a return code of less than eight. Hence the relational-expression is RC<8. Also the relational-expression can be enclosed in parentheses, as shown in second statement. There must be at least one space between the IF operator and relational-expression field and similarly one space between the expression and the THEN operator. Concepts
Continued… © Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 13 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
The Relational-Expression Field (cont’d) 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.
//TESTRC IF (ABEND | RC<8 | // RC=16) THEN
Comment goes here
Comments cannot be placed on the line you are continuing as the system will try to evaluate the comments as part of the expression. Concepts
Continued… © Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 14 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
The Relational-Expression Field (cont’d) 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
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 15 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Comparison Operators What are the characteristics of a Comparison Operator? Comparison operators compare a relationalexpression keyword to a numeric value. The result of the comparison is either true or false. The comparison operators are either alphabetic or arithmetic.
Concepts
Operator
Meaning
GT or >
Greater than
GE or >=
Greater than or equal to
NG or ¬>
Not greater than
EQ or =
Equal to
NE or ¬=
Not equal to
LT or <
Less than
LE or <=
Less than or equal to
NL or ¬<
Not less than
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 16 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Comparison Operators – An Example In this example, the statement tests if a return code is equal to 8. The relational-expression (RC=8) must be both preceded and followed by at least one space. No spaces are required before or after an arithmetic operator, such as = or >. At least one space is required both before and after alphabetic comparison operators, such as EQ or GT.
//TESTIT IF (RC=8) THEN Spaces are not required //TESTIT IF RC EQ 8 THEN Spaces are required
The use of parentheses in the relationalexpression is optional, but it is useful when coding combinations of expressions. Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 17 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Are We on Track?
Complete the JCL statement up to THEN operator to check if the return code is equal to 8, using parentheses.
//TESTIT _____________________
Review
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 18 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Logical Operators The logical operators include:
Concepts
•
AND (&)
•
OR
•
NOT (¬)
(|)
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 19 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Logical Operators- AND What are the characteristics of the AND operator?
IF (RC>=8 & RC<=24) THEN
The AND (&) operator returns a value only if both relational-expressions are true. RC = 12
For example, to test if a return code is between 8 and 24:
The condition is true
//TEST1 IF (RC>8 & RC<24) THEN
The AND operator must be preceded and followed by at least one space. Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 20 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Logical Operators- OR What are the characteristics of the OR operator?
IF (RC>8 | RC<16) THEN
The OR (|) operator returns a true value if either of the relational-expression is true. RC = 12
For example, to test if a return code is either equal to 8 or 16:
The condition is false
//TEST2 IF (RC>8 | RC<16) THEN
The OR operator must be preceded and followed by at least one space. Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 21 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Logical Operators- NOT What are the characteristics of the NOT operator?
IF ¬(RC>12) THEN
The NOT (¬) operator reverses the testing of a relational-expression. The system evaluates the NOT operator before any comparisons or logical operators.
RC = 8
The condition is true
For example, to test if a return code is not equal to 12:
//TEST3 IF ¬(RC=12) THEN
The NOT operator does not require a space to separate it from the expression it is reversing. Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 22 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Are We on Track?
Complete the following JCL statement using the AND (&) operator to test if the return code is between 8 and 24.
//TEST1 IF (_________________) THEN
Review
Review
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 23 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Are We on Track?
Complete the following JCL statement using the OR (|) operator to test if the return code is equal to 8 or 16.
//TEST2 IF (_________________) THEN
Review
Review
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 24 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Are We on Track?
Complete the following JCL statement using the NOT (¬) operator (with parentheses) to test if the return code is not greater than 8 and less than 24.
//TEST3 IF __________________ THEN
Review
Review
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 25 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
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
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 26 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Relational-Expression Keywords - RC What are the characteristics of the RC keyword? RC represents the highest return code received from a previous job step.
//TESTRC IF (RC>4) THEN //TESTRC IF (COMPILE.RC>4) THEN //TESTRC IF COMPILE.PROG1.RC>4 THEN
In the example, the first statement checks if the previous 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.
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 27 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Relational-Expression Keywords - ABEND What are the characteristics of the ABEND keyword? The keyword ABEND tests for abnormal termination from any previous job step. The syntax used for ABEND is:
//TEST IF ABEND THEN
//TEST IF TEST1.ABEND = TRUE THEN
//name IF ABEND THEN Or
//name IF ABEND = TRUE THEN Both these statements will test for an abnormal termination in any of the previous steps.
Both formats can be preceded with a step name or procedure step name to check specific job steps or procedure steps for abnormal termination. Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 28 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Relational-Expression Keywords - ¬ABEND What are the characteristics of the ¬ABEND keyword? The keyword ¬ABEND checks for abnormal termination from any previous job step. The syntax used for ABEND is:
//TEST IF ¬ABEND THEN
//TEST IF TEST1.ABEND = FALSE THEN
//name IF ¬ABEND THEN Or
//name IF ABEND = FALSE THEN Both these statements will test to ensure an abnormal termination did not occur in any of the previous steps. 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. Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 29 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Are We on Track?
Complete following JCL statement using the ABEND operator to test for an abnormal termination in a prior job step named TEST1.
//TST4ABND IF (_________________) THEN
Review
Review
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 30 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Are We on Track?
Complete the following JCL statement using the ¬ABEND operator to test that an abnormal termination did not occur in a prior job step named TEST1.
//TST4ABND IF (_________________) THEN
Review
Review
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 31 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Relational-Expression Keywords - ABENDCC
ABENDCC = Sxxx
ABENDCC = Uxxxx U = Abnormal userdefined completion code
S = Abnormal system completion code
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.
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. Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 32 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
ABENDCC – An Example The first statement tests for an abnormal system completion 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.
Concepts
//TST4ABND IF ABENDCC = S0C1 THEN
//TST4ABND IF RUNPGM.ABENDCC = // U0100 THEN
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 33 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
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
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 34 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
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
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 35 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Relational-Expression Keywords - ¬RUN – An Example In this example, the ¬RUN keyword tests if a step called LINK did not execute:
//JOB1 //COMPILE //LINK // //TST4RUN //TEST
IF ¬LINK.RUN THEN EXEC PGM=RECOVER
JOB 777,SMITH EXEC PGM=COMPILE EXEC PGM=LINK, COND=(8,LT,COMPILE) IF ¬LINK.RUN THEN EXEC PGM=RECOVER
LINK If LINK does not execute then run RECOVER
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 36 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Are We on Track?
Complete the following JCL statement using the RUN operator to test if a step named COMPILE executed successfully.
//TST4RUN IF (_________________) THEN
Review
Review
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 37 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Are We on Track?
Complete the following JCL statement using the ¬RUN operator to test if a step named COMPILE did not execute successfully.
//TST4RUN IF (_________________) THEN
Review
Review
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 38 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
The THEN Clause Identifier
Name
Operation
Relational-Expression
Field
Field
Field
Field
Comment Identifier
// UNIQUE NAME IF RELATIONAL-EXPRESSION THEN
Field
COMMENT
... JCL statement to be executed when the expression is TRUE 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.
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 39 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
The THEN Clause – An Example To illustrate the working of the THEN clause consider the following JCL code:
//TESTRC //ERROR // ENDIF //STEP2
IF (RC>=8) THEN EXEC PGM=DELFILES 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
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 40 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
The ELSE Clause Identifier
Name
Operation
Comment
Field
Field
Field
Field
//
UNIQUE NAME
ELSE
COMMENT
... JCL statement to be executed when the expression is FALSE 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.
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 41 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
The ELSE Clause – An Example To illustrate the working of the ELSE clause consider the following JCL code:
//TESTRUN //GOOD // ELSE //ERROR // ENDIF //STEP2
IF STEP1.RUN THEN EXEC PGM=CREATE EXEC PGM=DELFILES
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 be executed 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
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 42 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
The ENDIF Clause Identifier
Name
Operation
Comment
Field
Field
Field
Field
//
UNIQUE NAME
ENDIF
COMMENT
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.
Concepts
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 43 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Are We on Track?
Complete following JCL statement up to THEN by checking if the return code is equal to 8 using parentheses. //TST4RUN IF _________________ //GOOD EXEC PGM=CREATE
Review
Review
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 44 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Are We on Track?
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
Review
Review
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 45 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Are We on Track?
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
Review
Review
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 46 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Glossary IF/THEN/ELSE/ENDIF Construct – This specifies conditional execution of job steps within a job
Glossary
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 47 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: IF/THEN/ELSE/ENDIF Construct
Topic Summary Now that you have completed this topic, you should be able to:
Summary
•
Identify the various types of job conditions that an IF/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
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 48 of 55
z/OS MVS JCL Introduction
UNIT
Conditional Processing
Topics: IF/THEN/ELSE/ENDIF Construct Nesting Conditional Constructs
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 49 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: Nesting Conditional Constructs
Topic Objectives 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
Introduction
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 50 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: Nesting Conditional Constructs
Nesting Conditional Constructs In a nested conditional construct the THEN clause or 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.
//COMPPGM //CHKCOMP //LNKPGM //CHKLKED //DELPGM // ELSE //RUNPGM // ENDIF // ENDIF //COMPLIB
EXEC PGM=COMPILE IF (COMPPGM.RC<=4) THEN EXEC PGM=LINK IF (LNKPGM.RC>4) THEN EXEC PGM=DELETE EXEC PGM=MYPROG
EXEC PGM=COMPRESS
The example shows a nested conditional construct where the value of return code of a program determines the next step.
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 51 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: Nesting Conditional Constructs
Nesting Conditional Constructs – An Example In the outer IF/THEN/ELSE/ENDIF construct, the CHKCOMP 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.
//COMPPGM //CHKCOMP //LNKPGM //CHKLKED //DELPGM // ELSE //RUNPGM // ENDIF // ENDIF //COMPLIB
EXEC PGM=COMPILE IF (COMPPGM.RC<=4) THEN EXEC PGM=LINK IF (LNKPGM.RC>4) THEN EXEC PGM=DELETE EXEC PGM=MYPROG
EXEC PGM=COMPRESS
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.
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 52 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: Nesting Conditional Constructs
The COND Parameter vs. Conditional Processing What is the advantage of using Conditional Processing over using the COND parameter? Both the IF/THEN/ELSE/ENDIF statement construct and the COND parameter are used to conditionally control the execution of job steps. It is always recommended to use the IF/THEN/ELSE/ENDIF statement construct for conditional testing as it is easier to read and understand compared to the COND parameter.
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 53 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing
Topic: Nesting Conditional Constructs
Topic Summary Now that you have completed this topic, you should be able to:
Summary
•
Code nested conditional constructs
•
Explain why using conditional statement constructs is preferable to using the COND parameter
Introduction
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 54 of 55
z/OS MVS JCL Introduction Unit: Conditional Processing Unit Summary Now that you have completed this unit, you should be able to:
Summary
•
Identify the various types of job conditions that an IF/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
Summary
© Copyright IBM Corp., 2000, 2004. All rights reserved.
Page 55 of 55