With the DB2SQL parameter style, the same parameters and same order of parameters are passed into the external program or service program as are passed in for parameter style SQL. However, DB2SQL allows additional optional parameters to be passed along as well.
If more than one of the optional parameters below is specified in the UDF definition, they are passed to the UDF in the order defined below. Refer to parameter style SQL for the common parameters. This parameter style can be used for both scalar and table UDFs.
For scalar functions:
>>-+------------------+--SQL-result--+----------------------+---> | .--------------. | | .------------------. | | V | | | V | | '---SQL-argument-+-' '---SQL-argument-ind-+-' >--SQL-result-ind--SQL-state--function-name--specific-name------> >--diagnostic-message--+------------+--+-----------+------------> '-scratchpad-' '-call-type-' >--+--------+-------------------------------------------------->< '-dbinfo-'
For table functions:
.------------. V | >>-+------------------+----SQL-result-+-------------------------> | .--------------. | | V | | '---SQL-argument-+-' .----------------. V | >--+----------------------+----SQL-result-ind-+--SQL-state------> | .------------------. | | V | | '---SQL-argument-ind-+-' >--function-name--specific-name--diagnostic-message-------------> >--+------------+--call-type--+--------+----------------------->< '-scratchpad-' '-dbinfo-'
For table functions, the scratchpad is initialized as above before the FIRST call to the UDF if FINAL CALL is specified on the CREATE FUNCTION. After this call, the scratchpad content is totally under control of the table function. DB2 does not examine or change the content of the scratchpad thereafter. The scratchpad is passed to the function on each invocation. The function can be re-entrant, and DB2 preserves its state information in the scratchpad.
If NO FINAL CALL was specified or defaulted for a table function, then the scratchpad is initialized as above for each OPEN call, and the scratchpad content is completely under control of the table function between OPEN calls. This can be very important for a table function used in a join or subquery. If it is necessary to maintain the content of the scratchpad across OPEN calls, then FINAL CALL must be specified in your CREATE FUNCTION statement. With FINAL CALL specified, in addition to the normal OPEN, FETCH, and CLOSE calls, the table function will also receive FIRST and FINAL calls, for the purpose of scratchpad maintenance and resource release.
For scalar functions:
For table functions: