The Power of the Question Mark in CL Programs and Menus

Article ID: 57020

In previous issues of the newsletter, I have relayed that you can use a question mark to prompt a command, just as if you pressed F4=Prompt. However, sometimes you want to control both the prompt fields that are shown and also those that are input-capable or changeable by the user. When writing CL programs or menus for operations or tech support personnel, the selective prompting capability of CL allows you to be in control of the CL command parameters.

In order to control the CL command prompter, you can use special prompting characters ??, ?*, and ?-. Each has a different effect. Let's examine how they affect the prompts that are displayed to the user.

Consider the following reference chart, which shows examples of the prompt characters and their effects. Try it out--it's cool!

Prompt Used            Value Displayed             Input Allowed
-----------------      ---------------------       ------------- 
??KEYWORD()            Default                     Yes
??KEYWORD(Value)       Value                       Yes
?*KEYWORD()            Default                     No
?*KEYWORD(Value)       Value                       No
?-KEYWORD()            Parameter not displayed     No
                       (Default used)
?-KEYWORD(Value)       Parameter not displayed     No
                       (Value used)

Consider this example:

DSPLIB  ??LIB() ?*OUTPUT(*PRINT)

This example prompts for the DSPLIB (Display Library) command. Notice that the command itself is not preceded by a question mark. When selective prompting characters are used within a command, the command itself need not be preceded by a question mark. However, if the command is not preceded by a question mark, the only fields displayed on the command prompt are those that are specified.

This can be an effective way to reduce the number of parameters that are shown on some commands with many parameters. In this example, only the LIB and OUTPUT parameters will be shown on the prompt. The LIB keyword is preceded by the characters ??. This is the selective prompting designation that causes the command parameter LIB to be displayed on the prompt. The ?? characters also specify that the parameter can be modified by the interactive user (i.e., the field will be input-capable). No value is specified for the library parameter, so the user will not see a value initially displayed in the prompt.

The next parameter is the OUTPUT parameter. It is preceded by the selective prompting characters ?*. These characters specify that the parameter and its value (*PRINT) will be displayed on the prompt, but that the user can't change the value (i.e., the field is not input-capable).

Let's look at another example:

? DSPLIB  ??LIB(APLIB) ?-OUTPUT(*PRINT)

In this example, the command is preceded by a single question mark. This indicates that all parameters can be shown to the user. The value APLIB is specified in the LIB parameter, and because ?? is used, the value of APLIB will be shown to the user and may be changed. The ?- preceding the OUTPUT keyword specifies that the output will be directed to *PRINT, but that the parameter will not be shown to the user and is unchangeable.

When you use the ?- characters, a rule comes into play that prevents the parameter from being shown on the prompt display: The command itself must be preceded by a question mark whenever ?- is used. Notice also that the question mark and the command itself are separated by a few blanks; this is acceptable. The question mark and the command may have any number of intervening blanks.

When working with selective prompting, you must adhere to a few rules:

    A command parameter must be presented in keyword notation when selective prompting for that parameter is requested.

    Blanks can't appear between the selective prompting characters (??, ?*, ?-) and the parameter keyword.

    Any parameter value specified by the prompt or supplied by the user will be used in the execution of the command. If a value is not specified on the prompt or by the user, the parameter default value will be used if one exists.

    If a CL program variable is used as a command parameter value that is changeable by the user, a change to the prompt does not change the value of the program variable. But the command will be executed with the changed value supplied by the user and not with the value stored in the variable. If the user does not change the command parameter value, the value of the program variable will be used in the execution of the command.

Finally, if using selective prompting when using a variable on a call to QCMDCHK, the command will be prompted and the variable updated according to the values entered by the workstation user as in the following example:

CHGVAR  &COMMAND  '? DSPLIB ??LIB()  ?-OUTPUT(*PRINT)'
CALL QCMDCHK   (&COMMAND  &LENGTH)

If F3 and F12 were not pressed, &COMMAND now contains the completed command as entered by the user. It is then fit to be used in a call to QCMDEXC or submitted to batch using the SBMJOB command.

Editor's Note: This article is an adaptation of material that appears in "Control Language Programming for the AS/400," which I co-authored with Bryan Meyers. If you're interested, you can order a copy of this book here.

ProVIP Sponsors

ProVIP Sponsors