2
votes

I am trying to get my head around using the COND statement in JCL on both the JOB step and the EXEC step. My aim is as follows:

  • All steps must complete with zero return code
  • Unless explicitly indicated for a particular step
  • The job should stop when a step completes with a return code not expected

Mostly, all steps will complete with zero, so it is the unusual path to have the over-ride. I don't want to have to code COND on each EXEC step to cover the normal zero case.

I had hoped that the following would do this, but I think the priority of COND on the JOB step appears to over-ride COND on an EXEC step.

//MYJOB   JOB ,COND=(0,NE)
//JOBLIB  DD   DSN=...
//        DD   DSN=...
//STEP1   EXEC PGM=MYPGM1
//STEP2   EXEC PGM=MYPGM2
//STEP3   EXEC PGM=MYPGM3,COND=(8,NE,STEP2)
//STEP4   EXEC PGM=MYPGM4
//

Is there any way to code this without doing the following:

//MYJOB   JOB 
//JOBLIB  DD   DSN=...
//        DD   DSN=...
//STEP1   EXEC PGM=MYPGM1
//STEP2   EXEC PGM=MYPGM2,COND=(0,NE,STEP1)
//STEP3   EXEC PGM=MYPGM3,COND=(8,NE,STEP2)
//STEP4   EXEC PGM=MYPGM4,COND=(0,NE,STEP3)
//
3
What is your goal? To abort the job at the first sign of trouble? Does step 3 have to get a RC 8, or is 8 or less OK? - Kevin McKenzie
@KevinMcKenzie - yes exactly - stop the job when a step has a non-zero RC, except for occasional steps that are expected to end with a particular RC. I'll update question to note this. In my example, STEP3 must be RC=8 exactly. - Morag Hughson

3 Answers

1
votes

According to the JCL Language Reference manual the system first checks the condition specified on the job card. If this is met the job terminates otherwise it then checks the cond code on the step.

FWIW I have always seen step condition codes and not JOB condition codes.

0
votes

Going by your dot pointed criteria your options are to code step based CONDs (which you have already discerned) or to use IF...THEN...ELSE...ENDIF statements around blocks of steps that you want to prevent from running based on return codes. IFs are much easier to code and read than CONDs although they are more verbose.

For example, this job uses IDCAMS to force a return code via the SET LASTCC command. The underscore is an integer up to 16, any higher will simply yield 16.

I have wrapped steps in 2 IF...ENDIF blocks. See below for output using RCs that trigger each outcome.

