Progress
Language Tutorial
for Windows
Using User-defined Functions
When you define a function using the FUNCTION statement, the statement is treated like an internal procedure. The FUNCTION statement can use the resources defined in the main procedure, helping you to simplify the actual statement that you need to code. However, user-defined functions differ from internal procedures because the function can return a value, and the function can be called from within a Progress expression. In addition, user-defined functions have certain restrictions such as you cannot define work tables, temporary tables or shared variables in a user-defined function.
Here’s a partial syntax of the FUNCTION statement.
Table 6–1 describes elements of the partial FUNCTION statement:.
The FUNCTION statement offers you the advantages of defining an internal procedure while also returning a value, a capability supported by a function. A function applies the logic that defines the function to the values that are passed to it, and provides a single return value to the calling procedure (that is, the procedure that contacted it to perform its function).
NOTE: You cannot define temp-tables, work-tables, shared variables, shared frames, shared browses or streams within a user-defined function.To gain a better understanding of the user-defined function, let’s review the code in Figure 6–3.
Figure 6–3: Defining and Using a User-defined Function
![]()
This example shows an extract of a main procedure in which the user-defined function compute is defined and then used, or invoked, in two separate instances. In this example, the function accepts input and output parameter details for each function call, and substitutes the actual parameters to perform its defined operation. As you can see from the two invocations of the function, the values passed to the function are different, but the function’s defined operation is applied in the same way; within the function definition, the value for hours that is supplied from the calling procedure is multiplied by the value supplied for rate from the same calling procedure. The single return value derived is returned to the calling procedure. The parameters associated with this user-defined function are further discussed in the "Using Parameters to Pass Values" section presented later in this chapter.
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |