EXEC CICS SPOOLOPEN
EXEC CICS SPOOLWRITE
EXEC CICS SPOOLCLOSE
You tell CICS to submit the JCL by coding
USERID('INTRDR') on the
SPOOLOPEN command. In addition, you should not code
NODE('*'), but include a specific node or
NODE('LOCAL') if the job is to run local system. You must also be sure you specify the correct output class for the standards at your shop. Look in the Application Programming Reference for details about how the commands work.
Alternatively, you can use an extrapartiion transient data queue (TDQ). The JCL or definition of the TDQ should point to the correct SYSOUT class and an internal reader. Then your program writes the JCL statements to the queue and then closes it. Note the job will not be submitted until the queue is closed. You will also need to use serialization techniques to prevent concurrent tasks from interleaving their JCL as they write.
The advantage of the spool commands is each task gets its own file so you don't have to worry about interleaving the JCL from two tasks. You also avoid closing and re-opening the TDQ each time.
Either way you choose you should be careful to arrange things so the batch jobs get proper security credentials. Certain attributes (e.g. inheritance) might give the batch jobs the same access authority as CICS, which could be bad depending on how much you trust your programmers. You must always be sure to put a slash-star card ("/*") at the end of the job so it will be automatically submitted.
This was first published in September 2007