User-Defined Functions

In Uniface, it is possible to create user-defined functions (also known as private functions) that can be used in the ProcScript language just as any other function.

To define your own function, define an entry with a return type. On the first line after entry, use the returns statement to define the return type. For example:

entry MULTIPLY
returns numeric

params
   numeric PAR1: IN
   numeric PAR2: IN
endparams

variables
   numeric MultiplyResult
endvariables

MultiplyResult = PAR1 * PAR2
return MultiplyResult
end

You call a user-defined function just as you would any other function. For example:

$1 = MULTIPLY(2, 4)
; $1 equals 8

Like any entry, a user-defined function can be defined in any code container within a component, including entity and field code containers. However, all entries have component scope, so it is best to define them in the Script container of the component object. This makes it easier to centralize, locate, and maintain these modules.

In a global ProcScript module, you can create user-defined functions without an entry statement. In this case, the function is given the name of the global ProcScript.

Operations cannot have a return type and cannot be used as functions.