<?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: Dynamic SQL in SAP HANA stored procedures - Using mapping table in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/dynamic-sql-in-sap-hana-stored-procedures-using-mapping-table/qaa-p/12408761#M4644845</link>
    <description>&lt;P&gt;Yes, it is possible. Just search for "SQLScript Debugger", then you find all the relevant stuff.&lt;/P&gt;</description>
    <pubDate>Mon, 31 May 2021 04:50:50 GMT</pubDate>
    <dc:creator>pfefferf</dc:creator>
    <dc:date>2021-05-31T04:50:50Z</dc:date>
    <item>
      <title>Dynamic SQL in SAP HANA stored procedures - Using mapping table</title>
      <link>https://community.sap.com/t5/technology-q-a/dynamic-sql-in-sap-hana-stored-procedures-using-mapping-table/qaq-p/12408754</link>
      <description>&lt;P&gt;In SAP ECC we have created a mapping table containing user and organisation authorization access.&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;U1 : OrgA
U2 : OrgB
U3 : *
&lt;/CODE&gt;&lt;/PRE&gt; 
  &lt;P&gt;We have created a SAP HANA Calculation View in SQL Analytics Privileges. And we have an authorization dynamic authorization process in place, which will filter the access to the organisation dynamically based on the reading of the mapping table.&lt;/P&gt;
  &lt;P&gt;The solution works.&lt;/P&gt;
  &lt;P&gt;Expect for the management of the * value corresponding to the access to all organisation.&lt;/P&gt;
  &lt;P&gt;Would you know how to adjust the source code below to manage the access to all organisation ?&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;PROCEDURE "_SYS_BIC"."REPORTS::CONTROLE_AUTH_ORGANISATION" ( out OUT_FILTER VARCHAR(500) ) 
    LANGUAGE SQLSCRIPT
    SQL SECURITY definer
    DEFAULT SCHEMA ABAP
    READS SQL DATA AS
BEGIN

 VALUES_LIST = SELECT USER_NAME,'organisation in (' ||'''' || STRING_AGG(RESTRICTION, ''',''' )  ||  '''' || ')' 
 as RESTRICTION from auth_table
 where USER_NAME = SESSION_USER
 group by USER_NAME;
 
 SELECT distinct RESTRICTION into OUT_FILTER from :VALUES_LIST;

END;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 29 May 2021 07:09:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/dynamic-sql-in-sap-hana-stored-procedures-using-mapping-table/qaq-p/12408754</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2021-05-29T07:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic SQL in SAP HANA stored procedures - Using mapping table</title>
      <link>https://community.sap.com/t5/technology-q-a/dynamic-sql-in-sap-hana-stored-procedures-using-mapping-table/qaa-p/12408755#M4644839</link>
      <description>&lt;P&gt;The IN operator will not work for that case, because it will just do a string comparison for the '*' from your auth_table. &lt;/P&gt;&lt;P&gt;You need to implement a special handling. If for the user a star is found in the auth_table, instead of returning an expression with the IN operator, you have to return an expression with the LIKE operator (-&amp;gt; 'organisation like ''%''').&lt;/P&gt;</description>
      <pubDate>Sat, 29 May 2021 07:28:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/dynamic-sql-in-sap-hana-stored-procedures-using-mapping-table/qaa-p/12408755#M4644839</guid>
      <dc:creator>pfefferf</dc:creator>
      <dc:date>2021-05-29T07:28:05Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic SQL in SAP HANA stored procedures - Using mapping table</title>
      <link>https://community.sap.com/t5/technology-q-a/dynamic-sql-in-sap-hana-stored-procedures-using-mapping-table/qaa-p/12408756#M4644840</link>
      <description>&lt;P&gt;May Thanks Florian.&lt;/P&gt;&lt;P&gt;Is there a way to debug SQLScript ? Or to display step by step variables values ?&lt;/P&gt;</description>
      <pubDate>Sat, 29 May 2021 14:24:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/dynamic-sql-in-sap-hana-stored-procedures-using-mapping-table/qaa-p/12408756#M4644840</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2021-05-29T14:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic SQL in SAP HANA stored procedures - Using mapping table</title>
      <link>https://community.sap.com/t5/technology-q-a/dynamic-sql-in-sap-hana-stored-procedures-using-mapping-table/qaa-p/12408757#M4644841</link>
      <description>&lt;P&gt;I would suggest the following code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;PROCEDURE "_SYS_BIC"."REPORTS::CONTROLE_AUTH_ORGANISATION" ( out OUT_FILTER VARCHAR(500) ) 
    LANGUAGE SQLSCRIPT
    SQL SECURITY definer
    DEFAULT SCHEMA ABAP
    READS SQL DATA AS
