Intelligent Prompting
by Stephen West


One nice feature unique to the IBM i is intelligent prompting, or prompt control.  This feature lets you control which parameters you want displayed for user-written commands.

The IBM i provides three forms of intelligent prompting.  The first, and easiest to implement, lets you flag parameters so that they do not display unless you press F10.  This feature is useful when a parameter's default value is usually acceptable.  The CL CPYF (Copy File) command uses this form of prompt control.

This first form is easily implemented in your own commands.  For the parameters you want to control, simply add the Prompt Control keyword with the Prompt Request value - PMTCTL(*PMTRQS) - to the corresponding PARM statements in you command deinition source.  Figure 1 shows a definition for a command that invokes a program to create a file display program.  The PARM statement at B contains PMTCTL(*PMTRQS) for the DATETIME parameter.  Therefore, this parameter's prompt will not display unless you press F10.

The second form of intelligent prompting lets you condition the display of some parameters on the values entered for parameters already displayed.  When you enter a specified value for a parameter, other parameters that depend on that value are then displayed.  Most of the CRTLINxxxx (Create Line Description) commands use this form of prompting.  This feature lets you ignore parameters that aren't relevant to the task you are performing.  You can simply begin the command, and the pertinent parameters present themselves according to your input.

Implementing this second form of intelligent prompting in your own commands requires a little more thought than you put into the first form.  You must first decide which parameters you want displayed for each particular condition.  To these parameters' PARM statements, you add the PMTCTL keyword with a label name as the value (e.g. C in Figure 1).  The label you specify identifies a condition or a group of conditions necessary to display the parameter.  You specify these conditions with a PMTCTL command definition statement (E) - not to be confused with the PMTCTL keyword that you used in the PARM statements.  Each condition requires at least one PMTCTL statement, but you can link multiple conditions with the LGLREL (Logical Relationship) keyword and *AND or *OR values (E).  The *AND operator has the higher precedence.

A parameter on which you base a condition is the controlling parameter.  You must specify a controlling parameter on each PMTCTL statement.  In a group of conditions indicated by a label, however, this parameter does not have to be the same for each condition.

The third form of prompt control lets you use an exit program to perform additional functions on the value for the controlling parameter before the command processor decides whether to display an additional parameter.  For example, when you create an object, you can use an exit program to check whether an object by that name already exists.  The exit program returns a parameter, and your command can then decide whether to display a prompt such as "Replace Existing Object?"

Implementing the third form of prompt control requires still more thought.  Remember that the exit program processes the value of the controlling parameter, not the conditioned parameter.  The PMTCTL statements use the value that the exit program returns (not the actual value of the controlling parameter) to perform a comparison.  You specify the exit program by placing the PMTCTLPGM keyword and the name of the exit program in the controlling parameter statement (A in Figure 1).

You must code the exit program according to a predefined set of standards.  The program must have exactly three parameters.  The first parameter is a 20-character field that contains the name of the command in positions 1 through 10 and the name of the controlling parameter in positions 11 through 20.  The exit program should not change this parameter's value.

The second parameter must have the same attributes and value as the controlling parameter.  The exit program should not change this parameter's value, either.  Finally, you must have a 32-character parameter for the value the exit program returns to the command.

In Figure 1, the command parameter defined at A references program CHKPGMEXS (Figure 2).  This program checks for an object with a name that matches the value entered for the parameter and returns the value *EXISTS if the object exists and * when it does not.  Display of the REPLEXSPGM parameter defined at D in Figure 1 depends on the value the exit program returns.

The three forms of intelligent prompting make the IBM i more programmer-friendly than it's predecessors.  The result is commands that are faster to use and less confusing than they would be without this feature.




© 2007 Workware, Inc. All rights reserved.