Prompt and Submit CL Commands
May 19, 2010 Ted Holt
I am a blessed man. Among the niceties of life that I enjoy are hot and cold running water, central heat and air conditioning, abundant food, and the CL command prompter. Many people are not so fortunate.
The CL command prompter provides a functional way to pass properly formatted data to a program so the program can do what it was made to do. Developers who work on other systems can only dream of such a facility.
To prompt a command from a CL command line is simple: type the command name and press F4. I doubt this is news to readers of this august publication. (An alternate method is to type a question mark before the command and press Enter. I never use it.)
You can also prompt a CL command from a menu or from a program that is running interactively. Just put a question mark before the command name. Here the Display Object Description (DSPOBJD) command is prompted.
You can restrict the permissible data entry by prefixing parameter keywords with certain two-character codes. In the following example, Display Object Description is again prompted, but this time, the OUTPUT parameter is loaded with a value of *PRINT and the user cannot change this value.
? DSPOBJD ?*OUTPUT(*PRINT)
If you use CL prompting in a program, be sure to monitor for message CPF6801–Command prompting ended when user pressed &1. The system sends this message to the program if the operation presses F3 or F12 to cancel the command prompt. The &1 substitution parameter tells you which of the two function keys the user pressed.
If the user presses Enter or F16, the command begins to run–interactively. If the command runs quickly to completion, running interactively is no big deal. But if the prompt must run for an extended time, it really should be submitted to a job queue so that it will run in batch mode. Fortunately, it is not difficult to submit a prompted CL command to batch. Use the Process Commands API, QCAPCMD, to prompt and create a command string, and the Submit Job (SBMJOB) command to run the command string in batch.
pgm dcl &Cmd *char 1024 dcl &CmdLen *int 4 value(1024) dcl &Options *char 20 dcl &OptionsLen *int 4 value(20) dcl &Options *char 20 dcl &NewCmd *char 1024 dcl &NewCmdLenA *int 4 value(1024) dcl &NewCmdLenC *int 4 value(1024) chgvar %sst(&Options 1 4) value(x'00000001') chgvar %sst(&Options 5 1) value('0') chgvar %sst(&Options 6 1) value('1') chgvar %sst(&Options 7 1) value('0') chgvar %sst(&Options 12 4) value(x'00000000') chgvar %sst(&Options 16 5) value(x'0000000000') chgvar &Cmd value('DSPOBJD') call qcapcmd parm(&Cmd &CmdLen &Options &OptionsLen + 'CPOP0100' &NewCmd &NewCmdLenA &NewCmdLenC + x'00000000') monmsg cpf6801 exec(return) sbmjob job(ted) rqsdta(&NewCmd) jobq(nomax) endpgm
In this example, the command to be prompted, DSPOBJD, is loaded into &Cmd. QCAPCMD prompts the command, the user fills in the blanks, and the revised command comes back in &NewCmd, which is then sent to batch through the Request Data (RQSDTA) parameter.
One nice thing about this technique is that it eliminates the need to write display files solely for the purpose of collecting data before submitting to batch. Also, while I’ve used one of IBM’s commands as an example, I have found this technique much more useful with commands of my own, especially commands that run application programs.