FUNCTION function-name RETURNS return-type PRIVATE( parameter , parameter ) :function-body
FUNCTION function-name RETURNS return-type( parameter , parameter )FORWARDMAP TO actual-name IN proc-handleIN SUPER.Use the following syntax to declare a Web service operation. For more information on declaring Web service operations, see OpenEdge Development: Web Services.
FUNCTION operationName RETURNS return-type( parameter , parameter )IN hPortType .The name of the function. You must avoid ABL reserved keywords. For a list of ABL keywords, see the Keyword Index in this manual.return-typeRETURNSIndicates the data type of the function return value. You can specify return-type as one of the following data types. For more information on each data type, see the Data types reference entry:
CHARACTER COM-HANDLE DATE DATETIME DATETIME-TZ DECIMALHANDLE INT64 INTEGER LOGICAL LONGCHAR MEMPTR RAWRECID ROWIDCLASS object-type-name EXTENT constantSpecifies the type name of an ABL or .NET class or interface. Specify an object type name using the syntax described in the Type-name syntax reference entry. With an appropriate USING statement, you can also specify a class or interface name alone, without the qualifying package or namespace.For a class or interface return value, ABL returns an object reference associated with the class or interface, not a class instance itself. For more information on object references, see the Class-based object reference reference entry.EXTENT constantDefines the return value as an array of data elements with the specified primitive or object type. This option can specify an array return value as either determinate (has a defined number of elements) or indeterminate (has an undefined number of elements). To define a determinate array return value, specify the EXTENT option with the constant argument. This optional argument is an integer value that represents the number of elements in the array. To define an indeterminate array return value, specify the EXTENT option without the constant argument.If you do not use the EXTENT option (or you specify constant as 0), the return value is not an array return value.
That the INTERNAL-ENTRIES attribute on the procedure that defines it does not provide its name (unless the procedure that defines it is the current procedure file).
That the GET-SIGNATURE( ) method on the procedure that defines it does not provide its signature (unless the procedure that defines it is the current procedure file).For information on the parameter definition syntax, see the Parameter definition syntax reference entry.The body of a function definition. Define function-body using the following syntax:
function-logic
...catch-block catch-blockfinally-blockEND FUNCTION .The logic of the function. This logic can contain the ABL statements allowed within a procedure block, except that the RETURN ERROR statement returns the Unknown value (?) for the function, regardless of its return type, but does not raise ERROR in the caller.To return a function value of the data type specified by return-type, you can execute the RETURN statement to set a value of that data type to return at run time. If you omit the RETURN statement, the function returns the Unknown value (?), regardless of the data type specified by return-type.If return-type is defined as a .NET array of mapped types (for example, "System.Byte[]"), you must return an object reference of the specified .NET array of mapped types in the RETURN statement. You cannot return an ABL array of a type that maps to the .NET array type (for example, INTEGER EXTENT) or the AVM raises a run-time error. If you do not execute any RETURN statement for return-type in the function-logic, the user-defined function returns the Unknown value (?) as its return value.Specifies a CATCH statement that defines error handling code for one or more error types. A DO block does not have any default error handling. Therefore, a DO block must have error handling options specified such that it becomes an undoable block. Otherwise, ABL generates a compiler warning. For more information on catch-block, see the CATCH statement reference entry.Specifies a FINALLY statement that defines the processing that must occur after all other processing in the block occurs. For more information on finally-block, see the FINALLY statement reference entry.END FUNCTIONactual-name IN proc-handleMAP TO
Optionally, that function-name (the second element in the FUNCTION statement) is an alias (alternative name) for the function and that actual-name is the name that appears in the function definition.
The definition of the function resides in another external procedure specified by proc-handle, which represents an expression that evaluates to a handle to the procedure that defines the function. This procedure can be an active procedure in the local context or in a remote persistent, single-run, or singleton procedure. For more information on remote user-defined functions, see OpenEdge Application Server: Developing AppServer Applications.A FUNCTION statement with the IN proc-handle option must include the following information on the function: the data type it returns, and the data type and mode (INPUT, OUTPUT, or INPUT-OUTPUT) of each parameter.The first example, r-udf1.p, defines and references the user-defined function doubler( ), which accepts an integer and returns the integer multiplied by two:The second example, r-udf2.p, declares a prototype for, references, and defines doubler( ):The third example consists of two procedures, r-udf3.p and r-udfdef.p. The example illustrates defining a prototype for user-defined function that is defined in an external procedure.The procedure, r-udf3.p, declares the prototype for doubler( ), runs r-udfdef.p persistently, invokes doubler( ), and deletes the persistent procedure:
/* r-udfdef.p *//* Defines user-defined function doubler() */FUNCTION doubler RETURNS INTEGER (INPUT parm1 AS INTEGER):RETURN (2 * parm1).END FUNCTION.To start the third example, run r-udf3.p in the Procedure Editor.In the fourth example, r-fctrl2.p, the user-defined function fact( ) implements the factorial function, common in probability and statistics, and commonly notated “!” (6! = 6 x 5 x 4 x 3 x 2 x 1; 100! = 100 x 99 x 98 x ... x 3 x 2 x 1):
doubler(my-shared-variable).
myfunc(OUTPUT TABLE tt BY-REFERENCE).For more information about passing these parameters by value, by reference, or by binding, see the Parameter passing syntax reference entry.
Use the ROUTINE-LEVEL ON ERROR UNDO, THROW statement in conjunction with the THROW option of the UNDO statement or the ON ERROR phrase in the user-defined function block.
Use the THROW option of the UNDO statement or the ON ERROR phrase from a CATCH block (CATCH statement) within the user-defined function block.
Invoke the STOP statement to raise the STOP condition in the caller.
© 2013 Progress Software Corporation and/or its subsidiaries or affiliates. |