<?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: Execute immediate returning a table as output in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/execute-immediate-returning-a-table-as-output/qaa-p/13983396#M4898734</link>
    <description>&lt;P&gt;No syntax error for me from ABAP code with little changes on variable names:&lt;/P&gt;&lt;LI-CODE lang="abap"&gt;EXEC SQL.
CREATE OR REPLACE PROCEDURE SAPHANADB.ZZSRO_TEST(
IN source_table NVARCHAR(50),
IN target_table NVARCHAR(50),
IN select_clause NVARCHAR(50),
IN where_clause NVARCHAR(50),
OUT result_rows TABLE (EMPLID VARCHAR(11), EMPL_RCD INTEGER, EFFDT DATE, EFFSEQ INTEGER, GVT_SF50_REMARK VARCHAR(3))
)

LANGUAGE SQLSCRIPT
AS
BEGIN
-- Construct and execute dynamic SQL to find missing rows
DECLARE sql_stmt NVARCHAR(5000);

sql_stmt := 'SELECT ' + select_clause + ' FROM ' + source_table + ' src ' + 'WHERE NOT EXISTS (SELECT 1 FROM ' || target_table || ' tgt WHERE ' || where_clause || ')';
result_rows := EXECUTE IMMEDIATE sql_stmt;
END;
ENDEXEC.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 12 Jan 2025 11:05:50 GMT</pubDate>
    <dc:creator>Sandra_Rossi</dc:creator>
    <dc:date>2025-01-12T11:05:50Z</dc:date>
    <item>
      <title>Execute immediate returning a table as output</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-returning-a-table-as-output/qaq-p/13983213</link>
      <description>&lt;P&gt;the following code does not compile&lt;/P&gt;&lt;P&gt;CREATE OR REPLACE PROCEDURE schema.GET_MISSING_ROWS(&lt;BR /&gt;IN source_table NVARCHAR(50),&lt;BR /&gt;IN target_table NVARCHAR(50),&lt;BR /&gt;IN select_clause NVARCHAR(50),&lt;BR /&gt;IN where_clause NVARCHAR(50),&lt;BR /&gt;OUT result_rows TABLE (EMPLID VARCHAR(11), EMPL_RCD INTEGER, EFFDT DATE, EFFSEQ INTEGER, GVT_SF50_REMARK VARCHAR(3))&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;LANGUAGE SQLSCRIPT&lt;BR /&gt;AS&lt;BR /&gt;BEGIN&lt;BR /&gt;-- Construct and execute dynamic SQL to find missing rows&lt;BR /&gt;DECLARE sql_stmt NVARCHAR(5000);&lt;BR /&gt;&lt;BR /&gt;sql_stmt := 'SELECT ' + :select_clause + ' FROM ' + :source_table + ' src ' + 'WHERE NOT EXISTS (SELECT 1 FROM ' || :target_table || ' tgt WHERE ' || :where_clause || ')';&lt;BR /&gt;result_rows := EXECUTE IMMEDIATE (:sql_stmt);&lt;BR /&gt;END;&lt;/P&gt;&lt;P&gt;error:&lt;/P&gt;&lt;P&gt;Could not execute 'CREATE OR REPLACE PROCEDURE schema.GET_MISSING_ROWS( IN source_table NVARCHAR(50), IN ...'&lt;BR /&gt;SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near "IMMEDIATE": line 16 col 28 (at pos 672)&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jan 2025 16:36:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-returning-a-table-as-output/qaq-p/13983213</guid>
      <dc:creator>mocasio</dc:creator>
      <dc:date>2025-01-11T16:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: Execute immediate returning a table as output</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-returning-a-table-as-output/qaa-p/13983224#M4898716</link>
      <description>You should try to locate the error cause. Try EXECUTE IMMEDIATE with hardcoded SELECT. Describe everything you have tried, and the result summary for each try.</description>
      <pubDate>Sat, 11 Jan 2025 18:35:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-returning-a-table-as-output/qaa-p/13983224#M4898716</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2025-01-11T18:35:43Z</dc:date>
    </item>
    <item>
      <title>Re: Execute immediate returning a table as output</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-returning-a-table-as-output/qaa-p/13983228#M4898717</link>
      <description>Is a syntax error not a execution error</description>
      <pubDate>Sat, 11 Jan 2025 18:51:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-returning-a-table-as-output/qaa-p/13983228#M4898717</guid>
      <dc:creator>mjocasio</dc:creator>
      <dc:date>2025-01-11T18:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: Execute immediate returning a table as output</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-returning-a-table-as-output/qaa-p/13983229#M4898718</link>
      <description>My answer was for a syntax error: You should try to locate the error cause. Try EXECUTE IMMEDIATE with hardcoded SELECT. Describe everything you have tried, and the result summary for each try.</description>
      <pubDate>Sat, 11 Jan 2025 19:35:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-returning-a-table-as-output/qaa-p/13983229#M4898718</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2025-01-11T19:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: Execute immediate returning a table as output</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-returning-a-table-as-output/qaa-p/13983396#M4898734</link>
      <description>&lt;P&gt;No syntax error for me from ABAP code with little changes on variable names:&lt;/P&gt;&lt;LI-CODE lang="abap"&gt;EXEC SQL.
CREATE OR REPLACE PROCEDURE SAPHANADB.ZZSRO_TEST(
IN source_table NVARCHAR(50),
IN target_table NVARCHAR(50),
IN select_clause NVARCHAR(50),
IN where_clause NVARCHAR(50),
OUT result_rows TABLE (EMPLID VARCHAR(11), EMPL_RCD INTEGER, EFFDT DATE, EFFSEQ INTEGER, GVT_SF50_REMARK VARCHAR(3))
)

LANGUAGE SQLSCRIPT
AS
BEGIN
-- Construct and execute dynamic SQL to find missing rows
DECLARE sql_stmt NVARCHAR(5000);

sql_stmt := 'SELECT ' + select_clause + ' FROM ' + source_table + ' src ' + 'WHERE NOT EXISTS (SELECT 1 FROM ' || target_table || ' tgt WHERE ' || where_clause || ')';
result_rows := EXECUTE IMMEDIATE sql_stmt;
END;
ENDEXEC.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Jan 2025 11:05:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-returning-a-table-as-output/qaa-p/13983396#M4898734</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2025-01-12T11:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: Execute immediate returning a table as output</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-returning-a-table-as-output/qaa-p/13983460#M4898742</link>
      <description>&lt;P&gt;I get the same syntax error if I embed your code in an AMDP procedure, but this message is not the root cause. The root cause is shown in red color here, concerning CREATE:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sandra_Rossi_0-1736681643259.png"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/210961i53A59A40E6671385/image-size/medium?v=v2&amp;amp;px=400" alt="Sandra_Rossi_0-1736681643259.png" title="Sandra_Rossi_0-1736681643259.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;You can easily see the right cause by commenting the line "EXECUTE IMMEDIATE":&lt;/P&gt;&lt;BLOCKQUOTE&gt;SQLSCRIPT message: feature not supported: DDL statements other than CREATE/DROP TABLE is/are not supported in procedure&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Consider that the AMDP procedure corresponds itself to a database procedure created in HANA via CREATE PROCEDURE, so you have to check&amp;nbsp;&lt;SPAN&gt;the documentation of CREATE PROCEDURE (&lt;A href="https://help.sap.com" target="_blank" rel="noopener"&gt;https://help.sap.com&lt;/A&gt;), to see the permitted statements in CREATE PROCEDURE and so in an AMDP procedure.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;You can see below that CREATE [OR REPLACE] PROCEDURE is not part of the permitted statements:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sandra_Rossi_2-1736697220337.png"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/210978i8ADF56F179B5AF11/image-size/medium?v=v2&amp;amp;px=400" alt="Sandra_Rossi_2-1736697220337.png" title="Sandra_Rossi_2-1736697220337.png" /&gt;&lt;/span&gt;&lt;BR /&gt;PS: for information, here's the minimal ABAP-AMDP-SQLSCRIPT reproducible example to get the error "sql syntax error: incorrect syntax near "IMMEDIATE"":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="abap"&gt;CLASS zzsro_amdp DEFINITION
  PUBLIC FINAL
  CREATE PUBLIC.
  PUBLIC SECTION.
    INTERFACES if_amdp_marker_hdb.
    METHODS test RAISING cx_amdp_error.
ENDCLASS.
CLASS zzsro_amdp IMPLEMENTATION.
  METHOD test BY DATABASE PROCEDURE
      FOR HDB 
      LANGUAGE SQLSCRIPT.
    CREATE OR REPLACE PROCEDURE schema.dbproc() LANGUAGE SQLSCRIPT AS
    BEGIN
    dummy := EXECUTE IMMEDIATE '';
    END;
  ENDMETHOD.
ENDCLASS.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS 2: minimal ABAP-AMDP-SQLSCRIPT reproducible example showing that CREATE [OR REPLACE] PROCEDURE is not permitted (error "SQLSCRIPT message: feature not supported: DDL statements other than CREATE/DROP TABLE is/are not supported in procedure":&lt;/P&gt;&lt;LI-CODE lang="abap"&gt;CLASS zzsro_amdp DEFINITION
PUBLIC FINAL
CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_amdp_marker_hdb.
METHODS test RAISING cx_amdp_error.
ENDCLASS.
CLASS zzsro_amdp IMPLEMENTATION.
METHOD test BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT.
CREATE OR REPLACE PROCEDURE schema.dbproc() LANGUAGE SQLSCRIPT AS
BEGIN
END;
ENDMETHOD.
ENDCLASS.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Jan 2025 16:47:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-returning-a-table-as-output/qaa-p/13983460#M4898742</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2025-01-12T16:47:30Z</dc:date>
    </item>
  </channel>
</rss>

