Prompt sets are the usual way of defining ahead of time a set of inputs for which the user will be prompted; but there is no straightforward way to choose at runtime which prompt set object to use. In some situations, it is useful to be able generate an input dialog box dynamically, based on pieces of information that are not known prior to execution.
I developed an approach that can be used to address this need. Here is an example prompt set with an assortment of various element types.
Figure 1. An example prompt set
The script that processes this prompt set looks like this:
UC0.GENERATE_INPUT_DIALOG.SCRI
:SET &PromptSet_Name# = "UC0.PROMPT_SET-TEST.PRPT"
:INC UC0.GENERATE_INPUT_DIALOG.JOBI
:INC UC0.PRINT_VARIABLES.JOBI
The include object UC0.GENERATE_INPUT_DIALOG.JOBI does all the work. Behind the scenes, it uses a couple of SEC_SQLI objects to read the details of the prompt set:
- UC0.GET_PRPT_CAPTION.VARA_SEC_SQLI reads the window title of the prompt set.
- UC0.GET_PRPT_ELEMENT_DETAILS.VARA_SEC_SQLI reads the details of the prompt set elements.
(It was necessary to use these VARAs because the :PREP_PROCESS_PROMPTSET command is not able to read all of the details of the prompt set.)
After reading the prompt set details, the JOBI uses these pieces of information to dynamically generate a :BEGINREAD...:ENDREAD block, recreating the prompt set as faithfully as possible.
The dynamically-generated input dialog box looks like this.
Figure 2. A dynamically-generated input dialog box, generated based on the example prompt set in Figure 1. (Multi-select elements displayed as text fields)
Configuration
The :READ command does not support reading a variable via indirect reference — that is, reading in the value of a variable whose name is set at run time. Because of this, you must modify the JOBI before this will work with your prompt sets.
Near the end of the JOBI there is a :SWITCH block containing the actual :READ commands. Note that there is exactly one :CASE clause and one corresponding :READ command for each variable in the demo prompt set. If you have a prompt set with variables called &APP_NAME# and &SEQ_NUM#, then you’ll need to add these four lines to the :SWITCH block:
: CASE "APP_NAME#"
: READ &APP_NAME#, &InputCheck#, &Caption#, &Default#, &InputHandling#
: CASE "SEQ_NUM#"
: READ &SEQ_NUM#, &InputCheck#, &Caption#, &Default#, &InputHandling#
Display of check box elements
The :READ command does not support display of check box elements. The display of such elements (check box groups and and check box lists) can be customized by setting the value of the variable &Display_MultiSelect_Elements_As#.
If &Display_MultiSelect_Elements_As# is set to text., the two check box elements are displayed as text fields, as In Figure 2 above. A label is inserted above such fields, informing the user of the inputs that are accepted. This behavior is the default if no value is specified for &Display_MultiSelect_Elements_As#.
Figure 3. Multi-select elements displayed as text fields
If &Display_MultiSelect_Elements_As# is set to combo, check box and check list elements are displayed as combo boxes.
Figure 4. Multi-select elements displayed as combo boxes
If &Display_MultiSelect_Elements_As# is set to menu, and check box and check list elements are displayed as menus and the user will be able to select only one item.
Figure 5. Multi-select elements displayed as menus
Text elements with multi-select enabled are always displayed as ordinary text fields. A label is inserted before the field, indicating that multiple values may be entered, and mentioning the character that should be used to separate different values.
Figure 6. A multi-select text element
Limitations
There are a few limitations, mostly due to underlying limitations of the :READ command:
- The :READ command does not support reading a variable whose name is set at run time. Because of this, two lines must be added to the JOBI for each variable that might be encountered in a prompt set. See Configuration, above.
- CALE data sources are not supported.
- XML VARA data sources are not supported.
- PREP_PROCESS_VAR_XML retrieves data in all uppercase letters, so fields with an XML VARA data source will also be in all caps.
- The :READ command does not support display of check boxes. Therefore, only one item may be selected for these elements. You can configure how to display these elements. See Display of check box elements, above.
- The :READ command does not support display of locked input fields, so these are displayed as messages.
- The :READ command does not support display of fields with no caption, so these are displayed with the caption “::”.
- The :READ command does not support ranges that include negative numbers. Therefore, such ranges are displayed as menus rather than number pickers.
- The :READ command does not support time, date, and timestamp controls. Therefore, these fields are displayed as text fields.
- The :READ command does not support time, date, and timestamp ranges. Therefore these ranges are explained in text labels.
The objects are attached. This discussion stems from a questionPhillipPetermann607578 recently asked :Rebuild Prompt - Substitution VARA in ":READ - Command".