<?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: Nested SQL-Statement with dynamic &amp;quot;exists&amp;quot; in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-sql-statement-with-dynamic-quot-exists-quot/m-p/7327210#M1537677</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What do you mean by a dynamic Join statement. I can see only a dynamic where clause in your statement which can be build using a join statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 21 Sep 2010 14:39:54 GMT</pubDate>
    <dc:creator>kesavadas_thekkillath</dc:creator>
    <dc:date>2010-09-21T14:39:54Z</dc:date>
    <item>
      <title>Nested SQL-Statement with dynamic "exists"</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-sql-statement-with-dynamic-quot-exists-quot/m-p/7327206#M1537673</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi experts&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need a multi sql-statement with an dynamic "exists"-command on the  the second level.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;dynamic where = 'WERKS EQ MD&lt;SUB&gt;WERKS AND LGORT EQ MD&lt;/SUB&gt;LGORT'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select *&lt;/P&gt;&lt;P&gt;           from mara as ma&lt;/P&gt;&lt;P&gt;                   where exists ( select *&lt;/P&gt;&lt;P&gt;                                                    from mard as md&lt;/P&gt;&lt;P&gt;                                                          where matnr eq ma~matnr&lt;/P&gt;&lt;P&gt;                                                           and exists ( select *&lt;/P&gt;&lt;P&gt;                                                                                from t001l&lt;/P&gt;&lt;P&gt;                                                                                where (dynamic_where) ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I do it on this way, i get a dump called SAPSQL_INVALID_TABLENAME, regarding that the system don't knows the table 'MD'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But when I do it on the way below it runs.&lt;/P&gt;&lt;P&gt;select *&lt;/P&gt;&lt;P&gt;           from mara as ma&lt;/P&gt;&lt;P&gt;                   where exists ( select *&lt;/P&gt;&lt;P&gt;                                                    from mard as md&lt;/P&gt;&lt;P&gt;                                                             where matnr eq ma~matnr&lt;/P&gt;&lt;P&gt;                                                            and exists ( select *&lt;/P&gt;&lt;P&gt;                                                                                from t001l&lt;/P&gt;&lt;P&gt;                                                                                where werks eq md~werks&lt;/P&gt;&lt;P&gt;                                                                                and lgort eq md~lgort ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can someone please help me, to create a dynamic where-statement on t001l instead of the constant-statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Christian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Sep 2010 13:42:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-sql-statement-with-dynamic-quot-exists-quot/m-p/7327206#M1537673</guid>
      <dc:creator>Private_Member_19084</dc:creator>
      <dc:date>2010-09-21T13:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: Nested SQL-Statement with dynamic "exists"</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-sql-statement-with-dynamic-quot-exists-quot/m-p/7327207#M1537674</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dynamic WHERE-conditions in subqueries are not supported at least until Rel. 7.00, see ABAP documentation. I don't know whether new enhancement packages will add this feature.&lt;/P&gt;&lt;P&gt;Have you looked into rewriting your query to use joins instead of subqueries?&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Sep 2010 13:48:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-sql-statement-with-dynamic-quot-exists-quot/m-p/7327207#M1537674</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2010-09-21T13:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Nested SQL-Statement with dynamic "exists"</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-sql-statement-with-dynamic-quot-exists-quot/m-p/7327208#M1537675</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Thomas&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, thank you for your fast and very helpful answer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried an InnerJoin, but with this I can't make a dynamic "join-statement".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Sep 2010 14:34:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-sql-statement-with-dynamic-quot-exists-quot/m-p/7327208#M1537675</guid>
      <dc:creator>Private_Member_19084</dc:creator>
      <dc:date>2010-09-21T14:34:45Z</dc:date>
    </item>
    <item>
      <title>Re: Nested SQL-Statement with dynamic "exists"</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-sql-statement-with-dynamic-quot-exists-quot/m-p/7327209#M1537676</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can have a dynamic where condition using internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select x  y  z  from table  t  where(itab).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check in SDN, u'll find a lot of posts.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;G@urav&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Sep 2010 14:37:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-sql-statement-with-dynamic-quot-exists-quot/m-p/7327209#M1537676</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-09-21T14:37:09Z</dc:date>
    </item>
    <item>
      <title>Re: Nested SQL-Statement with dynamic "exists"</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-sql-statement-with-dynamic-quot-exists-quot/m-p/7327210#M1537677</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What do you mean by a dynamic Join statement. I can see only a dynamic where clause in your statement which can be build using a join statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Sep 2010 14:39:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-sql-statement-with-dynamic-quot-exists-quot/m-p/7327210#M1537677</guid>
      <dc:creator>kesavadas_thekkillath</dc:creator>
      <dc:date>2010-09-21T14:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: Nested SQL-Statement with dynamic "exists"</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-sql-statement-with-dynamic-quot-exists-quot/m-p/7327211#M1537678</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you can do it using the dynamic syntax&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT ... FROM (dbtab_syntax) INTO ...&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;dbtab_syntax can contain the entire JOIN, ON and WHERE syntax, but it must be a valid expression, or you will produce short dumps unless caught via TRY / ENDTRY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Sep 2010 15:10:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-sql-statement-with-dynamic-quot-exists-quot/m-p/7327211#M1537678</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2010-09-21T15:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: Nested SQL-Statement with dynamic "exists"</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-sql-statement-with-dynamic-quot-exists-quot/m-p/7327212#M1537679</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I did a dynamic join recently, &lt;/P&gt;&lt;P&gt;check the sample code if it helps&lt;/P&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;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;     CONDENSE gs_struct-val_tab NO-GAPS.
      CONDENSE gs_struct-val_field NO-GAPS.

      CONCATENATE gs_struct-val_tab '~' gs_struct-val_field INTO fld_where.

      CONCATENATE fld_where ' EQ ' l_com  &amp;lt;valor&amp;gt; l_com INTO strwhere RESPECTING BLANKS.

      " validacion con constante?
      IF gs_struct-val_cons IS NOT INITIAL.
        CONCATENATE strwhere 'AND' gs_struct-val_cons INTO strwhere SEPARATED BY space.
      ENDIF.

      IF &amp;lt;valor&amp;gt; IS INITIAL AND gs_struct-notnull EQ 'X'.
        PERFORM set_light USING 'E' CHANGING &amp;lt;light&amp;gt;.

        CONCATENATE 'El valor del campo' gs_struct-fieldname 'es nulo'
        INTO &amp;lt;message&amp;gt; SEPARATED BY space.
      ELSE.
