<?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: Left outer join 3 tables with where-statement in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/left-outer-join-3-tables-with-where-statement/m-p/5471915#M1253037</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Freek! I tried it your way and it works totally fine.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 05 May 2009 17:57:21 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-05-05T17:57:21Z</dc:date>
    <item>
      <title>Left outer join 3 tables with where-statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/left-outer-join-3-tables-with-where-statement/m-p/5471911#M1253033</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi folks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope you can understand (and maybe solve) my problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Generally I try to left outer join three tables. The third table is used for a WHERE-statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The three table structures are the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;table 1 (user)    &lt;/P&gt;&lt;P&gt;user1 | key&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;table 2 (detail)   &lt;/P&gt;&lt;P&gt;key | ID&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;table 3 (header)&lt;/P&gt;&lt;P&gt;ID | user2                  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;...and I want to achieve the following structure (as example filled with data):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;user | key | ID&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="------" /&gt;&lt;P&gt;|----&lt;DEL&gt;-|&lt;/DEL&gt;----&lt;/P&gt;&lt;P&gt;xy    | a    | 001&lt;/P&gt;&lt;P&gt;xy    | b    | #&lt;/P&gt;&lt;P&gt;z     | b     | #&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The clue ist the usage of the third table. &lt;STRONG&gt;I need the table to set user1 and user2 equal (WHERE)&lt;/STRONG&gt; but there are two problems:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) Obviously I can't left outer join two tables with each other. In this case I already used the 'key' of table 1 to join it with the 'key' of table 2. So I can't left outer join the 'ID' of table 2 with the 'ID' of table 3. Error message that I can only left outer join a table once. Any proposals?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) I have to include a WHERE to equal user1 with user2. But I am not allowed to use the user2 from table 3 because of the left outer join.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried this coding:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT a&lt;SUB&gt;user1 a&lt;/SUB&gt;key b~id INTO TABLE itab FROM ( table1 AS a&lt;/P&gt;&lt;P&gt;  LEFT OUTER JOIN table2 AS b ON a&lt;SUB&gt;key = b&lt;/SUB&gt;key ) &lt;/P&gt;&lt;P&gt;  LEFT OUTER JOIN table3 AS c ON b&lt;SUB&gt;ID = c&lt;/SUB&gt;ID ) &lt;/P&gt;&lt;P&gt;  WHERE a&lt;SUB&gt;user1 = c&lt;/SUB&gt;user2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would really appreciate your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;MrclSpdl&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Apr 2009 13:10:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/left-outer-join-3-tables-with-where-statement/m-p/5471911#M1253033</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-15T13:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: Left outer join 3 tables with where-statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/left-outer-join-3-tables-with-where-statement/m-p/5471912#M1253034</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi  MrclSpdl,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can make the join for first two table and get in to a internal table. Then join the internal table with the third table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Shahid Malayil&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Apr 2009 13:32:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/left-outer-join-3-tables-with-where-statement/m-p/5471912#M1253034</guid>
      <dc:creator>shahid_malayil1</dc:creator>
      <dc:date>2009-04-15T13:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: Left outer join 3 tables with where-statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/left-outer-join-3-tables-with-where-statement/m-p/5471913#M1253035</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Shahid,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I already tried to join an internal table filled with the data from the first select. Unfortunetaly it isn't possible to work with a SELECT ... FROM statement and internal tables in ABAP &lt;SPAN __jive_emoticon_name="sad"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rgds&lt;/P&gt;&lt;P&gt;MrclSpdl&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Apr 2009 14:08:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/left-outer-join-3-tables-with-where-statement/m-p/5471913#M1253035</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-15T14:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: Left outer join 3 tables with where-statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/left-outer-join-3-tables-with-where-statement/m-p/5471914#M1253036</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;IF you want to join a DB table with an internal table, you need to use the 'FOR ALL ENTRIES' statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select dbfields&lt;/P&gt;&lt;P&gt;into table itab2&lt;/P&gt;&lt;P&gt;from dbtab&lt;/P&gt;&lt;P&gt;for all entries in itab&lt;/P&gt;&lt;P&gt;where dbfield1 = itab-field1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will get you a second internal table with all the corresponding data for the first selection.  You can then join them with a loop through the first table and a read table on the second table (for 1 - 1 relation) or a nested loop statement on both tables (for 1 - N relation).  Make itab a hashed table when using read table with key, use a sorted table if you need to loop without key access.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Freek&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 May 2009 13:18:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/left-outer-join-3-tables-with-where-statement/m-p/5471914#M1253036</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-05T13:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: Left outer join 3 tables with where-statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/left-outer-join-3-tables-with-where-statement/m-p/5471915#M1253037</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Freek! I tried it your way and it works totally fine.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 May 2009 17:57:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/left-outer-join-3-tables-with-where-statement/m-p/5471915#M1253037</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-05T17:57:21Z</dc:date>
    </item>
  </channel>
</rss>

