If you know that certain programs are very I/O intensive or process intensive, or you want them always to be submitted as a batch job for any other reason, you can achieve this from a single CL program, i.e. without writing another program to submit the program.
Assume that you need to call some programs, run some queries, etc. to achieve a certain objective. You usually group them all in one CL program (SUBMIT_PGM, for e.g.) and write another CL program just to submit this, if you always want this program to run in batch, from a menu option in an application.
The trick is to add the following code in the initial processing section of the CL program.
where &JOB_TYPE is a *CHAR variable of 1 byte length.
If the value of &JOB_TYPE is '1', which means the program is called interactively, the following code is added to submit the call of the same program (SUBMIT_PGM) in batch.
SBMJOB CMD(CALL PGM(SUBMIT_PGM)) GOTO END_PGM
where END_PGM is the label of the ENDPGM statement.
The main processing section of the program is added after the SBMJOB command.
The advantages of this method are twofold. First, the program saves you from writing another program to submit it. The second one, the more important one, is it prevents anyone from running the program interactively, either accidentally or deliberately.
PGM DCL VAR(&JOB_TYPE) TYPE(*CHAR) LEN(1) RTVJOBA TYPE(&JOB_TYPE) IF COND(&JOB_TYPE = '1') THEN(DO) SBMJOB CMD(CALL PGM(SUBMIT_PGM)) GOTO END_PGM ENDDO CALL PGM(CALLED_PGM) RUNQRY QRY(QUERY_RUN) . . . . . . . . END_PGM: ENDPGM