Handling unknown return values
This section describes how to use a system-descriptor area to save values that a dynamically executed user-defined function returns.
To use a system-descriptor area to handle unknown function return values:
- Assemble and prepare an EXECUTE FUNCTION statement.
The EXECUTE FUNCTION statement cannot include an INTO clause. For more information, see Assemble and prepare the SQL statement.
- Allocate a system-descriptor area with the ALLOCATE DESCRIPTOR
statement.
For more information, see Allocate memory for a system-descriptor area.
- Determine the number and data type (or data types) of the return
value (or values) with the DESCRIBE...USING SQL DESCRIPTOR statement.
The DESCRIBE...USING SQL DESCRIPTOR statement fills an item descriptor for each value that the user-defined function returns. For more information about DESCRIBE, see Initialize the system-descriptor area.
- After the DESCRIBE statement, you can test the SQLCODE variable
(sqlca.sqlcode) for the SQ_EXECPROC defined constant to check
for a prepared EXECUTE FUNCTION statement.
This constant is defined in the sqlstype.h header file. For more information, see ids_esqlc_0586.html#ids_esqlc_0586.
- Execute the EXECUTE FUNCTION statement and store the return values
in the system-descriptor area.
The statement you use to execute a user-defined function depends on whether the function is a noncursor function or a cursor function. The following sections discuss how to execute each type of function.
- Deallocate the system-descriptor area with the DEALLOCATE DESCRIPTOR statement.