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 some small 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.
All executable code must be in a function. The only types of logic allowed outside of a function are variable declarations, object declarations, and class definitions (CASE, DECLARE, DESCRIBE, END, MAINTAIN, and MODULE statements).
Some functions have arguments, meaning when you invoke the function, you must supply information that the function needs to complete its task.
Some functions also have a return value, meaning they calculate a value and return this value to whatever called the function. Functions that are event handlers (that is, that are invoked by some action in a form) cannot have return values.
Notice that local variables (defined in a function using the DECLARE command) are available only within that function. As soon as the function completes processing, these values are no longer available. Global variables (defined using the DECLARE command outside of a function or using the COMPUTE command anywhere) are available for the entire procedure. For more information on local and global variables, see the Maintain Language Reference manual.
You can also call one function from within another function.
The combination of the arguments and return value of a function is known as its signature.
or
Click the New function button on the Maintain Objects toolbar.
WebFOCUS Maintain opens the procedure containing your function in the Procedure Editor at the code for the function.
Note: The following Maintain language commands are not valid within the context of a function: CASE, ENDCASE, MAINTAIN, END, MODULE, and DESCRIBE.
Tip: You can add Maintain language code to your function using the Language Wizard. Place your insertion point where you want your code to go, right-click in the Procedure Editor window, and in the shortcut menu, click Language Wizard.
You can obtain Help on any Maintain language keyword by selecting the keyword and pressing F1 key.
For more information, see the Maintain Language Reference manual.
Tip: You can add Maintain language code to your function using the Language Wizard. Place your insertion point where you want your code to go, right-click in the Procedure Editor window, and in the shortcut menu, click Language Wizard.
You can obtain Help on any Maintain language keyword by selecting the keyword or placing your insertion point in the keyword and pressing F1 key.
When you create or edit a function, WebFOCUS Maintain opens the New Function, Edit Function, or Member Function dialog box, as shown in the following image.
This dialog box includes the following options:
The name you assign to your 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 (_).
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 edit an existing argument, double-click its name. You can also edit an existing argument directly by clicking it twice or pressing F2.
To create a new argument, double-click the gray rectangle.
Note: Not all functions require arguments. You cannot use a function with arguments as an event handler.
Opens the Function Parameter dialog box where you can define a new argument.
Deletes a selected argument from the list of arguments.
Moves a selected argument up in the list of arguments.
Moves a selected argument down in the list of arguments.
Contains the name and data type of the return value that the function calculates. You can type this in, if you wish.
Opens the Function Return dialog box, where you can define the return value.
When you click the Description tab in the New Function or Edit Function dialog box, WebFOCUS Maintain opens a dialog box where you can enter a description for your function, as shown in the following image.
You can view the description of a function in the Project Explorer with the Show description command. For more information, see How to View the Description of a Procedure Component.
Suppose you create a project that enables end users to update a list of fan club members. Part of this project is a form where end users can enter information for a new fan club member and then insert this information into the data source. This example demonstrates how you create a function that updates the data source and how you trigger it from the form.
Your new function appears in the list of components of the procedure.
WebFOCUS Maintain opens the source code for your function in the Procedure Editor.
For all include Fannames.CUSTOMER.SSN from AddFanStack ; Stack clear AddFanStack ;
Tip: You can use the Language Wizard to enter this code instead of typing it. Place your insertion point between Case AddFan and EndCase, right-click in the Procedure Editor window, and in the shortcut menu, click Language Wizard.
The Events dialog box looks similar to the following example:
When you execute the project, clicking Add executes the function AddFan.
WebFOCUS |