Example: Sourced UDFs involving UDTs

Suppose you have defined a sourced UDF on the built-in SUM function to support SUM on Euros.

The function statement is as follows:

     CREATE FUNCTION SUM (EURO) 
       RETURNS EURO 
       SOURCE SYSIBM.SUM (DECIMAL())

You want to know the total of sales in Germany for each product in the year of 2004. You want to obtain the total sales in U.S. dollars:

     SELECT PRODUCT_ITEM, US_DOLLAR (SUM (TOTAL)) 
       FROM GERMAN_SALES 
       WHERE YEAR = 2004 
       GROUP BY PRODUCT_ITEM

You cannot write SUM (US_DOLLAR (TOTAL)), unless you had defined a SUM function on U.S. dollar in a manner similar to the above.

Related reference
Example: Assignments involving different UDTs