User-defined functions
- Last Updated: March 30, 2020
- 2 minute read
- OpenEdge
- Version 12.2
- Documentation
A user-defined function is a block of custom code in a procedure file that returns a value. It is similar to the built-in ABL functions. It is like an internal procedure, but with the requirement that it must return a value. A user-defined function can also define parameters that are used as input, output, or both.
Before you can use a user-defined function in your code, you must define it. The
definition must precede the code where it is used. Here is the simplified
syntax:
|
- function-name
- The name of the function.
- type
- The type of the return value.
- parameter-list
- Parameters are optional. A valid specification of parameters includes the
parameter use (
INPUT,OUTPUT,INPUT-OUTPUT), its name, and its type. - return-value
- The return value of the function. The value must match the type specified in type.
In the following example code we define two functions,
OrderPrefix() and GeneratePO(). The
function, OrderPrefix(), takes no parameters and
returns the prefix for the purchase order (PO) as a CHARACTER type. The GeneratePO() function has two parameters and constructs a
PO number using these parameters.
|
You can pass a function as a parameter to another function. In the example
code, you see the
OrderPrefix() function being passed
as the first parameter to the GeneratePO() function.
Running the code produces the following output:
|