Any-size return values for UDSFs
If you use ANY for the size of a UDSF return value, the UDSF must calculate the size of the numeric or string return value by overriding the calculateSize() method to define the sizing operation.
The calculateSize() method provides an upper limit of the return value size. It specifies the amount of memory that the system allocates for the result; however, the actual return value length still needs to be set. A Db2® instance offers a number of sizer methods that you can use to process the string and numeric data types.
The following example shows the calculateSize() method
being used for a string data type:
virtual uint64 calculateSize() const
{
int len = 0;
for (int i=0; i < numSizerArgs(); i++) //for each input argument
{
if (sizerArgType(i) == UDX_VARIABLE)
len += sizerStringArgSize(i); //add the input argument sizes
}
return sizerStringSizeValue(len); //let return value be the sum
}