BEGIN

 VALUES_LIST = SELECT USER_NAME,'organisation in (' ||'''' || STRING_AGG(RESTRICTION, ''',''' )  ||  '''' || ')
 OR 0 &amp;lt; ' || SUM (CASE WHEN RESTRICTION = '*' THEN 1 ELSE 0 END)
 as RESTRICTION  from auth_table
 where USER_NAME = SESSION_USER
 group by USER_NAME;

 
 SELECT distinct RESTRICTION into OUT_FILTER from :VALUES_LIST;

END;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 29 May 2021 14:44:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/dynamic-sql-in-sap-hana-stored-procedures-using-mapping-table/qaa-p/12408757#M4644841</guid>
      <dc:creator>Cocquerel</dc:creator>
      <dc:date>2021-05-29T14:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic SQL in SAP HANA stored procedures - Using mapping table</title>
      <link>https://community.sap.com/t5/technology-q-a/dynamic-sql-in-sap-hana-stored-procedures-using-mapping-table/qaa-p/12408758#M4644842</link>
      <description>&lt;P&gt;Thanks a lot all.&lt;/P&gt;&lt;P&gt;The syntax proposed : SELECT USER_NAME,'organisation in ('||''''|| STRING_AGG(RESTRICTION,''',''')||''''|| ')OR0&amp;lt;' || SUM (CASE WHEN RESTRICTION = '*' THEN1ELSE0END)&lt;/P&gt;&lt;P&gt;doesn't works.&lt;/P&gt;&lt;P&gt;I agree with the proposal of using : LIKE operator (-&amp;gt; 'organisation like ''%''').&lt;/P&gt;&lt;P&gt;I am not familiar with SQL Script coding do not know how to implement it ?&lt;/P&gt;&lt;P&gt;May you provide me some details ?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 30 May 2021 07:16:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/dynamic-sql-in-sap-hana-stored-procedures-using-mapping-table/qaa-p/12408758#M4644842</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2021-05-30T07:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic SQL in SAP HANA stored procedures - Using mapping table</title>
      <link>https://community.sap.com/t5/technology-q-a/dynamic-sql-in-sap-hana-stored-procedures-using-mapping-table/qaa-p/12408759#M4644843</link>
      <description>&lt;P&gt;What error do you have with the code I suggested ?&lt;/P&gt;</description>
      <pubDate>Sun, 30 May 2021 09:55:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/dynamic-sql-in-sap-hana-stored-procedures-using-mapping-table/qaa-p/12408759#M4644843</guid>
      <dc:creator>Cocquerel</dc:creator>
      <dc:date>2021-05-30T09:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic SQL in SAP HANA stored procedures - Using mapping table</title>
      <link>https://community.sap.com/t5/technology-q-a/dynamic-sql-in-sap-hana-stored-procedures-using-mapping-table/qaa-p/12408760#M4644844</link>
      <description>&lt;P&gt;The error message is : Syntax error. "0" is incorrect or misplaced.&lt;/P&gt;</description>
      <pubDate>Sun, 30 May 2021 18:06:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/dynamic-sql-in-sap-hana-stored-procedures-using-mapping-table/qaa-p/12408760#M4644844</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2021-05-30T18:06:10Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic SQL in SAP HANA stored procedures - Using mapping table</title>
      <link>https://community.sap.com/t5/technology-q-a/dynamic-sql-in-sap-hana-stored-procedures-using-mapping-table/qaa-p/12408761#M4644845</link>
      <description>&lt;P&gt;Yes, it is possible. Just search for "SQLScript Debugger", then you find all the relevant stuff.&lt;/P&gt;</description>
      <pubDate>Mon, 31 May 2021 04:50:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/dynamic-sql-in-sap-hana-stored-procedures-using-mapping-table/qaa-p/12408761#M4644845</guid>
      <dc:creator>pfefferf</dc:creator>
      <dc:date>2021-05-31T04:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic SQL in SAP HANA stored procedures - Using mapping table</title>
      <link>https://community.sap.com/t5/technology-q-a/dynamic-sql-in-sap-hana-stored-procedures-using-mapping-table/qaa-p/12408762#M4644846</link>
      <description>&lt;P&gt;On my side, I have no syntax error and the result is as expected.&lt;BR /&gt;I guess you made a copy/paste error&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1940766-auth.jpg" /&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" style="color: inherit;" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 31 May 2021 06:42:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/dynamic-sql-in-sap-hana-stored-procedures-using-mapping-table/qaa-p/12408762#M4644846</guid>
      <dc:creator>Cocquerel</dc:creator>
      <dc:date>2021-05-31T06:42:12Z</dc:date>
    </item>
  </channel>
</rss>

