Incrementing G0000V00 is a feature that the system handles. I don't think it would a good idea try and replicate it by coding it again at an application level.
Here is the Rexx that I wrote for this. It seems to be doing what it is supposed to do. I am still testing it.
Code:
****** ***************************** Top of Data ******************************
000001 /* rexx */
000002 /*------------------------------------------------------------------*
000003 * Determine the next generation to the processed. *
000004 * Allocate it to the input DDNAME expected by PGM *
000005 * Run the PGM *
000006 *------------------------------------------------------------------*/
000007 parse arg gdgbase ',' retran ',' prg ',' indd ',' profile
000008 /*------------------------------------------------------------------*
000009 * gdgbase - Input GDG base name *
000010 * retran - File to be submitted manually without altering GDG *
000011 * generation pointer *
000012 * prg - Program to be run *
000013 * indd - Input DDNAME expected by PGM *
000014 *-------------------------------------------------------------------*
000015 * Initialize variables *
000016 *------------------------------------------------------------------*/
000017 rc1 = 0
000018 result = 0
000019 procgen.1 = ''
000020 nextgen = ''
000021 if gdgbase = '' then
000022 do
000023 say '!!! GDG Base has not been passed !!!'
000024 say '!!! Program Exiting !!!'
000025 exit 12
000026 end
000027
000028 /*------------------------------------------------------------------*
000029 * If retran generation is passed, use it directly without *
000030 * altering the lastgen pointer or trying to locate it under the GDG *
000031 *------------------------------------------------------------------*/
000032 if retran /= '' then
000033 do
000034 dsirc = listdsi("'"strip(retran)"'" 'RECALL')
000035 if dsirc /= 0 then
000036 do
000037 say '!!! Retran file not found !!!'
000038 say '!!! Program Exiting !!!'
000039 exit 12
000040 end
000041 else
000042 do
000043 procgen.1 = retran
000044 say 'Generation' procgen.1,
000045 'has been submitted for retransmission'
000046 rc1 = 1
000047 end
000048 end
000049 else
000050 do
000051 /*------------------------------------------------------------------*
000052 * Check if lastgen file is empty, if so this is the first run *
000053 * of the job. Initialize lastgen file with the most current *
000054 * generation and allocate the the current gen to input DD *
000055 *------------------------------------------------------------------*/
000056 "execio 1 diskr lastgen (stem lastgen. finis"
000057 if lastgen.0 = 0 then
000058 do
000059 call bpxwdyn("alloc dsn('"gdgbase"(0)')" ,
000060 "shr reuse rtdsn(procgen.1)")
000061 if result /= 0 then
000062 do
000063 say 'No generations found'
000064 say result
000065 Exit 12
000066 end
000067 rc1 = 2
000068 end
000069 else
000070 /*------------------------------------------------------------------*
000071 * If lastgen populated locate the next generation *
000072 * pull g0000v00 of each generation under the gdg using bpxwdyn *
000073 * Start from (0) gen and work backwards *
000074 * Compare each g0000v00 with the saved lastgen
000075 *------------------------------------------------------------------*/
000076 do
000077 do n = 0 by -1 while result = 0 & lastgen.1 /= nextgen
000078 /*------------------------------------------------------------------*
000079 * Keep on stepping backwards through gdg using relative gens *
000080 * Save the G0000V00 from previous bpxwdyn before you pull the one *
000081 * prior to it via. Remember,you are going backwards (0),(-1),(-2)...*
000082 * Compare the saved g0000v00 with one from the lastgen card when you*
000083 * loop back *
000084 * Get out of the loop when one of the following becomes true: *
000085 * a) Saved lastgen from PREVIOUS bpxwdyn matched the one on in the *
000086 * lastgen card *
000087 * !!! This means your MOST RECENT bpxwdyn just pulled in the DSN *
000088 * after the one saved in the lastgen card !!! *
000089 * b) The result turns non-zero *
000090 * Non-zero result means you have gone past the old generation *
000091 *------------------------------------------------------------------*/
000092 procgen.1 = nextgen
000093 call bpxwdyn("alloc dsn('"gdgbase"("n")')",
000094 "shr reuse rtdsn(nextgen)")
000095 end
000096 select
000097 when result = 0 & n = -2 then
000098 say procgen.1 'will be processed'
000099 when result = 0 & n < -2 then
000100 do
000101 say procgen.1 'will be processed'
000102 say abs(n) - 2 'file(s) remaining after this one'
000103 say 'SRSTAT file is being populated'
000104 srstatc.1 = "SRSTAT '"gdgbase"'",
000105 "AVAIL(YES) SUBSYS(EMSG)"
000106 "execio 1 diskw srstatc (stem srstatc. finis"
000107 rc1 = 3
000108 end
000109 when result = 0 then
000110 do
000111 say 'No more generations to process'
000112 Exit 4
000113 end
000114 otherwise
000115 do
000116 say 'Last generation not found'
000117 say 'result=' result
000118 Exit 12
000119 end
000120 end
000121 end
000122 "execio 1 diskw lastgen (stem procgen. finis"
000123 end
000124 if prg /= '' then
000125 do
000126 if indd /= '' then
000127 do
000128 "alloc fi("indd") da('"procgen.1"') shr"
000129 if rc <> 0 then exit 12
000130 address attchmvs prg
000131 if rc <> 0 then exit rc
000132 address tso "free f("indd")"
000133 end
000134 else
000135 do
000136 say 'Program Name passed without indd'
000137 Exit 12
000138 end
000139 end
000140 else
000141 do
000142 "execio 1 diskw procgen (stem procgen. finis"
000143 if rc <> 0 then exit 12
000144 end
000145 exit rc1
****** **************************** Bottom of Data ****************************
Thank you so much for every one's feed back and suggestions. Especially, Mr Robert Sample. I would greatly appreciate it if you could let me know if you spot problems with this code.
I have been testing this for a few days now. It seems to working. If lastgen file is empty it picks the latest generation that is out there saves it in lastgen, as expected, and allocates and to the input DDNAME and calls the program passed to it as prg. If lastgen has a DSN in it, it decrements relative gen numbers of the gdg iteratively, pulls the DSN for each and compares it with the saved lastgen. If a match is found it identifies the gen to processed as the one after the last gen and processes it by calling prg as before. If there are more than one generation out there after the last gen, it genrates SRSTAT command in sequential file and set rc=3, in additon to processing described before. A subsequent job step submits the command to TWS, if rc=3. The job thus gets 'auto submitted' and the lagging genearion will get picked up. This was done to handle to 'generation lag' introduced (very rarely) due to scheduling issues. There is no listcat being done, no parsing of listing.