<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Scalar UDF with several returning parameters in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/scalar-udf-with-several-returning-parameters/qaa-p/11405780#M4236489</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think my above suggestion will not work since the HANA UDF will not support the Input parameter as fields from other tables. You may have a look on the following discussion &lt;A href="https://scn.sap.com/thread/3426534" title="https://scn.sap.com/thread/3426534"&gt;field or table alias is not allowed as an input... | SCN&lt;/A&gt; .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Nithin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 27 Nov 2015 05:48:05 GMT</pubDate>
    <dc:creator>nithinu</dc:creator>
    <dc:date>2015-11-27T05:48:05Z</dc:date>
    <item>
      <title>Scalar UDF with several returning parameters</title>
      <link>https://community.sap.com/t5/technology-q-a/scalar-udf-with-several-returning-parameters/qaq-p/11405776</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a scalar user defined function with one (or more) input and two (or more) returning parameters. I want to use that function via declarative logic in a select statement. Both returning parameters shall be used, but since the function call is quite expensive, it should only be called once.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At the moment I haven't found a solution how to use both returning parameters with only one call. Here is a simple executable example (which is actually coming from the SQLScript Guide):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
&lt;P&gt;create function func_add_mul(x double, y double)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; returns result_add double,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result_mul double&lt;/P&gt;
&lt;P&gt;&amp;nbsp; language sqlscript reads sql data as&lt;/P&gt;
&lt;P&gt;begin&lt;/P&gt;
&lt;P&gt;&amp;nbsp; result_add = :x + :y;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; result_mul = :x * :y;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;do&lt;/P&gt;
&lt;P&gt;begin&lt;/P&gt;
&lt;P&gt;&amp;nbsp; lt_data = select 1 as a, 2 as b from dummy&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; union select 3 as a, 4 as b from dummy;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp; select a, b,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; func_add_mul(a, b).result_add as "add",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; func_add_mul(a, b).result_mul as "mult"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; from :lt_data;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;drop function func_add_mul;&lt;/P&gt;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When the select statement in line 14 is executed, the UDF func_add_mul is called twice for every row of the table. This is quite inefficient, since the UDF returns both results in a single call. I'm looking for a way (or a workaround) to achieve the same thing with only ONE call for every row.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only workaround I can think of would be to use imperative logic. Then I would first build two arrays containing the values a and b and then call the UDF once for every combination. Then I could unnest the resulting arrays into a table again. But I think due to performance reasons it would be better to use declarative logic...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does anyone know a solution for this problem? Or is it a current limitation for scalar UDFs? I'm using HANA SPS10 by the way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks and best regards&lt;/P&gt;&lt;P&gt;Felix&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Nov 2015 08:43:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/scalar-udf-with-several-returning-parameters/qaq-p/11405776</guid>
      <dc:creator>felix_guldner</dc:creator>
      <dc:date>2015-11-26T08:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: Scalar UDF with several returning parameters</title>
      <link>https://community.sap.com/t5/technology-q-a/scalar-udf-with-several-returning-parameters/qaa-p/11405777#M4236486</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Felix,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what calculations are you doing in the scalar UDF? Are you just doing (a+b) and (a*b) (what could be replaced by expressions) or something more sophisticated?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To my knowledge it is not possible to return both return values within one call in a select statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Florian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Nov 2015 12:45:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/scalar-udf-with-several-returning-parameters/qaa-p/11405777#M4236486</guid>
      <dc:creator>pfefferf</dc:creator>
      <dc:date>2015-11-26T12:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: Scalar UDF with several returning parameters</title>
      <link>https://community.sap.com/t5/technology-q-a/scalar-udf-with-several-returning-parameters/qaa-p/11405778#M4236487</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Florian,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;we are doing something more sophisticated. Actually, within the scalar UDF we are calling a complex stored procedure which selects data from several different tables/views and calculates some numbers in the end. These numbers are then returned to the UDF and from there just passed through.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Our overall requirement is to enrich a table/view with some calculated fields. These fields require a quite complex calculation, which is performed in a stored procedure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The coding above was just a very simple example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Felix&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Nov 2015 12:54:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/scalar-udf-with-several-returning-parameters/qaa-p/11405778#M4236487</guid>
      <dc:creator>felix_guldner</dc:creator>
      <dc:date>2015-11-26T12:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Scalar UDF with several returning parameters</title>
      <link>https://community.sap.com/t5/technology-q-a/scalar-udf-with-several-returning-parameters/qaa-p/11405779#M4236488</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Felix,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it possible for you to use a &lt;SPAN style="font-size: 13.3333px;"&gt;Table UDF to return multiple parameters ? Since the function will always return a single row, you can use the 'cross join' to connect your Table/View with the UDF. This is just a suggestion, I could be wrong! &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Nithin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Nov 2015 05:27:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/scalar-udf-with-several-returning-parameters/qaa-p/11405779#M4236488</guid>
      <dc:creator>nithinu</dc:creator>
      <dc:date>2015-11-27T05:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: Scalar UDF with several returning parameters</title>
      <link>https://community.sap.com/t5/technology-q-a/scalar-udf-with-several-returning-parameters/qaa-p/11405780#M4236489</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think my above suggestion will not work since the HANA UDF will not support the Input parameter as fields from other tables. You may have a look on the following discussion &lt;A href="https://scn.sap.com/thread/3426534" title="https://scn.sap.com/thread/3426534"&gt;field or table alias is not allowed as an input... | SCN&lt;/A&gt; .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Nithin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Nov 2015 05:48:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/scalar-udf-with-several-returning-parameters/qaa-p/11405780#M4236489</guid>
      <dc:creator>nithinu</dc:creator>
      <dc:date>2015-11-27T05:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Scalar UDF with several returning parameters</title>
      <link>https://community.sap.com/t5/technology-q-a/scalar-udf-with-several-returning-parameters/qaa-p/11405781#M4236490</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Nithin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it would have been a good workaround, but as you already mentioned, it's not possible to use table fields as input parameters for the table UDF. I just verified that in a simple example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Felix&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Nov 2015 06:50:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/scalar-udf-with-several-returning-parameters/qaa-p/11405781#M4236490</guid>
      <dc:creator>felix_guldner</dc:creator>
      <dc:date>2015-11-27T06:50:57Z</dc:date>
    </item>
  </channel>
</rss>

