|
Prompting for Variables
Dialogue Manager (DM) is the FOCUS facility for creating and executing stored procedures, which we call FOCEXECs. It allows application developers great flexibility in structuring the processing sequence within a system, as well as a means for end users to communicate when operating a procedure to supply values for runtime variables and query and direct the processing by viewing intermediate results and controlling the flow throughout its execution. These capabilities are spelled out in the Developing Applications manual (see Chapter 3, "Managing an Application With Dialogue Manager").
In this brief introduction to DM, keep in mind that this functionality is available only within FOCEXECs; you cannot type DM commands in the interactive FOCUS environment. One major concept in Dialogue Manager is variable substitution, by which users supply values for variable parameters in the procedures they are running.
If we consider a monthly sales report, for example, you would need to indicate the period covered and select the products to be summarized at run time. In Dialogue Manager you represent variable fields by prefacing the field names with an ampersand (&). Thus, in FOCUS lingo we call these "amper-variables," or simply "&vars."
Values for &vars may be defaulted, set statically, or the person running the FOCEXEC may be prompted for a value by FOCUS at runtime. In this article I will show how easy it is to prompt for a variable’s setting and to design and set an &var.
Here is a simple report request that includes an unknown &var:
TABLE FILE CAR
PRINT MODEL
BY CAR
BY COUNTRY
IF COUNTRY EQ '&COUNTRY'
END
-RUN |
If you run this FOCEXEC you receive the following prompt:
PLEASE SUPPLY VALUES REQUESTED
COUNTRY= |
FOCUS then waits until you input a value. Once you enter a value, FOCUS continues processing the remainder of the request, and then provides the output.
We can further refine this process by adding a PROMPT command. Here is an example:
-PROMPT &CARNAME.WHICH CAR DO YOU WANT?.
TABLE FILE CAR
PRINT SEG.MODEL
BY CAR
IF CAR EQ '&CARNAME'
END |
Now, when you run this request you see the following prompt on the screen and FOCUS awaits your response:
This seems much more user friendly.
You do not have to use PROMPT to ask a question for your &var. You could instead insert the text of the prompt with the &var where it appears. Example:
-* PRMPTVAR FOCEXEC
TABLE FILE CAR
PRINT MODEL
BY CAR
BY COUNTRY
&IFTEST.WHAT SELECTION CRITERIA DO YOU WANT?.
END
-RUN |
If you run this FOCEXEC by typing EX PRMPTVAR you will get the following prompt:
WHAT SELECTION CRITERIA DO YOU WANT? |
However, if you type EX PRMPTVAR IFTEST=’IF COUNTRY EQ ENGLAND’ you will get your report without being prompted. Try it out!
As you can see, -PROMPT is a powerful tool. Take a look at the documentation for other ideas on what you can do with it.
|