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


//JOB7     JOB MSGCLASS=X,CLASS=A,MSGLEVEL=(1,1),REGION=0M
//DSS EXEC  PGM=ADRDSSU
//DD1 DD UNIT=3590,VOL=SER=TAPE04,
//         LABEL=(1,SL),DISP=(NEW,CATLG),
//         DSN=BACKUP.A&DATE.A&TIME
//SYSPRINT DD SYSOUT=*
//SYSIN    DD    *
     DUMP OUTDD(DD1) -
     DS(INCLUSER1.DATASET1)) -
     CICSVRBACKUP
/*

Sample JCL to start REXX™ procedure, JCL1 (input/output files in the proc) and Sample JCL to start REXX™ procedure, JCL2 (input/output files in the JCL) show two samples of how to start a batch REXX™ procedure to modify and submit the JCL in Sample JCL to put date and time in the JCL and run DFSMSdss™ DUMP.

Sample JCL to start REXX™ procedure, JCL1 (input/output files in the proc) calls the REXX™ procedure in Sample REXX™ procedure JCL1 for dynamic allocation to replace the &DATE and &TIME values in Sample JCL to put date and time in the JCL and run DFSMSdss™ DUMP with the real date and time values. You must customize the input and output DD names, library, and member names in the REXX™ procedure.
Figure 2. Sample JCL to start REXX™ procedure, JCL1 (input/output files in the proc)


//JOB8     JOB MSGCLASS=X,CLASS=A,MSGLEVEL=(1,1),REGION=0M
//TSO   EXEC  PGM=IKJEFT01,PARM='JCL1'
//SYSPROC  DD DSN=USER1.CLIST,DISP=SHR
//SYSTSPRT DD SYSOUT=*
//SYSTSIN  DD DUMMY

Sample JCL to start REXX™ procedure, JCL2 (input/output files in the JCL) calls the REXX™ procedure in Sample REXX™ procedure JCL2 for dynamic allocation to replace the &DATE and &TIME values in Sample JCL to put date and time in the JCL and run DFSMSdss™ DUMP with the real date and time values. This is similar to Sample JCL to start REXX™ procedure, JCL1 (input/output files in the proc), but the input and output DD names, library, and member names are specified in the JCL instead of the REXX™ procedure. You must customize the input and output DD names, library, and member names in the JCL.
Figure 3. Sample JCL to start REXX™ procedure, JCL2 (input/output files in the JCL)



//JOB9     JOB MSGCLASS=X,CLASS=A,MSGLEVEL=(1,1),REGION=0M
//TSO   EXEC  PGM=IKJEFT01,PARM='JCL2'
//SYSPROC  DD DSN=USER1.CLIST,DISP=SHR
//DDI      DD DSN=USER1.CNTL(DFDSS),DISP=SHR
//DDO      DD DSN=USER1.CNTL(TEMP),DISP=SHR
//SYSTSPRT DD SYSOUT=*
//SYSTSIN  DD DUMMY

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



//JOB10     JOB MSGCLASS=X,CLASS=A,MSGLEVEL=(1,1),REGION=0M
//DSS   EXEC  PGM=ADRDSSU
//DD1   DD UNIT=3480,VOL=SER=TAPE04,
//         LABEL=(1,SL),DISP=(NEW,CATLG),
//         DSN=BACKUP.A001103.A141213
//SYSPRINT DD SYSOUT=*
//SYSIN    DD    *
     DUMP OUTDD(DD1) -
     DS(INCL(USER1.DATASET1)) -
     CICSVRBACKUP
/*