Command ===>                                                          Scroll ===> CSR
000001 //MYJOB    JOB (AA-1234),MYJOB,CLASS=P,MSGCLASS=X,REGION=0M, 
000002 // NOTIFY=&SYSUID 
000003 //* 
000004 //STEP1    EXEC PGM=IDCAMS 
000005 //SYSPRINT DD   SYSOUT=* 
000006 //SYSIN    DD   * 
000007  SET LASTCC=_ 
000008 /* 
000009 //IF1      IF   RC EQ 0 THEN 
000010 //STEP2    EXEC PGM=IDCAMS 
000011 //SYSPRINT DD   SYSOUT=* 
000012 //SYSIN    DD   * 
000013  SET LASTCC=_ 
000014 /* 
000015 //IF2      IF   STEP2.RC LT 8 THEN 
000016 //STEP3    EXEC PGM=IEFBR14 
000017 //STEP4    EXEC PGM=IEFBR14 
000018 //STEP5    EXEC PGM=IEFBR14 
000019 //EIF2     ENDIF 
000020 //EIF1     ENDIF 
****** ******************************** Bottom of Data ********************************

Will yield the following:

When I set the LASTCC value of STEP1 to 4 and STEP2 to any :

14.03.41 JOB26149  IEF403I MYJOB - STARTED - TIME=14.03.41                                 
14.03.41 JOB26149  GSDMV20I -JOBNAME  STEPNAME PROCSTEP CCODE ELAPSED-TIME  CPU-TIME STEPNO
14.03.41 JOB26149  GSDMV21I -MYJOB             STEP1        4     00:00:00     0.02S     1 
14.03.41 JOB26149  GSDMV21I -MYJOB             STEP2    FLUSH     00:00:00     0.00S     2 
14.03.41 JOB26149  GSDMV21I -MYJOB             STEP3    FLUSH     00:00:00     0.00S     3 
14.03.41 JOB26149  GSDMV21I -MYJOB             STEP4    FLUSH     00:00:00     0.00S     4 
14.03.41 JOB26149  GSDMV21I -MYJOB             STEP5    FLUSH     00:00:00     0.00S     5 
14.03.41 JOB26149  IEF404I MYJOB - ENDED - TIME=14.03.41                                   
14.03.41 JOB26149  $HASP395 MYJOB    ENDED - RC=0004                                       

When I set the the LASTCC value of STEP1 to 0 and STEP2 to 4 :

14.02.40 JOB26136  IEF403I MYJOB - STARTED - TIME=14.02.40                                 
14.02.40 JOB26136  GSDMV20I -JOBNAME  STEPNAME PROCSTEP CCODE ELAPSED-TIME  CPU-TIME STEPNO
14.02.40 JOB26136  GSDMV21I -MYJOB             STEP1        0     00:00:00     0.03S     1 
14.02.41 JOB26136  GSDMV21I -MYJOB             STEP2        4     00:00:00     0.02S     2 
14.02.41 JOB26136  GSDMV21I -MYJOB             STEP3        0     00:00:00     0.00S     3 
14.02.41 JOB26136  GSDMV21I -MYJOB             STEP4        0     00:00:00     0.00S     4 
14.02.41 JOB26136  GSDMV21I -MYJOB             STEP5        0     00:00:00     0.00S     5 
14.02.41 JOB26136  IEF404I MYJOB - ENDED - TIME=14.02.41                                   
14.02.41 JOB26136  $HASP395 MYJOB    ENDED - RC=0004                                       

When I set the the LASTCC value of STEP1 to 0 and STEP2 to 8 :

13.59.41 JOB25747  IEF403I MYJOB - STARTED - TIME=13.59.41                                 
13.59.41 JOB25747  GSDMV20I -JOBNAME  STEPNAME PROCSTEP CCODE ELAPSED-TIME  CPU-TIME STEPNO
13.59.41 JOB25747  GSDMV21I -MYJOB             STEP1        0     00:00:00     0.03S     1 
13.59.41 JOB25747  GSDMV21I -MYJOB             STEP2        8     00:00:00     0.01S     2 
13.59.41 JOB25747  GSDMV21I -MYJOB             STEP3    FLUSH     00:00:00     0.00S     3 
13.59.41 JOB25747  GSDMV21I -MYJOB             STEP4    FLUSH     00:00:00     0.00S     4 
13.59.41 JOB25747  GSDMV21I -MYJOB             STEP5    FLUSH     00:00:00     0.00S     5 
13.59.41 JOB25747  IEF404I MYJOB - ENDED - TIME=13.59.41                                   
13.59.41 JOB25747  $HASP395 MYJOB    ENDED - RC=0008                                       

Hope this helps in some way.

0
votes

You're asking if there is any way to accmomplish what you want. Here is one using an instream procedure:

//jobname  JOB .....                                                    
//*                                                                     
//* --- Start of instream procedure ----------------------------------- 
//*                                                                     
//$EXEC   PROC $PGM=,$PARM=,$COND=(0,NE)                                
//PS      EXEC PGM=&$PGM,PARM=&$PARM,COND=(&$COND)                      
//        PEND                                                          
//*                                                                     
//* --- End of instream procedure ------------------------------------- 
//*                                                                     
//STEP01  EXEC $EXEC,$PGM=MYPGM1                                        
//* add any DD statements for MYPGM1 hereafter                          
//*                                                                     
//STEP02  EXEC $EXEC,$PGM=MYPGM2                                        
//* add any DD statements for MYPGM2 hereafter                          
//*                                                                     
//STEP03  EXEC $EXEC,$PGM=MYPGM3,$COND=(8,NE,STEP02.PS)                 
//* add any DD statements for MYPGM3 hereafter                          
//*                                                                     
//STEP04  EXEC $EXEC,$PGM=MYPGM4                                        
//* add any DD statements for MYPGM4 hereafter                          
//*                                                                     

The instream prodecure has COND=(0,NE) on the EXEC, so this applies to any step executing that procedure. Using the $COND procedure parameter, you can override on any step as needed. Note that the actual step is now a procedure step, so COND= needs you to specify the step ("STEPnn" here), and the procedure step (always "PS" in this sample).