*&amp;amp;--------------------------------------------------------------------------------------*
*&amp;amp;      el valor no es nulo, valida sobre tabla-campo
*&amp;amp;--------------------------------------------------------------------------------------*
        IF gs_struct-val_tab IS NOT INITIAL AND gs_struct-val_field IS NOT INITIAL.
          CONCATENATE gs_struct-val_tab '~'gs_struct-val_field
          INTO strsel.

          CONCATENATE gs_struct-val_tab 'AS' gs_struct-val_tab
          INTO strfrom SEPARATED BY space.

          IF gs_struct-val_join IS NOT INITIAL AND gs_struct-val_on IS NOT INITIAL.
            CONCATENATE strfrom 'INNER JOIN' gs_struct-val_join 'AS' gs_struct-val_join 'ON' gs_struct-val_on
              INTO strfrom SEPARATED BY space.
          ENDIF.

          TRY .
              SELECT SINGLE (strsel)
              INTO &amp;lt;dummy&amp;gt;
              FROM (strfrom)"(gs_struct-val_tab)
              WHERE (strwhere).
            CATCH cx_sy_dynamic_osql_semantics.
              CLEAR ok_code.
              MESSAGE e001(00) WITH 'Error en generación de consulta'.
          ENDTRY.

          IF sy-subrc NE 0.
            PERFORM set_light USING 'E' CHANGING &amp;lt;light&amp;gt;.
            CONCATENATE 'Valor no encontrado en' gs_struct-val_tab '-'
                                                 gs_struct-val_field
                                                 INTO &amp;lt;message&amp;gt; SEPARATED BY space.
          ENDIF.
        ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Sep 2010 16:21:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-sql-statement-with-dynamic-quot-exists-quot/m-p/7327212#M1537679</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-09-21T16:21:20Z</dc:date>
    </item>
    <item>
      <title>Re: Nested SQL-Statement with dynamic "exists"</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-sql-statement-with-dynamic-quot-exists-quot/m-p/7327213#M1537680</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Thomas&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you again for your great answer.&lt;/P&gt;&lt;P&gt;Now, this solved my problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've done it wrong, I thought the dynamic-statement has to be in the 'ON'.&lt;/P&gt;&lt;P&gt;Now I've made a dynamic 'FROM'-statement and it runs great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thx a lot for your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chrsitian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Sep 2010 05:56:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-sql-statement-with-dynamic-quot-exists-quot/m-p/7327213#M1537680</guid>
      <dc:creator>Private_Member_19084</dc:creator>
      <dc:date>2010-09-22T05:56:39Z</dc:date>
    </item>
  </channel>
</rss>

