<?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: Create a Table function in SAP HANA in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/create-a-table-function-in-sap-hana/qaa-p/704351#M191701</link>
    <description>&lt;P&gt;Your table function is missing the "return" statement, because the table function has to return a result. Via the return statement a result has to be returned which matches the type of the defined return type (a table with a structure containing fields PRODUCT and BENEFIT). You can either combine that with with the select statement (if you remove the COUNT(*) and define an alias for the result of the STRING_AGG function or you define an intermediate result variable for the query result and return that intermediate result. An example would be:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;...&lt;BR /&gt;BEGIN
  RETURN select "PRODUCT", STRING_AGG("BENEFIT", ',') as "BENEFIT"&lt;BR /&gt;         from "_SYS_BIC"."SCHEMA_NAME/ZCV_TEST05_1"('PLACEHOLDER' = ('$$ip_ym$$',
	 '2018-06-30')) 
         group by "PRODUCT";
END;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;PS: Please also check always to close your statements with a semi-colon (like e.g. the query statement in your logic which is not closed).&lt;/P&gt;</description>
    <pubDate>Sat, 20 Oct 2018 05:51:56 GMT</pubDate>
    <dc:creator>pfefferf</dc:creator>
    <dc:date>2018-10-20T05:51:56Z</dc:date>
    <item>
      <title>Create a Table function in SAP HANA</title>
      <link>https://community.sap.com/t5/technology-q-a/create-a-table-function-in-sap-hana/qaq-p/704350</link>
      <description>&lt;P&gt;Dear Experts,&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;I am trying to create a Table function in SAP HANA . I am facing a problem while creating it.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;I did a test through a SELECT and I get the expected result, now I have to implement this same logic in the Table Function, but I have an error in the code.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/236645-image1.png" /&gt;&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;I have a simple Calculation View whose columns are PRODUCT, BENEFIT, CALDAY.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/236646-image2.png" /&gt;&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Thank you so much for your help!!&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Regards.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;This is the error:&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Could not execute 'FUNCTION "SCHEMA_NAME"."ZTEST05_TAB_FUNCTION" ( ) RETURNS (PRODUCT NVARCHAR(2), BENEFIT NVARCHAR(20)) ...' SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near "FUNCTION": line 1 col 1 (at pos 1)&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;FUNCTION "SCHEMA_NAME"."ZTEST05_TAB_FUNCTION" ( ) 
	RETURNS (PRODUCT NVARCHAR(2), BENEFIT NVARCHAR(20))
	LANGUAGE SQLSCRIPT
	SQL SECURITY INVOKER AS
BEGIN
SELECT
	 "PRODUCT",	 
	 COUNT(*), STRING_AGG(BENEFIT,',')
FROM "_SYS_BIC"."SCHEMA_NAME/ZCV_TEST05_1"('PLACEHOLDER' = ('$$ip_ym$$',
	 '2018-06-30')) 
GROUP BY "PRODUCT"         
END;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Oct 2018 16:10:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/create-a-table-function-in-sap-hana/qaq-p/704350</guid>
      <dc:creator>probledo</dc:creator>
      <dc:date>2018-10-19T16:10:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Table function in SAP HANA</title>
      <link>https://community.sap.com/t5/technology-q-a/create-a-table-function-in-sap-hana/qaa-p/704351#M191701</link>
      <description>&lt;P&gt;Your table function is missing the "return" statement, because the table function has to return a result. Via the return statement a result has to be returned which matches the type of the defined return type (a table with a structure containing fields PRODUCT and BENEFIT). You can either combine that with with the select statement (if you remove the COUNT(*) and define an alias for the result of the STRING_AGG function or you define an intermediate result variable for the query result and return that intermediate result. An example would be:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;...&lt;BR /&gt;BEGIN
  RETURN select "PRODUCT", STRING_AGG("BENEFIT", ',') as "BENEFIT"&lt;BR /&gt;         from "_SYS_BIC"."SCHEMA_NAME/ZCV_TEST05_1"('PLACEHOLDER' = ('$$ip_ym$$',
	 '2018-06-30')) 
         group by "PRODUCT";
END;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;PS: Please also check always to close your statements with a semi-colon (like e.g. the query statement in your logic which is not closed).&lt;/P&gt;</description>
      <pubDate>Sat, 20 Oct 2018 05:51:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/create-a-table-function-in-sap-hana/qaa-p/704351#M191701</guid>
      <dc:creator>pfefferf</dc:creator>
      <dc:date>2018-10-20T05:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Table function in SAP HANA</title>
      <link>https://community.sap.com/t5/technology-q-a/create-a-table-function-in-sap-hana/qaa-p/704352#M191702</link>
      <description>&lt;P&gt;Thank you so much!! Florian.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 16:15:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/create-a-table-function-in-sap-hana/qaa-p/704352#M191702</guid>
      <dc:creator>probledo</dc:creator>
      <dc:date>2018-10-23T16:15:11Z</dc:date>
    </item>
  </channel>
</rss>

