Calling a Procedure From the Current One

How to:

The Execute Wizard and the Include component enable you to call another procedure from the current one.

The Execute component allows one procedure to execute or call another procedure. The redesigned Execute Wizard allows you to view and select available procedures and supply values for parameters in the called procedure and also test that called procedure. The called procedure behaves as a completely separate procedure, with its own context.

Execute Wizard allows you to select the procedure for which you are supplying parameter values. Once this procedure is specified, Execute Wizard displays these parameters and prompts you to provide values for them. You can provide values for all parameters in the procedure, or can choose to provide values for only some of the parameters. If you provide values for only some of the parameters, you must provide values for the other parameters using another method. (For example, values are passed from another part of the application.) After providing parameter values, you can test the called procedure.

The Execute Wizard is available throughout all development areas of the product: Projects, Data Servers, and Managed Reporting. When working in Managed Reporting, the tool allows developers to use reports in the repository folder or to use procedures that reside on the WebFOCUS Reporting Server.

Execute Wizard uses the WFDESCRIBE auto-prompting feature to locate and pass parameters. To activate the WFDESCRIBE feature, change the default value in the IBIF_wfdescribe setting in the cgivars.wfs file.

The Include component allows one procedure to run another procedure as if the second one were embedded in the first. In this case, the procedure being included (called) has full access to variables defined in the calling procedure. Using this tool, you can create an object that includes another procedure within a host procedure. There is no limit to the number of procedures that can be included.


Top of page

x
Procedure: How to Call a Procedure With the Include Component
  1. Open the host procedure.
  2. Click a component connector at the point at which you wish to include the existing procedure.

    The Component Connector toolbox opens.

  3. Click the Include button on the toolbox.

    The Open dialog box opens.

  4. Select the procedure you wish to embed from the list, or type the name of a new procedure in the File Name field.
  5. Click Open.

Tip: The Include component inserts the -INCLUDE command into the procedure code.


Top of page

x
Procedure: How to Execute a Procedure With the Execute Wizard
  1. Click the component connector at the point at which you wish to include the existing procedure.

    The Component Connector toolbox opens.

  2. Click the Execute button.

    The Execute Procedure Wizard opens, as shown in the following image.

  3. Select the procedure you want to execute from the list of available procedures, and click Next. The Execute Procedure Wizard - Enter Procedure Parameters window opens, as shown in the following image.

    Execute Procedure Wizard diagram

    The Enter Procedure Parameters window contains a list of variables contained in the procedure you are executing, and fields in which to enter values for those variables. This screen will not appear if the procedure you are calling does not have parameters.

  4. Enter the variable values you wish to use in the procedure you are executing. If you do not wish to provide a value for a variable, clear the Optional check box next to the variable name.
  5. Click Next.

    The Execute Procedure Wizard - Summary window opens, as shown in the following image. This window allows you to view the name of the procedure you are calling and view the variables-value pairs.

    Execute Procedure Wizard diagram

  6. Click Test Procedure to ensure that the procedure runs properly. If the procedure works properly, a report will display in your browser.
  7. Click Finish to insert the selected procedure into the current procedure.

Tip: The Execute component inserts the EX command in the procedure code. Hover over the Execute object to see the EX command. If you wish to run the embedded procedure, right-click the Execute object and choose Run from the shortcut menu.



Example: Calling a Procedure From Another Procedure

In the following example, you will create two procedures. One procedure, named SALESREP, will contain a sales report with variables. The second procedure, called SVALUES, will contain the values for the variables in SALESREP, and will execute SALESREP. The result will be a sales report with variable values filled in.

Create the SALESREP procedure:

  1. Create a new procedure named SALESREP.
  2. From the Create with drop-down list, select Procedure Viewer. The Procedure Viewer opens.
  3. Click on the Component Connector, and select Report. Select the SALES Master File and press Open. Report Painter opens.
  4. Create a Variable field by right-clicking inside the Fields tab of the Object Inspector and selecting New Report Variable Field.
    1. Enter CITY in the Name input field.
    2. From the Accept List area, select the Static list radio button.
    3. From the Variable Type drop-down list, select the Single Select option.
    4. In the Data Context area, select Values for field.
    5. Click the Select a field ellipsis to get the Value Retrieval dialog box.
    6. Select the field CITY and then click Get Data.
    7. Double-click the returned values to add them all to the Accept List.
    8. Click OK to close the Variable Editor.
    9. The new variable is visible in the Object Inspector by expanding the Variables folder and then the Report Variables.
  5. Insert a Report Heading and type Monthly Report for and add Report Variable &CITY by dragging it from the Object Inspector. When prompted to insert a variable as a field to be evaluated or as a literal value (default option), select the default option of Insert as literal value.
  6. Add the UNIT_SOLD and RETURNS fields to your report, then select both fields in the layout and click the Sum button in the toolbar.
  7. Create the RATIO field by doing the following:
    1. Select Computes from the Report menu. The Report Options window opens.
    2. Enter RATIO in the Field input box.
    3. Enter D5.2 in the Format input box.
    4. Enter 100 * (RETURNS/UNIT_SOLD) in the Expressions window.
    5. Click OK.
  8. Add the PROD_CODE field to your report, and click By.
  9. Filter the PROD_CODE field by doing the following:
    1. Select the Where/If tab at the bottom of the Object Inspector.
    2. Right-click the WHERE Conditions folder and select Where. The Expression Builder opens.
    3. Double-click PROD_CODE. PROD_CODE appears in the Column to filter field.
    4. Select is from from the Logical Relation drop-down menu.
    5. Double-click the Compare Value field. The Range Builder opens.
    6. Enter &CODE1 in the From field and &CODE2 in the To field.
    7. Click OK.
  10. Add the CITY field to your report, and click By.
  11. Filter by the CITY field by doing the following:
    1. Select the Where/If tab at the bottom of the Object Inspector.
    2. Right-click the WHERE Conditions folder and select Where. The Expression Builder opens.
    3. Double-click CITY. CITY appears in the Column to filter field.
    4. Select equals from the Logical Relation drop-down menu.
    5. Select Parameter from the Compare Type drop-down menu.
    6. Double-click the Compare Value field. The Variable Editor opens.
    7. Click OK. &CITY is entered in the Compare Value field.
    8. Click OK.
  12. Save and close the procedure.

Create the SVALUES procedure:

  1. Create a new procedure named SVALUES and from the Create with drop-down list, select Procedure Viewer. The Procedure Viewer opens.
  2. Click a component connector, and select Execute. The Execute Wizard opens.
  3. Select SALESREP from the list of procedures, and click Next.

    The Enter Procedure Parameters window opens, as shown in the following image.

    Execute Procedure Wizard diagram

  4. Select STAMFORD from the Value drop-down menu for CITY.
  5. Enter B10 in the Value field for CODE1.
  6. Enter B20 in the Value field for CODE2.
  7. Click Next.

    The Summary window opens, as shown in the following image.

    Execute Procedure Wizard/Summary diagram

  8. Click Finish. You return to the Component Connector toolbox.
  9. Close and save the procedure.

When the SVALUES procedure is run, the following report appears.

monthly report


WebFOCUS