<?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: SQL use Subquery in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-use-subquery/m-p/12634936#M2013696</link>
    <description>&lt;P&gt;It's probably possible with EXISTS (it's kind of join), but it would be too much time-consuming to answer.&lt;/P&gt;&lt;P&gt;Otherwise, if it works as native SQL in your database, just execute it as native SQL.&lt;/P&gt;&lt;P&gt;Good luck!&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jun 2022 10:27:58 GMT</pubDate>
    <dc:creator>Sandra_Rossi</dc:creator>
    <dc:date>2022-06-23T10:27:58Z</dc:date>
    <item>
      <title>SQL use Subquery</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-use-subquery/m-p/12634933#M2013693</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
  &lt;P&gt;I try to write a SQL in my ABAP Report but it does not work with subqueries.&lt;/P&gt;
  &lt;P&gt;I do not know how to change the SQL to fix my problem.&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;SELECT DISTINCT m~CONTR_NUM,&lt;BR /&gt;                m~CONTR_NUM_P,&lt;BR /&gt;                s~SUBSCRIPTION_ID,&lt;BR /&gt;                h~CONTRACT_TYPE,&lt;BR /&gt;                h~CUSTOMER,&lt;BR /&gt;                m~PRODUCT_OFFERING,&lt;BR /&gt;                p1~MAKTX,&lt;BR /&gt;                k~PRODUCT_OFFERING,&lt;BR /&gt;                p2~MAKTX&lt;BR /&gt;  FROM ( SELECT v~PRODINST_ID, v~CONTR_NUM, p~CONTR_NUM_P, p~PRODUCT_OFFERING&lt;BR /&gt;          FROM YGK_CONT_P as p&lt;BR /&gt;          JOIN YGK_CONT_RELA_V as v&lt;BR /&gt;            ON p~PRODINST_ID = v~PRODINST_ID&lt;BR /&gt;           AND p~contr_num = v~contr_num&lt;BR /&gt;         WHERE v~RELATION_NAME = 'has_Zweitanbindung'&lt;BR /&gt;           AND p~ITEM_STATUS = 'A' ) as m&lt;BR /&gt; inner join (SELECT v~PRODINST_ID,&lt;BR /&gt;                    v~CONTR_NUM,&lt;BR /&gt;                    p~CONTR_NUM_P,&lt;BR /&gt;                    p~PRODUCT_OFFERING&lt;BR /&gt;               FROM YGK_CONT_P as p&lt;BR /&gt;               JOIN YGK_CONT_RELA_V as v&lt;BR /&gt;                 ON p~PRODINST_ID = v~PRODINST_ID&lt;BR /&gt;                AND p~contr_num = v~contr_num&lt;BR /&gt;              WHERE v~RELATION_NAME = 'has_Erstanbindung'&lt;BR /&gt;                AND p~ITEM_STATUS = 'A') as k&lt;BR /&gt;    ON m~contr_num = k~contr_num&lt;BR /&gt; Inner join MAKT as p1&lt;BR /&gt;    ON ( p1~MATNR = m~PRODUCT_OFFERING AND p1~SPRAS = 'D' )&lt;BR /&gt; Inner join MAKT as p2&lt;BR /&gt;    ON ( p2~MATNR = k~PRODUCT_OFFERING AND p2~SPRAS = 'D' )&lt;BR /&gt; INNER JOIN YGK_CONT_H as h&lt;BR /&gt;    ON m~contr_num = h~contr_num&lt;BR /&gt; INNER JOIN YGK_CONT_P as s&lt;BR /&gt;    ON ( m~contr_num = s~contr_num AND s~PARENT_ID = ' ' AND&lt;BR /&gt;       s~item_status = 'A' )&lt;BR /&gt; WHERE ( m~CONTR_NUM, m~CONTR_NUM_P ) NOT IN&lt;BR /&gt;       ( SELECT e~CONTR_NUM, e~CONTR_NUM_P&lt;BR /&gt;          FROM YGK_CONT_RELA_V as e&lt;BR /&gt;         WHERE e~RELATION_NAME = 'has_ProaktivesServicemanagement' ).&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Jun 2022 09:08:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-use-subquery/m-p/12634933#M2013693</guid>
      <dc:creator>tobias96</dc:creator>
      <dc:date>2022-06-23T09:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: SQL use Subquery</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-use-subquery/m-p/12634934#M2013694</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;What is the error you are getting?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 09:27:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-use-subquery/m-p/12634934#M2013694</guid>
      <dc:creator>venkateswaran_k</dc:creator>
      <dc:date>2022-06-23T09:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: SQL use Subquery</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-use-subquery/m-p/12634935#M2013695</link>
      <description>&lt;P&gt;Please use the COMMENT button for comments, questions, adding details, replying to a comment or a proposed solution or to the OP question, etc., ANSWER is only to propose a solution, dixit SAP text at the right of the answer area. &lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 09:46:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-use-subquery/m-p/12634935#M2013695</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2022-06-23T09:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: SQL use Subquery</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-use-subquery/m-p/12634936#M2013696</link>
      <description>&lt;P&gt;It's probably possible with EXISTS (it's kind of join), but it would be too much time-consuming to answer.&lt;/P&gt;&lt;P&gt;Otherwise, if it works as native SQL in your database, just execute it as native SQL.&lt;/P&gt;&lt;P&gt;Good luck!&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 10:27:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-use-subquery/m-p/12634936#M2013696</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2022-06-23T10:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: SQL use Subquery</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-use-subquery/m-p/12634937#M2013697</link>
      <description>&lt;P&gt;Please try this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;with +test1 as 
