User-defined functions

In addition to the system-defined functions, you can define your own functions and use them in calculated fields. The names of user-defined functions intended for use in calculated fields must begin with the letters “RW” to be recognized by the Dexterity and Runtime Report Writers. The “RW” can be uppercase, lowercase or a mixture of cases, and can be followed by any character.

Only user-defined functions with names that begin with the letters “RW” will be displayed when User-Defined is selected in the Functions tab of the Calculated Fields window.


To add a user-defined function to an expression, select the core the function is part of from the Core drop-down list. Once a core is selected, the Function drop-down list will become active. You can then select the desired user-defined function from the Function drop-down list. Click Add to add the function to the expression.

Dexterity automatically adds the selected function to the expression enclosed in parentheses and preceded by the system-defined function FUNCTION_SCRIPT. This system-defined function is used only to process user-defined functions. It is added to the expression by Dexterity, and can’t be added to the expression from the System-Defined Function drop-down list.

Once the user-defined function is added to the expression, add any needed parameters using the fields and constants tabs. Table fields, calculated fields and constants can be used as parameters for a user-defined function included in a calculated field. Be sure the parameters are placed before the closing parenthesis.

Be sure to add the appropriate number and type of parameters for the selected function. Dexterity will not check the compatibility of the specified parameters until runtime. Also note that the function should not have any optional parameters. All parameters must always be supplied to the function.


To use a report field value as parameter for a user-defined function, create a calculated field with that report field as the only element of the calculated expression. Then, use that calculated field as the parameter for the user-defined function in another calculated field.


When a user-defined function in a calculated field is evaluated depends on the parameters that are passed to the function. If no “in” parameters are passed to the user-defined function, the function will be evaluated one time when the report is run. If a table field or value based on a table field is passed as a parameter to the user-defined function, the function will be evaluated each time a new record is read from that table.

Example 1

The following user-defined function is used to retrieve the address of a house, based on the House ID passed to the function.

Function: RW_GetAddress

 

function returns string address;
in string house_ID;

'House ID' of table House_Data = house_ID;
get table House_Data;
if err() = OKAY then
	address = Address of table House_Data;
end if;

The expression for the calculated field that uses this user-defined function is shown in the following illustration. Notice that a field from the House_Data table is passed to the function.

[spacer]

Example 2

The following user-defined function is similar to the UCASE system-defined function, except that it converts the specified value to lower case.

Function: RW_LCASE

 

function returns string lower_case_value;
in string input_string;

{Use the built-in function to convert the string to lower case.}
lower_case_value = lower(input_string);

The expression for a calculated field that uses this function is shown in the following illustration.

[spacer]


Documentation Feedback