<?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>topic Re: EXEC SQL with IN Clause in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/exec-sql-with-in-clause/m-p/3626843#M873800</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I haven't used it myself (yet), but this is what I found in the help:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EXEC SQL - EXECUTE &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Syntax &lt;/P&gt;&lt;P&gt;EXEC SQL. &lt;/P&gt;&lt;P&gt;  EXECUTE PROCEDURE proc ( IN    p_in1    IN    p_in2 ..., &lt;/P&gt;&lt;P&gt;                           OUT   p_out1   OUT   p_out2 ..., &lt;/P&gt;&lt;P&gt;                           INOUT p_inout1 INOUT p_inout2 ... ) &lt;/P&gt;&lt;P&gt;ENDEXEC. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect &lt;/P&gt;&lt;P&gt;In database systems, you can define procedures as so-called "stored procedures". Since the syntax for calling such procedures and the pertinent parameter transfer for various database systems can vary widely, a uniform command exists in Native SQL. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The statement EXECUTE PROCEDURE calls a procedure proc stored in the database. For all formal parameters of the procedure, you must specify the actual parameters, separated by commas. You must specify IN, OUT or INOUT before every actual parameter, in order to indicate whether the parameter is an input, output, or input/output parameter. You can use literals or Host Variables labeled by a colon(:)for the actual parameters. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example &lt;/P&gt;&lt;P&gt;This example defines a selfunc procedure using database specific SQL-Statements (Informix). It also calls the procedure using the SAP-specific Native-SQL-Statement EXECUTE PROCEDURE in a LOOP-loop by means of a Selection Table, and deletes the the procedure using an SQL-Statement. In the case shown here, the procedure is a function whose return value output in EXECUTE PROCEDURE is copied to the host variable name. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA scarr_carrid TYPE scarr-carrid. &lt;/P&gt;&lt;P&gt;SELECT-OPTIONS s_carrid FOR scarr_carrid NO INTERVALS. &lt;/P&gt;&lt;P&gt;DATA s_carrid_wa LIKE LINE OF s_carrid. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA name TYPE c LENGTH 20. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TRY. &lt;/P&gt;&lt;P&gt;    EXEC SQL. &lt;/P&gt;&lt;P&gt;      CREATE FUNCTION selfunc( input CHAR(3) ) &lt;/P&gt;&lt;P&gt;        RETURNING char(20); &lt;/P&gt;&lt;P&gt;        DEFINE output char(20); &lt;/P&gt;&lt;P&gt;        SELECT carrname &lt;/P&gt;&lt;P&gt;               INTO output &lt;/P&gt;&lt;P&gt;               FROM scarr &lt;/P&gt;&lt;P&gt;               WHERE mandt  = '000' AND &lt;/P&gt;&lt;P&gt;                     carrid = input; &lt;/P&gt;&lt;P&gt;        RETURN output; &lt;/P&gt;&lt;P&gt;        END FUNCTION; &lt;/P&gt;&lt;P&gt;    ENDEXEC. &lt;/P&gt;&lt;P&gt;    LOOP AT s_carrid INTO s_carrid_wa &lt;/P&gt;&lt;P&gt;                     WHERE sign = 'I' AND option = 'EQ'. &lt;/P&gt;&lt;P&gt;      TRY. &lt;/P&gt;&lt;P&gt;         EXEC SQL. &lt;/P&gt;&lt;P&gt;            EXECUTE PROCEDURE selfunc( IN  :s_carrid_wa-low, &lt;/P&gt;&lt;P&gt;                                       OUT :name ) &lt;/P&gt;&lt;P&gt;          ENDEXEC. &lt;/P&gt;&lt;P&gt;          WRITE: / s_carrid_wa-low, name. &lt;/P&gt;&lt;P&gt;        CATCH cx_sy_native_sql_error. &lt;/P&gt;&lt;P&gt;          MESSAGE `Error in procedure execution` TYPE 'I'. &lt;/P&gt;&lt;P&gt;      ENDTRY. &lt;/P&gt;&lt;P&gt;    ENDLOOP. &lt;/P&gt;&lt;P&gt;    EXEC SQL. &lt;/P&gt;&lt;P&gt;      DROP FUNCTION selfunc; &lt;/P&gt;&lt;P&gt;    ENDEXEC. &lt;/P&gt;&lt;P&gt;  CATCH cx_sy_native_sql_error. &lt;/P&gt;&lt;P&gt;    MESSAGE `Error in procedure handling` TYPE 'I'. &lt;/P&gt;&lt;P&gt;ENDTRY.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 14 Apr 2008 20:03:41 GMT</pubDate>
    <dc:creator>Sm1tje</dc:creator>
    <dc:date>2008-04-14T20:03:41Z</dc:date>
    <item>
      <title>EXEC SQL with IN Clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/exec-sql-with-in-clause/m-p/3626842#M873799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to run an EXEC SQL statement with an IN clause.  Here's my SQL code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
