Prompt Control Controls Parsimonious Command Prompting
February 22, 2012 Ted Holt
Note: The code accompanying this article is available for download here.
I like everything to be as simple as possible. Call me parsimonious, but I agree with my friend Cletus the Codeslinger, who says, “When something’s complicated, somebody’s trying to get your money.” One way to simplify CL command prompting is to show relevant parameters only. Here’s how that’s done.
By default, prompting a CL command shows all parameters, even though some of them may not be applicable to what the user is trying to accomplish. The Prompt Control Definition (PMTCTL) keyword allows you to prompt for a parameter only if the user needs to supply a value. Rather than overwhelm the user with many parameter entry fields, some of which do not apply, you show parameters only if they need a value.
Consider IBM‘s ANZOBJCVN (Analyze Object Conversion) command, which helps prepare V5R4 systems for a later version of the operating system. If you type the command name and press F4, you’ll see the display shown in Figure 1.
The system wants to know if you’re going to collect data or print a report. If you enter *COLLECT, you’ll see the display in Figure 2.
But if you enter *REPORT, you’ll see the display in Figure 3. Notice the difference in the parameters in Figures 2 and 3. The value of the OPTION parameter determines whether or not other parameters apply.
PMTCTL lets you specify a condition (or conditions) that must apply in order for a parameter to be prompted. Here’s an example:
IFCOLLECT: PMTCTL CTL(OPTION) COND((*EQ *COLLECT))
The condition has a name, IFCOLLECT, which is specified as the label. Condition IFCOLLECT is true if the OPTION parameter is equal to *COLLECT. Any parameter that is controlled by this keyword will be shown in the prompt list only when this condition is true. Here’s how to make the LIB parameter appear in the prompt when IFCOLLECT is true.
PARM KWD(LIB) ... PMTCTL(IFCOLLECT) ...
Here’s a more complete example, using a command I call DOIT:
CMD PROMPT('Do it') PARM KWD(OPTION) TYPE(*CHAR) LEN(8) RSTD(*YES) + VALUES(*COLLECT *REPORT) MIN(1) + EXPR(*YES) PROMPT('Option') PARM KWD(LIB) TYPE(*GENERIC) SPCVAL((*ALLUSR) + (*NONE)) EXPR(*YES) PMTCTL(IFCOLLECT) + PROMPT('Libraries to analyze') PARM KWD(RPTTYPE) TYPE(*CHAR) LEN(7) RSTD(*YES) + SPCVAL((*CVNPRB) (*LIBSUM) (*LIBDTL) + (*OBJSUM) (*OBJDTL)) + SNGVAL((*ALLAVL)) + MIN(0) MAX(5) PMTCTL(IFREPORT) + PROMPT('Type of report') IFCOLLECT: PMTCTL CTL(OPTION) COND((*EQ *COLLECT)) IFREPORT: PMTCTL CTL(OPTION) COND((*EQ *REPORT))
Notice the two PMTCTL statements at the bottom. You don’t have to put them at the end of the command source member, but that’s where I like to put them. IFCOLLECT and IFREPORT are both controlled by the OPTION parameter. LIB will be prompted only when IFCOLLECT is true, and RPTTYPE will only be prompted when IFREPORT is true.
The example I’ve given is simple. You can create more complex conditions by using multiple values on the COND keyword, and by using the NBRTRUE and LGLREL keywords. I’ll let you read about those on your own time. I’ve found that the simple conditions like those in my illustration are almost always sufficient.