A lot of our JCL programs are triggered from our Windows Application Servers with nothing more than a .BAT file. The batch file just runs an FTP script to upload the JCL.txt file to the Job Scheduler on the mainframe.
Most of our JCL programs are fixed text files but sometimes I have to do some variable substitution within the JCL.txt file before I upload it to the mainframe to run. I normally just do this with a VBscript because it works quite nicely to read the entire JCL.txt file into a variable and then just use the REPLACE command and then write it out to a new file to upload to the mainframe.
So my task today is to do that variable substitution within a normal batch file without using any hybrid techniques or external tools.
So lets examine this scenario. We have software that watches for a file in a specific directory. When it sees a new file in the directory it kicks off the batch file and passes the file name it found to the batch file. That file name needs to be substituted into the JCL.txt file by finding the variable %parmin% and write it out to a temp file that will then be uploaded to the job scheduler on the mainframe.
JCL.txt
Code: Select all
//$1CLTCAD JOB FORMAT,'CLT',CLASS=A,MSGLEVEL=(1,1),MSGCLASS=X 00010001
//JOBLIB DD DSN=GCP.MACH1.PROD.LINKLIB,DISP=SHR 00020001
// DD DSN=DIS.PROD.LINKLIB,DISP=SHR 00030001
//******************************************************************** 00050001
//* jcl test ** 00060001
//******************************************************************** 00080001
//DEL010 EXEC PGM=IEFBR14 00320001
//IEF01 DD DSN=DMR.CLTNPROD.ALLOCAT.DOCMAST(+01), 00330001
// DISP=(MOD,DELETE), 00340001
// UNIT=(DISK,,DEFER), 00350001
// SPACE=(TRK,0) 00360001
//IEF02 DD DSN=DMR.CLTNPROD.PROJECT.STATUS(+01), 00370001
// DISP=(MOD,DELETE), 00380001
// UNIT=(DISK,,DEFER), 00390001
// SPACE=(TRK,0) 00400001
//* 00410001
//STEP010 EXEC SAS 00420001
//MASTER DD DSN=DMR.CLTNPROD.ALLOCAT.DOCMAST(0),DISP=SHR 00430001
//RECONIN DD DSN=DMR.CLTNPROD.PROJECT.STATUS(0),DISP=SHR 00440001
//PARMIN DD * 00450001
%parmin% 00460001
/* 00470001
//MASTOUT DD DSN=DMR.CLTNPROD.ALLOCAT.DOCMAST(+01), 00510001
// DISP=(NEW,CATLG,DELETE), 00520001
// UNIT=SMS,MGMTCLAS=TRANS, 00530001
// SPACE=(CYL,(250,250),RLSE), 00540001
// DCB=(LRECL=200,BLKSIZE=0,RECFM=FB,BUFNO=10) 00550001
//RECONUP DD DSN=DMR.CLTNPROD.PROJECT.STATUS(+01), 00560001
// DISP=(NEW,CATLG,DELETE), 00570001
// UNIT=SMS,MGMTCLAS=TRANS, 00580001
// SPACE=(CYL,(250,250),RLSE), 00590001
// DCB=(LRECL=1000,BLKSIZE=0,RECFM=FB,BUFNO=10) 00600001
//SYSIN DD DSN=DMR.CLTNIFE.FILES(ALLOADHS),DISP=SHR 00610001
//* 00620001
// IF STEP010.SAS.RC > 4 THEN 00630001
//* 00640001
//DEL020 EXEC PGM=IEFBR14 00680001
//IEF02 DD DSN=DMR.CLTNPROD.ALLOCAT.DOCMAST(+01), 00690001
// DISP=(MOD,DELETE), 00700001
// UNIT=(DISK,,DEFER), 00710001
// SPACE=(TRK,0) 00720001
//IEF03 DD DSN=DMR.CLTNPROD.PROJECT.STATUS(+01), 00730001
// DISP=(MOD,DELETE), 00740001
// UNIT=(DISK,,DEFER), 00750001
// SPACE=(TRK,0) 00760001
//* 00770001
// ENDIF 00780001
// 00790001
For the sake of testing I am just hard coding my parmin variable. And I thought I would just give the CALL ECHO a try to see if it would do the DOUBLE expansion of the variable.
Code: Select all
@echo off
setlocal
:: set parmin=%1
set parmin=foo.txt
for /f "delims=" %%G in (JCL.txt) do echo %%G
pause
Sure enough it expands the variable.
Code: Select all
//PARMIN DD * 00450001
foo.txt 00460001
/* 00470001
//MASTOUT DD DSN=DMR.METLPROD.ALLOCAT.DOCMAST(+01), 00510001
Problem is the stupid special characters. It got rid of "> 4" on this line.
Code: Select all
// IF STEP010.SAS.RC THEN 00630001
I thought I could do something like this but this does not work because it seems to be expanding the variable when it PIPES it to FIND so the FIND command never finds %parmin%.
Code: Select all
@echo off
setlocal
:: set parmin=%1
set parmin=foo.txt
for /f "delims=" %%G in (JCL.txt) do (
echo %%G |find "%%parmin%%" && (call echo %%G) || (echo %%G)
)
pause
Not sure where to go from here.