Using a batch REXX procedure to generate a unique
output data set name
Sample JCL which show how to use the REXX procedure.
The sample JCL to put date and time in the JCL and run DFSMSdss DUMP
shows a sample of how to put date and time in the JCL to generate
unique names for the output data set each time the job is run: Figure 1. Sample JCL to put
date and time in the JCL and run DFSMSdss DUMP
For both samples, the REXX procedure must be placed in
the data set allocated to SYSPROC.
Here is the REXX procedure, JCL1 (input and output files
in the procedure): Figure 4. Sample REXX procedure
JCL1 for dynamic allocation
/*REXX: ***************************************************************/
/* */
/* This REXX procedure obtains the system date and time and replace */
/* &DATE and &TIME in the input member with current date and time */
/* and write all changed and unchanged lines to the output member. */
/* */
/* Input is taken from the data set specified in variable dsni and */
/* member specified in inmem. */
/* */
/* Output is written to the dataset specified in variable dsno and */
/* member specified in outmem. */
/* After conversion the output is submitted. */
/* */
/* The indd and outdd names are used to allocate the datasets to */
/* ddnames. They are freed in the end of this procedure. */
/* */
/* Customize the names below to get the correct input and output. */
/* */
/**********************************************************************/
/**********************************************************************/
/* DATASETNAMES */
/**********************************************************************/
dsni = "USER1.CNTL" /* INPUT LIBRARY */
dsno = "USER1.CNTL" /* OUTPUT LIBRARY */
indd = 'DDI' /* input ddname */
outdd = 'DDO' /* output ddname */
/**********************************************************************/
/* MEMBERS */
/**********************************************************************/
inmem = 'DFDSS' /* Input JCL */
outmem = 'TEMP' /* Output JCL */
/**********************************************************************/
/* Allocate datasets */
/**********************************************************************/
"ALLOC DSN('" || dsni || "(" || inmem || ")') FILE(" || indd || ")"
"ALLOC DSN('" || dsno || "(" || outmem || ")') FILE(" || outdd || ")"
/**********************************************************************/
/* Read all lines */
/**********************************************************************/
"EXECIO * DISKR" indd "1 (FINIS STEM IN.)"
/**********************************************************************/
/* Get system date and time. */
/* Date is saved as yymmdd */
/* Time is saved as hhmmss */
/**********************************************************************/
date = date('S')
date = substr(date,3)
time = time('N')
time = substr(time,1,2) || substr(time,4,2) || substr(time,7,2)
/**********************************************************************/
/* Check all lines for &DATE or &TIME and replace them with the */
/* saved values in date and time. */
/**********************************************************************/
o = 0 /* init */
do i = 1 to in.0 /* do for all input */
o = o + 1 /* one more line for output */
out.o = in.i /* copy to output */
ind = pos('&DATE',out.o) /* any date? */
do while ind > 0 /* do while date found */
out.o = insert(' ',out.o,ind,1) /* insert a blank since */
out.o = overlay(date,out.o,ind) /* overlay is one longer */
ind = pos('&DATE',out.o) /* any more? */
end /* */
ind = pos('&TIME',out.o) /* any time? */
do while ind > 0 /* do while time found */
out.o = insert(' ',out.o,ind,1) /* insert a blank since */
out.o = overlay(time,out.o,ind) /* overlay is one longer */
ind = pos('&TIME',out.o) /* any more? */
end /* */
end
/**********************************************************************/
/* Write all lines to output dataset */
/**********************************************************************/
"EXECIO * DISKW" outdd "(FINIS STEM OUT.)"
/**********************************************************************/
/* Free the allocated datasets */
/**********************************************************************/
"FREE FILE(" || indd || ")"
"FREE FILE(" || outdd || ")"
/**********************************************************************/
/* Submit the changed job and return */
/**********************************************************************/
"SUBMIT '" || dsno || "(" || outmem || ")'"
return
Here is the REXX procedure, JCL2 (input and output files
in the JCL): Figure 5. Sample REXX procedure
JCL2 for dynamic allocation
/*REXX: ***************************************************************/
/* */
/* This REXX procedure obtains system date and time and replace */
/* &DATE and &TIME in the input member with current date and time */
/* and write all changed and unchanged lines to the output member. */
/* */
/* Input is taken from the dataset specified in the JCL for the */
/* ddname given in variable indd, in this example DDI */
/* */
/* Output is written to the dataset specified in the JCL for the */
/* ddname given in variable outdd, in this example DDO */
/* After conversion the output is submitted and the member used */
/* for that is in variable outmem, in this example TEMP */
/* */
/* Customize the names below to get the correct input and output. */
/* */
/**********************************************************************/
/**********************************************************************/
/* DDNAMES and member */
/**********************************************************************/
outmem = 'TEMP' /* output member given in JCL */
indd = 'DDI' /* input ddname */
outdd = 'DDO' /* output ddname */
/**********************************************************************/
/* Read all lines */
/**********************************************************************/
"EXECIO * DISKR" indd "1 (FINIS STEM IN.)"
/**********************************************************************/
/* Get system date and time. */
/* Date is saved as yymmdd */
/* Time is saved as hhmmss */
/**********************************************************************/
date = date('S')
date = substr(date,3)
time = time('N')
time = substr(time,1,2) || substr(time,4,2) || substr(time,7,2)
/*********************************************************************/
/* Check all lines for DATE or TIME and replace them with the */
/* saved values in date and time. */
/*********************************************************************/
o = 0 /* init */
do i = 1 to in.0 /* do for all input */
o = o + 1 /* one more line for output */
out.o = in.i /* copy to output */
ind = pos('DATE',out.o) /* any date? */
do while ind > 0 /* do while date found */
out.o = insert(' ',out.o,ind,1) /* insert a blank since */
out.o = overlay(date,out.o,ind) /* overlay is one longer */
ind = pos('DATE',out.o) /* any more? */
end /* */
ind = pos('TIME',out.o) /* any time? */
do while ind > 0 /* do while time found */
out.o = insert(' ',out.o,ind,1) /* insert a blank since */
out.o = overlay(time,out.o,ind) /* overlay is one longer */
ind = pos('TIME',out.o) /* any more? */
end /* */
end
/*********************************************************************/
/* Write all lines to output dataset */
/*********************************************************************/
"EXECIO * DISKW" outdd "(FINIS STEM OUT.)"
/*********************************************************************/
/* Get datasetname for output */
/*********************************************************************/
x = LISTDSI(outdd "FILE")
/*********************************************************************/
/* Submit the changed job and return */
/*********************************************************************/
"SUBMIT '" || sysdsname || "(" || outmem || ")'"
return
The job submitted by the previous procedures looks like: Figure 6. Job submitted by REXX procedure
JCL1 and JCL2