Execute same step again
Select messages from
# through # FAQ
[/[Print]\]

MVSFORUMS.com -> Job Control Language(JCL)

#1: Execute same step again Author: chuck,  PostPosted: Fri Mar 06, 2020 3:57 pm
    —
I have a situation in a job as follows.
Execute a step. The step produces an output file. If the file is not empty execute the step again. Repeat till file is empty. AFAIK there is no concept of a GOTO in JCL Smile

The specifics are as follows.
The step is a load for a DB2 table. This table has rows that are parents to other rows. Sometimes a load will not complete since the parents are not present. But the initial load will load some of the parents. The failed rows are written to a discard file. if the discard file is not empty you retry the load. If you do it enough times the load will finish with the discard file being empty.

I guess the solution may not be in JCL? But any thoughts are appreciated.

#2: Re: Execute same step again Author: kolusu, Location: San Jose PostPosted: Fri Mar 06, 2020 8:08 pm
    —
chuck wrote:
I have a situation in a job as follows.
Execute a step. The step produces an output file. If the file is not empty execute the step again. Repeat till file is empty. AFAIK there is no concept of a GOTO in JCL Smile

The specifics are as follows.
The step is a load for a DB2 table. This table has rows that are parents to other rows. Sometimes a load will not complete since the parents are not present. But the initial load will load some of the parents. The failed rows are written to a discard file. if the discard file is not empty you retry the load. If you do it enough times the load will finish with the discard file being empty.

I guess the solution may not be in JCL? But any thoughts are appreciated.


Chuck,

It is quite simple.

1. Check if input DISCARD file is empty. will get RC=4 if the file is empty
2. If empty check returns RC=0 then it is NOT empty and you need to run your load step.
3. You can once again submit this JCL as is

here is a sample.

Code:

//***************************************************************
//*  SETS RC=0000 IF DATASET HAS RECORDS                        *
//*  SETS RC=0004 IF DATASET IS EMPTY                           *
//***************************************************************
//STEP0100 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//MYFILE   DD DISP=SHR,DSN=<datasetname>
//SYSIN    DD *
  PRINT INFILE(MYFILE) CHARACTER COUNT(1)
/*
//***************************************************************
//* RUN THE LOAD JOB                                            *
//***************************************************************
//STEP0200 EXEC  PGM=loadtodb2,COND=(4,EQ,STEP0100)
....
//***************************************************************
//* SUBMIT THIS JCL TO INTERNAL READER UNTIL DISCARD FILE IS    *
//* EMPTY                                                       *
//***************************************************************
//STEP0300 EXEC PGM=IKJEFT01,COND=(4,EQ,STEP0100)
//SYSTSPRT DD SYSOUT=*                                           
//SYSTSIN  DD *
SUBMIT 'YOUR.PDS.JCL(JCLNAME)'     
/*

#3: Re: Execute same step again Author: chuck,  PostPosted: Mon Mar 09, 2020 9:58 am
    —
kolusu wrote:
chuck wrote:
I have a situation in a job as follows.
Execute a step. The step produces an output file. If the file is not empty execute the step again. Repeat till file is empty. AFAIK there is no concept of a GOTO in JCL Smile

The specifics are as follows.
The step is a load for a DB2 table. This table has rows that are parents to other rows. Sometimes a load will not complete since the parents are not present. But the initial load will load some of the parents. The failed rows are written to a discard file. if the discard file is not empty you retry the load. If you do it enough times the load will finish with the discard file being empty.

I guess the solution may not be in JCL? But any thoughts are appreciated.


Chuck,

It is quite simple.

1. Check if input DISCARD file is empty. will get RC=4 if the file is empty
2. If empty check returns RC=0 then it is NOT empty and you need to run your load step.
3. You can once again submit this JCL as is

here is a sample.

Code:

//***************************************************************
//*  SETS RC=0000 IF DATASET HAS RECORDS                        *
//*  SETS RC=0004 IF DATASET IS EMPTY                           *
//***************************************************************
//STEP0100 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//MYFILE   DD DISP=SHR,DSN=<datasetname>
//SYSIN    DD *
  PRINT INFILE(MYFILE) CHARACTER COUNT(1)
/*
//***************************************************************
//* RUN THE LOAD JOB                                            *
//***************************************************************
//STEP0200 EXEC  PGM=loadtodb2,COND=(4,EQ,STEP0100)
....
//***************************************************************
//* SUBMIT THIS JCL TO INTERNAL READER UNTIL DISCARD FILE IS    *
//* EMPTY                                                       *
//***************************************************************
//STEP0300 EXEC PGM=IKJEFT01,COND=(4,EQ,STEP0100)
//SYSTSPRT DD SYSOUT=*                                           
//SYSTSIN  DD *
SUBMIT 'YOUR.PDS.JCL(JCLNAME)'     
/*


Hi,
Thanks for that. I wasn't familiar with SUBMIT verb at all.

Just curious about one thing. The step that checks if file is empty- wouldn't that be after the load step?
The load step would potentially populate the discards dataset and I would want to check if it's empty or not after the load step has run, right?

Regards

#4: Re: Execute same step again Author: kolusu, Location: San Jose PostPosted: Mon Mar 09, 2020 10:05 am
    —
chuck wrote:


Hi,
Thanks for that. I wasn't familiar with SUBMIT verb at all.

Just curious about one thing. The step that checks if file is empty- wouldn't that be after the load step?
The load step would potentially populate the discards dataset and I would want to check if it's empty or not after the load step has run, right?

Regards


Chuck,

You can move it after the load step provided the load step handles the empty file case. I had the empty file check first as I wanted to skip the load step in case the file is empty. The COND check skips the LOAD and SUBMIT steps if the file is empty. If you move the file check after the LOAD step, then you will execute the LOAD step unconditionally.

#5: Re: Execute same step again Author: chuck,  PostPosted: Fri Mar 13, 2020 9:12 am
    —
kolusu wrote:
chuck wrote:


Hi,
Thanks for that. I wasn't familiar with SUBMIT verb at all.

Just curious about one thing. The step that checks if file is empty- wouldn't that be after the load step?
The load step would potentially populate the discards dataset and I would want to check if it's empty or not after the load step has run, right?

Regards


Chuck,

You can move it after the load step provided the load step handles the empty file case. I had the empty file check first as I wanted to skip the load step in case the file is empty. The COND check skips the LOAD and SUBMIT steps if the file is empty. If you move the file check after the LOAD step, then you will execute the LOAD step unconditionally.


Cool- yeah, the LOAD will be performed at least once unconditionally. I am bit more of an IF/ENDIF fan, never really came to grips with COND Smile
Thanks!



MVSFORUMS.com -> Job Control Language(JCL)


output generated using printer-friendly topic mod. All times are GMT - 5 Hours

Page 1 of 1

Powered by phpBB © 2001, 2005 phpBB Group