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:
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.