Put column values into a system-descriptor area
When you create a SELECT statement dynamically, you cannot use the INTO host_var clause of FETCH because you cannot name the host variables in the prepared statement. To fetch column values into a system-descriptor area, use the USING SQL DESCRIPTOR clause of FETCH instead of the INTO clause. The FETCH...USING SQL DESCRIPTOR statement puts each column value into the DATA field of its item descriptor.
When the column values are in the system-descriptor area, you can use the GET DESCRIPTOR statement to transfer these values from their DATA fields to the appropriate host variables. You must use the LENGTH and TYPE fields to determine, at run time, the data types for these host variables. You might need to perform data type or length conversions between the SQL data types in the TYPE fields and the data types that are needed for host variables that hold the return value.
For more information about how to execute SELECT statements dynamically, see Handling an unknown select list. For more information about how to execute user-defined functions dynamically, see Handling unknown return values.