Using Functions in Procedures

How to:

Reference:

A function, also known as a case, is a series of commands in a procedure grouped together as a unit of control. A function accomplishes a task, such as calculating values, extracting data from a data source to place in a data source stack, or writing information to a data source. You can also call one function from within another function.

Procedure: How to Create a Function

  1. Select the procedure you would like the new function to be part of.
  2. Right-click the procedure and click New function in the shortcut menu.
  3. In the New Function dialog box, type a name for your function in the Name field (up to 66 characters with no spaces).
  4. Use the New button to open the Function Parameter dialog box to add any arguments (not all functions require arguments).
  5. Use the Returns field to enter the name and format of a return value (not all functions require return values). You can also click the ellipsis button to open the Function Return dialog box. This is where you can define the function.
  6. Click the Description tab, type a description, and click OK. (Optional)
  7. Right-click the function and select Edit Source from the shortcut menu.
    The Maintain Data Editor opens the procedure containing your function in the code for the function.
  8. Locate your cursor just before the ENDCASE keyword and enter the Maintain Data language commands that determine what this function does.

    Note: The following Maintain Data language commands are not valid within the context of a function: CASE, ENDCASE, MAINTAIN, END, MODULE, and DESCRIBE.

    Tip: You can add Maintain Data language code to your function using the Language Wizard. Place your insertion point where you want your code to go, right-click in the Maintain Data Editor window and select Language Wizard in the shortcut menu.

Procedure: How to Edit a Function

  1. Right-click the function in the Requests & Data Sources panel.
  2. Click Edit Source in the shortcut menu.
  3. Make your desired changes between the CASE funtionname and ENDCASE keywords.

    Tip: You can add Maintain Data language code to your function using the Language Wizard. Place your insertion point where you want your code to go, right-click in the Maintain Data Editor window and select Language Wizard in the shortcut menu.

Procedure: How to Edit the Name, Arguments, Return Value, and Description of a Function

  1. Right-click the function in the Requests & Data Sources panel.
  2. Click Edit in the shortcut menu.
  3. Make your changes in the Edit Function dialog box and click OK.

Reference: Function Editor: Signature Tab

When you create or edit a function, WebFOCUS App Studio Maintain Data opens the New Function, Edit Function, or Member Function dialog box, as shown in the following image.
Maintain Edit Function Dialog Box

This dialog box contains the following options:

Name

The name you assign to your function (or case). This name can be up to 66 characters long. It must begin with a letter and can include any combination of letters, digits, and underscores (_).

Takes: (Name/Type)

Lists the arguments that the function requires. When you invoke the function, you pass to it variable names or values to substitute for these arguments.

  • To create a new argument, double-click the gray rectangle or click the plus sign to the right of the field.
  • To edit an existing argument, double-click its name.
  • To change the order of the arguments, select the argument to be moved and use the arrows to move it up or down.
  • To delete an argument, select it and click the red X to the right of the field.

Note: Not all functions require arguments. You cannot use a function with arguments as an event handler.

Returns: (Name/Type)

Contains the name and data type of the return value that the function calculates. This information can be entered directly in the field, or you can use the ellipsis button to open the Function Return dialog box to enter it.