External scalar function and method processing model
The FIRST call, NORMAL call, and FINAL call are processing models for methods and scalar UDFs that are defined with the FINAL CALL specifications.
Use
the following calls for ordinary error processing for methods and
scalar UDFs.
- FIRST call
- This is a special case of the NORMAL call, identified as FIRST to enable the function to perform any initial processing. Arguments are evaluated and passed to the function. Normally, the function will return a value on this call, but it can return an error, in which case no NORMAL or FINAL call is made. If an error is returned on a FIRST call, the method or UDF must clean up before returning, because no FINAL call will be made.
- NORMAL call
- These are the second through second-last calls to the function, as dictated by the data and the logic of the statement. The function is expected to return a value with each NORMAL call after arguments are evaluated and passed. If NORMAL call returns an error, no further NORMAL calls are made, but the FINAL call is made.
- FINAL call
- This is a special call, made at end-of-statement processing (or CLOSE of a cursor), provided that the FIRST call succeeded. No argument values are passed on a FINAL call. This call is made so that the function can clean up any resources. The function does not return a value on this call, but can return an error.
For methods or scalar UDFs not defined with FINAL CALL, only NORMAL calls are made to the function, which normally returns a value for each call. If a NORMAL call returns an error, or if the statement encounters another error, no more calls are made to the function.
Note: This model describes the ordinary error processing for methods
and scalar UDFs. In the event of a system failure or communication
problem, a call indicated by the error processing model cannot be
made. For example, for a FENCED UDF, if the
db2udf
fenced
process is somehow prematurely terminated, the database
manager cannot make the indicated calls.