Create a sourced function
A sourced function is built over any built-in or existing user-defined function. It can
then be altered to suit the needs of the new function. The new function can be used with the
system data types or you can add your own data types. For a listing of built-in functions, see
Built-in functions.
To create a sourced function based on a system function:
- In the System i Navigator window, expand the system you want to use.
- Expand Databases.
- Expand the database and schema that you want to work with.
- Right-click the Functions container and select New, then External.
- On the New Sourced Function dialog, specify the name by which you want the function to be known in the
Function field. The name must not be the same as a procedure that exists in the same schema.
Also, the signature of the function must not be the same as any other function that exists in the same schema.
- Specify the name of the function on which this function is based in the Source function field.
- Select the data type that the function returns. Depending on what type you select, you
must also specify the length of the return value in the Length field and the number of
digits to the right of the decimal in the Scale field or the CCSID type in the CCSID field.
If you selected a large object type, select Return value as a locator to save system resources
by deferring or avoiding moving data.
- If you want to see the parameters that the function uses, click the Parameters tab.
- Click OK.
Notes:
- To create a sourced function based on an existing user-defined function (UDF), right-click on the
source function (UDF) in the schema tree and select New based on. Then following the steps listed above.
- When creating a new sourced function, if the source is a built-in function, the grid
is empty and you must insert any parameters that you want to define. If the source function
is user-defined, the parameters of the source function are initially shown in the grid, and
you can use them as they are or cast them to other types. However, in this case, you cannot add or remove parameters.