Thursday, September 20, 2007

Submit a Prompted Command to Batch:

If we put a question mark before a command name in a CL program and run the program interactively, the system prompts the command, allows filling in the blanks, and then executes the command.

Similarly there is a way to prompt the command, and then send it to batch for execution.
For example, here's the type of code we are running interactively.
? SAVOBJ
MONMSG MSGID(CPF6801) EXEC(RETURN)

The system prompts the Save Object (SAVOBJ) command. If the user presses Enter, the system runs the command. However, if the user presses F3 or F12 to cancel the prompt, the Monitor Message command takes over.
If we want the command to run in batch, we need the QCMDCHK API. It is like the QCMDEXC API most of us are very familiar with in that it accepts the same parameters.
Here's an example that prompts a Save Object command and submits it to batch.
DCL VAR(&CMD) TYPE(*CHAR) LEN(1024)
DCL VAR(&CMDLEN) TYPE(*DEC) LEN(15 5) VALUE(1024)

CHGVAR VAR(&CMD) VALUE('?SAVOBJ')
CALL PGM(QCMDCHK) PARM(&CMD &CMDLEN)
MONMSG MSGID(CPF6801) EXEC(RETURN)

SBMJOB RQSDTA(&CMD)
SNDPGMMSG MSG('Your command was submitted to batch.') +
MSGTYPE(*COMP)

The &CMD variable is initialized to a prompted SAVOBJ command. Calling QCMDCHK causes the system to prompt the command and change the value of &CMD as modified by the user from the prompt screen.
After QCMDCHK runs, the Submit Job (SBMJOB) command is used to start a batch job. Notice that the command is passed through the Request Data (RQSDTA) parameter, not the Command (CMD) parameter.

No comments: