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:

  1. 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.

  2. Allocate a system-descriptor area with the ALLOCATE DESCRIPTOR statement.

    For more information, see Allocate memory for a system-descriptor area.

  3. 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.

  4. 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 Determine the statement type.

  5. 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.

  6. Deallocate the system-descriptor area with the DEALLOCATE DESCRIPTOR statement.

    See Free memory allocated to a system-descriptor area.