Progress
Report Builder
User’s Guide
Creating User-defined Functions
Follow these steps to create a user-defined function:
- Choose Calculations
User Defined Function. If there are UDFs defined, a User Defined Functions dialog box appears:
![]()
If there are no UDFs defined, the New User Defined Function dialog box appears, and you should proceed to Step 3.
- Choose New to create a new UDF. The New User Defined Function dialog box appears:
![]()
- Specify the function name in the User Defined Function Name fill-in field. Function names follow the same rules as 4GL field names. They can be up to 32 characters long and can consist of alphabetic characters (A-Z or a-z), digits (0-9), and special characters ($, &, #, %, -, and _). In addition, function names must begin with a letter (A-Z or a-z) and cannot contain spaces. When naming a UDF, you can use lowercase or mixed case or a particular set of characters (for example “u” or “UDF”) to distinguish its name from the names of built-in Report Builder functions.
- Choose the New button to create the parameters you need for the expression. The New Parameter dialog box appears:
![]()
- Specify the parameter name in the Parameter Name fill-in field. Parameter names follow the same rules as 4GL field names.
- Specify the parameter type in the Parameter Type combo box. The default type is Character.
- For character parameters, activate the Case Sensitive toggle box if you want the parameter to be case sensitive.
- Choose OK to return to the New User Defined Function dialog box.
- Enter the expression in the Expression fill-in field. UDF expressions can contain built-in functions, operators, parameters, constants, and other UDFs. You can either type these elements or select them from the selection lists and Operator Palette. You must enter spaces around each operator of the expression. See the following section for more information about using the selection lists and buttons.
You can format the expression by pressing CTRL-TAB to indent and CTRL-RETURN to start a new line.
- Choose Verify to check the expression syntax. If there is an error in the expression (for example, if you used an unrecognized operator), Report Builder displays an error message. When possible, it also positions the cursor to the place in the expression where the error occurred.
Edit the existing expression. When the expression is complete and correct, choose OK.
NOTE: When you choose OK, Report Builder verifies the expression.- Choose OK to create the function and return to the User Defined Functions dialog box.
- Choose Close to return to the report layout.
Using the Selection Lists and Buttons
The easiest way to create an expression is to select the element from the Parameters and Functions selection list, the Operators palette, and the selection lists that display when you choose the Calc Expression or UDF Expression buttons. Because this technique reduces the amount of typing required, you can build expressions more quickly and accurately.
Table 7–1 explains how to perform basic tasks using these techniques.
Table 7–1: Using the User Interface Elements to Create an Expression
Task Description Selecting parameters Double-click a field, or select it from the Fields selection list, then choose Insert. The selection list displays the currently defined parameters. Selecting functions Double-click a function, or select it from the Functions selection list, then choose Insert. The Functions selection list displays the built-in Report Builder functions, as well as any user-defined functions you have created. Pasting function arguments Double-click a field name, or select it from the Fields selection list, then choose Insert.
If the Paste Arguments toggle box is activated when you insert a built-in function in the expression, Report Builder automatically highlights the symbols representing the function’s first argument. These symbols usually indicate the argument’s data type.
For example, if you select the SUBSTRING function and insert it into the field expression, this is how it appears:SUBSTRING( char , num , optnum )
In this example, the symbols in parentheses represent the arguments to SUBSTRING: “char” represents a required character argument; “num” a required numeric argument; and “opt num” an optional numeric argument.
If you select a character field as the first argument, the field name replaces “char” in the expression. You can then supply the other function arguments as needed.
The Paste Arguments toggle box is activated by default. If you deactivate it, Report Builder inserts function names without supplying argument symbols. Instead, it inserts the function name followed by a set of parentheses — for example, SUBSTRING( ). Selecting operators Activate the Operator Palette toggle box to display the available operators, then select the appropriate operator. See "Calculated Fields,"for explanations of these operators and descriptions of their use in expressions.
Report Builder automatically inserts the required spaces around the operator when you choose the button. Copying calculated expressions Choose the Calc Expression button. The Calculated Fields dialog box appears. Select a calculated field and choose OK. Report Builder inserts the expression of the selected field into the new UDF’s expression.
When you select a calculated field in the Calculated Fields dialog box, Report Builder displays the field’s expression in the bottom section of the dialog box. Copying a UDF expression Choose the UDF Expression button. The User Defined Functions dialog box appears. Select a UDF expression, then choose OK. Report Builder inserts the expression of the selected field into the new UDF’s expression. This allows you to simply modify an existing expression rather than starting from scratch.
When you use a UDF in a calculated field expression, you must supply the required parameters that you declared when you created the UDF. For example, if the UDF declaration specifies one date parameter, when you include the UDF reference in a calculated field, you specify one date field as a parameter to the UDF.
When you copy a calculated field expression into a UDF, you must either remove any field references or replace them with parameter references. When you copy a UDF expression, you must change any parameter references to use the parameters defined for this UDF.
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |