Parameter style GENERAL WITH NULLS

The parameter style GENERAL WITH NULLS can only be used with scalar UDFs.

With this parameter style, the parameters are passed into the service program as follows (in the order specified):

Read syntax diagramSkip visual syntax diagram
                             .------------------.   
                             V                  |   
>>-SQL-result = funcname--(----+--------------+-+--------------->
                               '-SQL-argument-'     

>--+------------------------+--SQL-result-ind--)---------------><
   '-SQL-argument-ind-array-'                      

SQL-argument
This argument is set by DB2® before calling the UDF. This value repeats n times, where n is the number of arguments specified in the function reference. The value of each of these arguments is taken from the expression specified in the function invocation. It is expressed in the data type of the defined parameter in the CREATE FUNCTION statement. Note: These parameters are treated as input only; any changes to the parameter values made by the UDF are ignored by DB2.
SQL-argument-ind-array
This argument is set by DB2 before calling the UDF. It can be used by the UDF to determine if one or more SQL-arguments are null or not. It is an array of two-byte signed integers (indicators). The nth array argument corresponds corresponds to the nth SQL-argument. Each array entry is set to one of the following values:
0
The argument is present and not null.
-1
The argument is null.

The UDF should check for null input. Note: This parameter is treated as input only; any changes to the parameter value made by the UDF is ignored by DB2.

SQL-result-ind
This argument is set by the UDF before returning to DB2. The database provides the storage for the return value. The argument is defined as a two-byte signed integer. If set to a negative value, the database interprets the result of the function as null. If set to zero or a positive value, the database uses the value returned in SQL-result. The database provides the storage for the return value indicator. Since the parameter is passed by address, the address is of the storage where the indicator value should be placed.
SQL-result
This value is returned by the UDF. DB2 copies the value into database storage. In order to return the value correctly, the function code must be a value-returning function. The database copies only as much of the value as defined for the return value as specified on the CREATE FUNCTION statement. If the CAST FROM clause is used in the CREATE FUNCTION statement, DB2 assumes the UDF returns the value as defined in the CAST FROM clause, otherwise DB2 assumes the UDF returns the value as defined in the RETURNS clause.

Because of the requirement that the function code be a value-returning function, any function code used for parameter style GENERAL WITH NULLS must be created into a service program.

Notes:
  1. The external name specified on the CREATE FUNCTION statement can be specified either with or without single quotation marks. If the name is not quoted, it is uppercased before it is stored; if it is quoted, it is stored as specified. This becomes important when naming the actual program, as the database searches for the program that has a name that exactly matches the name stored with the function definition. For example, if a function was created as:
       CREATE FUNCTION X(INT) RETURNS INT
         LANGUAGE C
         EXTERNAL NAME 'MYLIB/MYPGM(MYENTRY)'
       
    and the source for the program was:
       void myentry(
              int*in
              int*out,
              .
              .
              . .
    the database will not find the entry because it is in lowercase myentry and the database was instructed to look for uppercase MYENTRY.
  2. For service programs with C++ modules, make sure in the C++ source code to precede the program function definition with extern "C". Otherwise, the C++ compiler will perform 'name mangling' of the function's name and the database will not find it.