MainframeSupports
tip week 27/2012:

The title of this weeks tip may seem a little exaggerated as JCL in no way supports the use of REXX, but with only a little effort it is possible to write a REXX program directly in the JCL job stream and execute the program in the following step. I have seen others use this method, but I could not find a good reason to use it myself until one day when I needed to use a JCL variable in some SYSIN. Unfortunately JCL does not support the use of JCL variables in SYSIN. Instead I invented the following piece of JCL:

...
//         SET PGMNAME=MYSQLPGM
//MAKEREXX EXEC PGM=IEBGENER
//SYSPRINT DD SYSOUT=*
//SYSIN    DD DUMMY
//SYSUT2   DD DISP=(NEW,PASS),DSN=&&REXX(REXXPGM),
//         SPACE=(TRK,(1,1,1)),RECFM=FB,LRECL=80
//SYSUT1   DD *
  /* REXX */
  ARG PGMNAME
  MYSQLWHR.0 = 1
  MYSQLWHR.1 = " WHERE PROGNAME = '"PGMNAME"'"
  "EXECIO * DISKW MYSQLWHR (STEM MYSQLWHR. OPEN FINIS)"
/*
//*
//RUNREXX  EXEC PGM=IKJEFT01,PARM='%REXXPGM &PGMNAME'
//SYSTSPRT DD SYSOUT=*
//SYSTSIN  DD DUMMY
//SYSEXEC  DD DISP=(OLD,DELETE),DSN=&&REXX
//MYSQLWHR DD DISP=(NEW,PASS),DSN=&&MYSQLWHR,
//         SPACE=(TRK,1),RECFM=FB,LRECL=80
...

The step MAKEREXX writes the REXX-code to the temporary dataset &&REXX in member REXXPGM. The following step RUNREXX executes the REXX, which writes a line to the temporary dataset &&MYSQLWHR. This temporary dataset I use in another step to build a SQL statement. The important point is that by using the inline REXX I can transfer the value of the JCL variable PGMNAME to a dataset, and this dataset I can subsequently use as SYSIN (or any other kind of dataset input). I could have chosen to create all SYSIN in the REXX, but then the REXX would be bigger and the JCL harder to read and understand. If you are not familiar with how to concatenate SYSIN data written directly in the JCL with datasets, then it might be a good idea to let the REXX create all the input.

Previous tip in english        Forrige danske tip        Tip list