Joined: 10 Mar 2005 Posts: 432 Location: Milan, Italy
a) I think that a logic loop in a JCL is possible but to help you with a sample I must study your case and I need more informations....
b) I don't think that SELCOPY belong to the family of systems or application utility(usually they begin with IEH* or IEB*)
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
Sure. Your STEP2 step should run conditionally and simply submit the job again. After 10 iterations, your program PGM1 will have to change the condition code so that the STEP2 process will be bypassed.
dear moderator, when you say "your program PGM1 will have to change the condition code so that the" does it implies that PGM1 needs to have a counter set(in PARM) in it which checks for the # of times its run?...and using the CC in the cobo, register it changes the value after certain # of runs...this would be intervening in the code..is there a way which avoids this way too.
Is there any way in JCL that a counter can be SET in a step.
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
Ashutosh, basically, your process will need the following:
1. An external location to store the value of the iteration counter (database, VSAM, PDS, sequential file).
2. A program/utility that can retrieve the iteration counter, interrogate its value, perform the necessary calculation to increment it, and store the iteration counter back to its repository. Also, this program/utility should set it's return-code value based on the value of the counter.
It seems to me that a relatively simple solution is to append a record to a sequential dataset (with DISP=MOD) on each execution of the job and then check it for the total number of records. When the dataset contains 10 records, then the job will stop re-submitting itself. There are a couple of ways to handle this:
Joined: 10 Mar 2005 Posts: 432 Location: Milan, Italy
If you want to execute 10 times the same program you can use a PROC as you can see below and so you don't need a jcl loop:
Code:
//MYJOB JOB (......)
//*--------------------------- begin of proc ------------------------*
//MYPROC PROC
//PRCSTP01 EXEC PGM=PGM1
// PEND
//*--------------------------- end of proc --------------------------*
//*------------------EXECUTION OF IN-STREAM PROC------------*
//STEP001P EXEC MYPROC
//STEP002P EXEC MYPROC
...other steps....
//STEP010P EXEC MYPROC
//*--------------------------- end of job -----------------------------*
In any way...if you don't want create a proc then you can use a loop jcl or as Superk's sample or as you can see below; U need 3 files:
1) 1 Counter
2) 1 member of partitioned to put there a simple source of REXX(Don't be afraid... It's easy and if you have some questions I will be here!)
3) 1 MainJcl
4) 1 SubJcl
Specific:
- (1)Counter: Sequential or member(is the same) and the length is not important but its record format must be FB; Put in this a zero '0'.
- (2) Put this rexx in a partitioned and name the program as you like but
be sure that from col 72 to 80 no number were specified and if it happen(usually they are formed when you paste your record in insert line mode):
Code:
/*% NOCOMMENT REXX */
/* PROGRAMMA: xxxxxxxx */
/* AUTORE : MGIndaco */
/* ENV. : BATCH */
Address TSO
Parse Arg Limit
Say '-----------------------------------------'
Say '- Begin ---------------------------------'
Say '-----------------------------------------'
/*---------------------------------------*/
/*- Accept of dsname of DD JOB ---------*/
/*---------------------------------------*/
List = LISTDSI(JOB FILE)
Jcl = sysdsname
Say ' Path of JCL to submit : ' Jcl
/*---------------------------------------*/
/*- Open File Counter -------------------*/
/*---------------------------------------*/
"ExecIO 0 DiskR COUNTER(Open"
"ExecIO 1 DiskR COUNTER"
Pull Record
/*---------------------------------------*/
/*- Close File Counter ------------------*/
/*---------------------------------------*/
"ExecIO 0 DiskR COUNTER(Finis"
Record = Strip(SubStr(Record,1,10)) + 1
/*---------------------------------------*/
/*- Test of Limit -----------------------*/
/*---------------------------------------*/
If Record <= Limit Then Do
Say Record
/*---------------------------------------*/
/*- Open file Counter for write new value*/
/*---------------------------------------*/
"ExecIO 0 DiskW COUNTER(Open"
Push Record
"ExecIO 1 DiskW COUNTER"
/*----------------------------------------*/
/*- Close file Counter for write new value*/
/*----------------------------------------*/
"ExecIO 0 DiskW COUNTER(FINIS"
/*----------------------------------------*/
/*- Submit the job and get the message ---*/
/*----------------------------------------*/
X = OUTTRAP('SubTrap.')
"SUBMIT '" !!Jcl!! "'"
X = OUTTRAP('OFF')
JobIx = 0
JobIx = index(SubTrap.1,'(')
NomJob = substr(SubTrap.1,15,JobIx-15)
NumJob = substr(SubTrap.1,JobIx+1,8)
/*----------------------------------------*/
/*- Display of jobname and jobnumber -----*/
/*----------------------------------------*/
Say ' Job submitted: 'NomJob
Say ' Job number : 'NumJob
End
Else Do
/*----------------------------------------*/
/*- Limit reached.... reset of Counter ---*/
/*----------------------------------------*/
Say ' No more job will be submitted'
Say ' File Counter resetted '
Push 0
"ExecIO 0 DiskW COUNTER(Open"
"ExecIO 1 DiskW COUNTER"
"ExecIO 0 DiskW COUNTER(FINIS"
End
Say '-----------------------------------------'
Say '- End -----------------------------------'
Say '-----------------------------------------'
Exit Record
- (3)MainJcl: as above... sequential or member is the same... code
Pay attention to substitute
NAMEofPGM - member name of rexx source
2 - Limit of loop:
MyRexxLib - where you have inserted the rexx source
MyCounter - File counter
MySubJcl - your jcl..
Joined: 10 Mar 2005 Posts: 432 Location: Milan, Italy
I have tried all and I want to assure you that it funtion very well.
The best in this way is that, if you want, you can read your subjcl before submit and change all you want and have in this way not only a loop but a full control of parameter, dataset names, program names, step names and so on...
If you look well and you need more info about rexx put your request in rexx forum... It's a great language.
Joined: 26 May 2005 Posts: 28 Location: Northern VA, USA
Looping in a classic programming sense is not possible with batch JCL. It is a top-down flow.
About the closest you can come is to add steps to the end of your job to a) submit this same job again or b) submit another job, based on condition codes or abend status. The submit steps can be set up with IF-THEN or COND= parameters, whatever works in your particular case.