Troubleshooting
Problem
This document provides an example of using a choice exit program to generate a dynamic choice list for CL command parameters at runtime.
Resolving The Problem
When CL command parameters are prompted (typically with F4 function key), the choice list is generally static; the choice list is predetermined when the command object is compiled. A choice exit program can be used to generate a dynamic choice list at runtime. This document provides an example of a choice exit program. The following is a pertinent excerpt from Chapter 9 of the IBM eServer iSeries CL Programming Version 5 manual (document number SC41-5721-05):
Possible Choices and Values The prompter will display possible choices for parameters to the right of the input field on the prompt displays. The text to be displayed can be created automatically, specified in the command definition source, or created dynamically by an exit program. Text describing possible choices can be defined for any PARM, ELEM, or QUAL statement, but because of limitations in the display format, the text is displayed only for values with a field length of 12 or less, 10 or less for all but the first qualifier in a group. The text for possible choices is defined by the CHOICE parameter. The default for this parameter is *VALUES, which indicates that the text is to be created automatically from the values specified for the TYPE, RANGE, VALUES, SPCVAL, and SNGVAL keywords. The text is limited to 30 characters; if there are more values than can fit in this size, an ellipsis (...) is added to the end of the text to indicate that it is incomplete. You can specify that no possible choices should be displayed (*NONE), or you can specify either a text string to be displayed or the ID of a text message which is retrieved from the message file specified in the PMTFILE parameter of the CRTCMD command. You can also specify that an exit program to run during prompting to provide the possible choices text. This could be done if, for example, you want to show the user a list of objects that currently exist on the system. The same exit program can be used to provide the list of permissible values shown on the Specify Value for Parameter display. To specify an exit program, specify *PGM for the CHOICE parameter, and the qualified name of the exit program in the CHOICEPGM parameter on the PARM, ELEM, or QUAL statement. The exit program must accept the following two parameters: o Parameter 1: A 21-byte field that is passed by the prompter to the choice program, and contains the following:
|
The value passed to the program depends upon the actions the user takes with the command:
1 | When the user types the command on the command line and presses F4 to prompt, the exit program is called with a 'C' in byte 21 of the first program parameter. The program must be coded to handle this parameter value; in the simplest case, the 'C' value can be trivially handled by returning to the command with no action taken. |
2 | After Step 1, the parameters of the command will show on the screen. If the user types ? followed by pressing the Enter or F4 key on the dynamic choice parameter, the choice exit program will run with a 'P' in byte 21 of the first program parameter. This indicates that the program should generate a list of current choices. |

[{"Type":"MASTER","Line of Business":{"code":"LOB57","label":"Power"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG60","label":"IBM i"},"Platform":[{"code":"PF012","label":"IBM i"}],"Version":"7.1.0"}]
Historical Number
24643608
Was this topic helpful?
Document Information
Modified date:
18 December 2019
UID
nas8N1017220
Manage My Notification Subscriptions