Interpreted CL Members
March 7, 2012 Hey, Ted
I am thinking of writing a program that will read a source member of CL commands, interpreting them and running them dynamically one at a time. I can think of several situations in which such a utility would be more suitable than compiled CL programs. Before I re-invent the wheel, I want to know if IBM i already has something like that.
Yes, there’s something like that. You can do this sort of thing with input spooling. I’ve only used input spooling on occasion, so I’m not an expert, but I can show you how it works.
Create a source physical file member to hold the CL commands. Place Batch Job (//BCHJOB) and End Batch Job (//ENDBCHJOB) commands in the first and last records, with your commands in between, like this:
//BCHJOB JOB(MYJOB) JOBQ(NOMAX) DSPLIBL OUTPUT(*PRINT) DSPLIB LIB(MYLIB) OUTPUT(*PRINT) //ENDBCHJOB
Use the Submit Database Job (SBMDBJOB) to run the commands in the file.
SBMDBJOB FILE(MYLIB/MYSRCF) MBR(MYSRCMBR)
One thing you should be aware of is that most of the parameters that you’re accustomed to placing in the Submit Job (SBMJOB) command don’t appear in SBMDBJOB, but in BCHJOB instead.
In addition to CL commands, the file may contain input data for the job stream. Tell the program to read a file named QINLINE. Here’s such a program, which I call MYRPGPGM.
Fqinline ip f 80 disk Fqsysprt o f 132 printer D count s 3p 0 Iqinline ns 01 I 1 80 DataIn /free count += 1; /end-free Oqsysprt h 1p 1 O 'Begin' O d 01 1 O count 4 O DataIn + 1 O t lr 1 O 'End'
Surround the data with //DATA and an end-of-data marker, which defaults to //.
//BCHJOB JOB(MYJOB) JOBQ(NOMAX) CALL MYRPGPGM //DATA LINE 1 LINE 2 LINE 3 AND FINAL // //ENDBCHJOB
As I said, I’ve rarely used input spooling. I suspect that’s true in general. When I was new to the System/38 world (having worked only with S/34 and S/36), I asked an experienced S/38 programmer how he submitted batch jobs, and he replied, “SBMJOB. Is there any other way?”