( SELECT v~PRODINST_ID, v~CONTR_NUM, p~CONTR_NUM_P, p~PRODUCT_OFFERING
          FROM YGK_CONT_P as p
          JOIN YGK_CONT_RELA_V as v
            ON p~PRODINST_ID = v~PRODINST_ID
           AND p~contr_num = v~contr_num
         WHERE v~RELATION_NAME = 'has_Zweitanbindung'
           AND p~ITEM_STATUS = 'A' )
),

test2 as
(SELECT v~PRODINST_ID,
                    v~CONTR_NUM,
                    p~CONTR_NUM_P,
                    p~PRODUCT_OFFERING
               FROM YGK_CONT_P as p
               JOIN YGK_CONT_RELA_V as v
                 ON p~PRODINST_ID = v~PRODINST_ID
                AND p~contr_num = v~contr_num
              WHERE v~RELATION_NAME = 'has_Erstanbindung'
                AND p~ITEM_STATUS = 'A'

)
SELECT DISTINCT m~CONTR_NUM,
                m~CONTR_NUM_P,
                s~SUBSCRIPTION_ID,
                h~CONTRACT_TYPE,
                h~CUSTOMER,
                m~PRODUCT_OFFERING,
                p1~MAKTX,
                k~PRODUCT_OFFERING,
                p2~MAKTX
  FROM +test as m
 inner join +test2 as k
    ON m~contr_num = k~contr_num
 Inner join MAKT as p1
    ON ( p1~MATNR = m~PRODUCT_OFFERING AND p1~SPRAS = 'D' )
 Inner join MAKT as p2
    ON ( p2~MATNR = k~PRODUCT_OFFERING AND p2~SPRAS = 'D' )
 INNER JOIN YGK_CONT_H as h
    ON m~contr_num = h~contr_num
 INNER JOIN YGK_CONT_P as s
    ON ( m~contr_num = s~contr_num AND s~PARENT_ID = ' ' AND
       s~item_status = 'A' )
 WHERE ( m~CONTR_NUM, m~CONTR_NUM_P ) NOT IN
       ( SELECT e~CONTR_NUM, e~CONTR_NUM_P
          FROM YGK_CONT_RELA_V as e
         WHERE e~RELATION_NAME = 'has_ProaktivesServicemanagement' ).&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Jun 2022 12:43:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-use-subquery/m-p/12634937#M2013697</guid>
      <dc:creator>ThorstenHoefer</dc:creator>
      <dc:date>2022-06-23T12:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: SQL use Subquery</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-use-subquery/m-p/12634938#M2013698</link>
      <description>&lt;P&gt;Hi &lt;/P&gt;&lt;P&gt;I was also about to say this soln.  But it is giving syntax error as "Comma without preceding colon (after WITH?).&lt;/P&gt;&lt;P&gt;How to resolve this&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 12:46:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-use-subquery/m-p/12634938#M2013698</guid>
      <dc:creator>venkateswaran_k</dc:creator>
      <dc:date>2022-06-23T12:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: SQL use Subquery</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-use-subquery/m-p/12634939#M2013699</link>
      <description>&lt;P&gt;Please check that you use tte new sql syntax. You should select the result "into table  @lt_data"&lt;/P&gt;&lt;P&gt;Which Abap Version do you use?&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.sap.com/doc/abapdocu_751_index_htm/7.51/de-DE/abapwith.htm"&gt;WITH - ABAP-Schlüsselwortdokumentation (sap.com)&lt;/A&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; WHERE not exists 
       ( SELECT  @abap_true 
          FROM YGK_CONT_RELA_V as e
         WHERE e~RELATION_NAME = 'has_ProaktivesServicemanagement' and&lt;BR /&gt;               e~CONTR_NUM = m~CONTR_NUM and&lt;BR /&gt;               e~CONTR_NUM_P = m~CONTR_NUM_P )&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Jun 2022 12:52:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-use-subquery/m-p/12634939#M2013699</guid>
      <dc:creator>ThorstenHoefer</dc:creator>
      <dc:date>2022-06-23T12:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: SQL use Subquery</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-use-subquery/m-p/12634940#M2013700</link>
      <description>&lt;P&gt;Hi thanks for your answer.&lt;/P&gt;&lt;P&gt;Unfortunately it will not work for me I do not know exactly why not.&lt;/P&gt;&lt;P&gt;I get an error in SE80 at the first line&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; "" is grammatically not allowed here.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The part with where not in is not the problem.&lt;/P&gt;&lt;P&gt;I use ABAP Version 750&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;WHERE ( m~CONTR_NUM, m~CONTR_NUM_P ) NOT IN
       ( SELECT e~CONTR_NUM, e~CONTR_NUM_P
          FROM YGK_CONT_RELA_V as e
         WHERE e~RELATION_NAME = 'has_ProaktivesServicemanagement' ).&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Jun 2022 13:27:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-use-subquery/m-p/12634940#M2013700</guid>
      <dc:creator>tobias96</dc:creator>
      <dc:date>2022-06-23T13:27:34Z</dc:date>
    </item>
    <item>
      <title>Re: SQL use Subquery</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sql-use-subquery/m-p/12634941#M2013701</link>
      <description>&lt;P&gt;CTE (WITH) is only available from 7.51.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 14:47:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sql-use-subquery/m-p/12634941#M2013701</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2022-06-23T14:47:22Z</dc:date>
    </item>
  </channel>
</rss>

