Thursday, April 28, 2011

JCL FAQs Series 03: IF and Conditions

JCL IF Statement Revisited

The condition portion of above statement is somewhat under documented. It can consist of an expression which evaluates to 'TRUE' or 'FALSE' or a comparison of two values. The two values being compared must be of the same type:
• a numeric value 0-4095 (something which looks like a return code). This includes the RC operator.
• values of the form Udddd where dddd is a decimal number 0001-4095 or Sxxx where xxx is a hexadecimal value in the range 001-FFF (something which looks like an abend code). This includes the ABENDCC operator.
• values 'TRUE' or 'FALSE'. This includes the RUN or ABEND operator.
The operators can:
• be specific to a step, e.g. ABEND.STEP1 which is set depending on whether or not STEP1 abended OR
• apply to the whole job: ABEND - did any step abend?


Here is an example of what can be done:
// SET ABCLEAN='TRUE'
//COPY EXEC PGM=MYPGM
....
// IF (ABEND = &ABCLEAN | COPY.RC 8) THEN
//FINAL EXEC PGM=CLEANUP
....
// ELSE
//CLEAN EXEC PGM=LASTPGM
....
// ENDIF
//

As it stands, the cleanup program runs if any step abends or the return code from the COPY step is greater than 8. However, if the setting for ABCLEAN is changed to FALSE, then the cleanup program will not run if any step abends.

Another possibility is:
....
// SET RUNFIN='FALSE'
// IF &RUNFIN THEN
//FINAL EXEC PGM=CLEANUP
....
// ENDIF

In this example, the final step will not execute. The setting for RUNFIN could be altered to TRUE to change this behaviour. Note that an IF statement or COND parameter test does not prevent the first step in a job from running.

Bypassing Selected Job Steps

One or more job steps can be bypassed by adding the following parameter to the EXEC statement for any job to be bypassed:
COND=(0,LE)
This specifies that the step will be bypassed if any return code value is greater than or equal to zero.

A job step or group of job steps can also be bypassed by adding the following statement before the first job step to be bypassed:
// IF RC <= 0 THEN and terminating the block with // ENDIF First step in a job is to be bypassed
Execute an IEFBR14 step:
// EXEC PGM=IEFBR14 as the first step in the job to provide an initial return code value.

Beginning with a Specific Job Step
The RESTART JOB parameter can be used to cause job execution to start with a specified job step. For example:
//MYJOB JOB .... ,RESTART=STEP10.COPY ....
//STEP10 EXEC IEBCOPY ....
Execution will begin with STEP10. The procedure step is COPY in this example.

The COND JOB parameter COND=(0,LE) could be specified to only execute the step specified on the RESTART parameter.

Condition Code Checking
The objective is to define when a program should run based on what the results were from earlier JCL steps. Of course, some people are still attached to the JCL COND parameter which actually specifies when you don't want the program to run. However, in most cases, IF THEN,ELSE,ENDIF JCL statements are easier to code correctly and let you do things which would be difficult to achieve with the old COND parameter.
Here is a sample JCL fragment: //COPY EXEC PGM=MYPGM .... // IF (COPY.RC = 0) THEN //NEXT EXEC PGM=NEXTPGM .... // IF (ABEND | NEXT.RC 8) THEN //FINAL EXEC PGM=CLEANUP .... // ELSE //CLEAN EXEC PGM=LASTPGM .... // ENDIF // ENDIF // If the first program runs with return code zero, then program NEXTPGM is run. If that program issues a return code greater than 8 or an earlier step has abended, then program CLEANUP is run. Otherwise, LASTPGM is run.
You can also test what the abend code value was or whether a specific job step executed.

No comments:

Post a Comment