EXEC SQL.
      OPEN C FOR
      SELECT name
             FROM sv_hoover_data
             where dunsNum in :DUNS_NUMBERS
    ENDEXEC.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My DUNS_NUMBERS variable is of type String and contains the following data:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;('12334223','4353434','54674563')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When the statement is executed, I receive the following error message in SM21:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Line 1: Incorrect syntax near '@P1'.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, the underlying database is MS SQL Server.  When I run the query via MS Query Ananlyzer, it runs fine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does any know if EXEC SQL can handle IN clauses, and if so, how they're written?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Matt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Apr 2008 19:47:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/exec-sql-with-in-clause/m-p/3626842#M873799</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-14T19:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: EXEC SQL with IN Clause</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/exec-sql-with-in-clause/m-p/3626843#M873800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I haven't used it myself (yet), but this is what I found in the help:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EXEC SQL - EXECUTE &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Syntax &lt;/P&gt;&lt;P&gt;EXEC SQL. &lt;/P&gt;&lt;P&gt;  EXECUTE PROCEDURE proc ( IN    p_in1    IN    p_in2 ..., &lt;/P&gt;&lt;P&gt;                           OUT   p_out1   OUT   p_out2 ..., &lt;/P&gt;&lt;P&gt;                           INOUT p_inout1 INOUT p_inout2 ... ) &lt;/P&gt;&lt;P&gt;ENDEXEC. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect &lt;/P&gt;&lt;P&gt;In database systems, you can define procedures as so-called "stored procedures". Since the syntax for calling such procedures and the pertinent parameter transfer for various database systems can vary widely, a uniform command exists in Native SQL. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The statement EXECUTE PROCEDURE calls a procedure proc stored in the database. For all formal parameters of the procedure, you must specify the actual parameters, separated by commas. You must specify IN, OUT or INOUT before every actual parameter, in order to indicate whether the parameter is an input, output, or input/output parameter. You can use literals or Host Variables labeled by a colon(:)for the actual parameters. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example &lt;/P&gt;&lt;P&gt;This example defines a selfunc procedure using database specific SQL-Statements (Informix). It also calls the procedure using the SAP-specific Native-SQL-Statement EXECUTE PROCEDURE in a LOOP-loop by means of a Selection Table, and deletes the the procedure using an SQL-Statement. In the case shown here, the procedure is a function whose return value output in EXECUTE PROCEDURE is copied to the host variable name. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA scarr_carrid TYPE scarr-carrid. &lt;/P&gt;&lt;P&gt;SELECT-OPTIONS s_carrid FOR scarr_carrid NO INTERVALS. &lt;/P&gt;&lt;P&gt;DATA s_carrid_wa LIKE LINE OF s_carrid. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA name TYPE c LENGTH 20. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TRY. &lt;/P&gt;&lt;P&gt;    EXEC SQL. &lt;/P&gt;&lt;P&gt;      CREATE FUNCTION selfunc( input CHAR(3) ) &lt;/P&gt;&lt;P&gt;        RETURNING char(20); &lt;/P&gt;&lt;P&gt;        DEFINE output char(20); &lt;/P&gt;&lt;P&gt;        SELECT carrname &lt;/P&gt;&lt;P&gt;               INTO output &lt;/P&gt;&lt;P&gt;               FROM scarr &lt;/P&gt;&lt;P&gt;               WHERE mandt  = '000' AND &lt;/P&gt;&lt;P&gt;                     carrid = input; &lt;/P&gt;&lt;P&gt;        RETURN output; &lt;/P&gt;&lt;P&gt;        END FUNCTION; &lt;/P&gt;&lt;P&gt;    ENDEXEC. &lt;/P&gt;&lt;P&gt;    LOOP AT s_carrid INTO s_carrid_wa &lt;/P&gt;&lt;P&gt;                     WHERE sign = 'I' AND option = 'EQ'. &lt;/P&gt;&lt;P&gt;      TRY. &lt;/P&gt;&lt;P&gt;         EXEC SQL. &lt;/P&gt;&lt;P&gt;            EXECUTE PROCEDURE selfunc( IN  :s_carrid_wa-low, &lt;/P&gt;&lt;P&gt;                                       OUT :name ) &lt;/P&gt;&lt;P&gt;          ENDEXEC. &lt;/P&gt;&lt;P&gt;          WRITE: / s_carrid_wa-low, name. &lt;/P&gt;&lt;P&gt;        CATCH cx_sy_native_sql_error. &lt;/P&gt;&lt;P&gt;          MESSAGE `Error in procedure execution` TYPE 'I'. &lt;/P&gt;&lt;P&gt;      ENDTRY. &lt;/P&gt;&lt;P&gt;    ENDLOOP. &lt;/P&gt;&lt;P&gt;    EXEC SQL. &lt;/P&gt;&lt;P&gt;      DROP FUNCTION selfunc; &lt;/P&gt;&lt;P&gt;    ENDEXEC. &lt;/P&gt;&lt;P&gt;  CATCH cx_sy_native_sql_error. &lt;/P&gt;&lt;P&gt;    MESSAGE `Error in procedure handling` TYPE 'I'. &lt;/P&gt;&lt;P&gt;ENDTRY.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Apr 2008 20:03:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/exec-sql-with-in-clause/m-p/3626843#M873800</guid>
      <dc:creator>Sm1tje</dc:creator>
      <dc:date>2008-04-14T20:03:41Z</dc:date>
    </item>
  </channel>
</rss>

