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  function-name RETURNS type [ ( parameter-list ) ] :
  /* ABL code */
  RETURN return-value.
END FUNCTION.
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.
/* eCustomFunctions.p */ 

FUNCTION OrderPrefix RETURNS CHARACTER():
  RETURN "PO".
END FUNCTION.

FUNCTION GeneratePO RETURNS CHARACTER (INPUT pcString AS CHARACTER, INPUT-OUTPUT piNumber AS INTEGER):
  VAR CHAR cResult.
  cResult = pcString + STRING(100 * piNumber).
  piNumber = piNumber + 1.
  RETURN cResult.
END FUNCTION.

DEFINE VARIABLE iNum AS INTEGER NO-UNDO INITIAL 999.

/* main procedure code */
MESSAGE "Purchase Order number is:" GeneratePO(OrderPrefix(),INPUT-OUTPUT iNum) SKIP
  "New iNum is: " iNum VIEW-AS ALERT-BOX.
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:
Purchase Order number is: PO99900 
New iNum is:  1000