<?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: Problems with joining tables in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131975#M111955</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would suggest that you change your code to something like this.  This works a lot better in my system.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This most important part here is that you are missing a key when join the AFVC and AFVV tables.  You need to add APLZL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

report zrich_0003.


types: begin of itab,
ltxa1 like afvc-ltxa1,
vornr like afvc-vornr,
arbei like afvv-arbei,
end of itab.

data: it_temp type table of itab,
      wa_temp type itab.

select&amp;lt;b&amp;gt; b~ltxa1 b~vornr c~arbei&amp;lt;/b&amp;gt;into (wa_temp-ltxa1, wa_temp-vornr, wa_temp-arbei)
&amp;lt;b&amp;gt;   from caufv as a
       inner join afvc as b
        on a~aufpl = b~aufpl&amp;lt;/b&amp;gt;
          inner join afvv as c
                 on b~aufpl = c~aufpl
&amp;lt;b&amp;gt;                and b~APLZL = C~APLZL&amp;lt;/b&amp;gt;     " &amp;lt;--- This right here  "
                       &amp;lt;b&amp;gt;where a~aufnr = '001004193793'.&amp;lt;/b&amp;gt;
  write:/ wa_temp-ltxa1, wa_temp-vornr, wa_temp-arbei.
  append wa_temp to it_temp.
endselect.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, I have swapped the join for CAUFV and AFVC.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 13 Feb 2006 20:23:03 GMT</pubDate>
    <dc:creator>RichHeilman</dc:creator>
    <dc:date>2006-02-13T20:23:03Z</dc:date>
    <item>
      <title>Problems with joining tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131973#M111953</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am totally new at programming abap and would like som help with a join-statement.&lt;/P&gt;&lt;P&gt;I am wondering why this code generates four rows instead of 2 as a result? Is there some kind of nested loops going on? Can I solve this with inner or outer joins?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Report test.&lt;/P&gt;&lt;P&gt;TYPES: BEGIN OF itab,&lt;/P&gt;&lt;P&gt;       ltxa1 LIKE afvc-ltxa1,&lt;/P&gt;&lt;P&gt;       vornr LIKE afvc-vornr,&lt;/P&gt;&lt;P&gt;       arbei LIKE afvv-arbei,&lt;/P&gt;&lt;P&gt;      END OF itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: it_temp TYPE table of itab,&lt;/P&gt;&lt;P&gt;      wa_temp TYPE itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT a&lt;SUB&gt;ltxa1 a&lt;/SUB&gt;vornr c~arbei&lt;/P&gt;&lt;P&gt;INTO (wa_temp-ltxa1, wa_temp-vornr, wa_temp-arbei)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FROM afvc AS a&lt;/P&gt;&lt;P&gt;JOIN caufv AS b&lt;/P&gt;&lt;P&gt;ON a&lt;SUB&gt;aufpl = b&lt;/SUB&gt;aufpl&lt;/P&gt;&lt;P&gt;OUTER JOIN afvv AS c&lt;/P&gt;&lt;P&gt;ON b&lt;SUB&gt;aufpl = c&lt;/SUB&gt;aufpl&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WHERE b~aufnr = '000005000240'.&lt;/P&gt;&lt;P&gt;  WRITE:/ wa_temp-ltxa1, wa_temp-vornr, wa_temp-arbei.&lt;/P&gt;&lt;P&gt;  APPEND wa_temp TO it_temp.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Tomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Feb 2006 20:12:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131973#M111953</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-13T20:12:31Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with joining tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131974#M111954</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tomas,&lt;/P&gt;&lt;P&gt;  Change it this way..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT a&lt;SUB&gt;ltxa1 a&lt;/SUB&gt;vornr c~arbei&lt;/P&gt;&lt;P&gt;INTO (wa_temp-ltxa1, wa_temp-vornr, wa_temp-arbei)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FROM afvc AS a&lt;/P&gt;&lt;P&gt;JOIN caufv AS b&lt;/P&gt;&lt;P&gt;ON a&lt;SUB&gt;aufpl = b&lt;/SUB&gt;aufpl&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;JOIN&amp;lt;/b&amp;gt; afvv AS c&lt;/P&gt;&lt;P&gt;ON b&lt;SUB&gt;aufpl = c&lt;/SUB&gt;aufpl&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WHERE b~aufnr = '000005000240'.&lt;/P&gt;&lt;P&gt;WRITE:/ wa_temp-ltxa1, wa_temp-vornr, wa_temp-arbei.&lt;/P&gt;&lt;P&gt;APPEND wa_temp TO it_temp.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Feb 2006 20:20:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131974#M111954</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-13T20:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with joining tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131975#M111955</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would suggest that you change your code to something like this.  This works a lot better in my system.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This most important part here is that you are missing a key when join the AFVC and AFVV tables.  You need to add APLZL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

report zrich_0003.


types: begin of itab,
ltxa1 like afvc-ltxa1,
vornr like afvc-vornr,
arbei like afvv-arbei,
end of itab.

data: it_temp type table of itab,
      wa_temp type itab.

select&amp;lt;b&amp;gt; b~ltxa1 b~vornr c~arbei&amp;lt;/b&amp;gt;into (wa_temp-ltxa1, wa_temp-vornr, wa_temp-arbei)
&amp;lt;b&amp;gt;   from caufv as a
       inner join afvc as b
        on a~aufpl = b~aufpl&amp;lt;/b&amp;gt;
          inner join afvv as c
                 on b~aufpl = c~aufpl
&amp;lt;b&amp;gt;                and b~APLZL = C~APLZL&amp;lt;/b&amp;gt;     " &amp;lt;--- This right here  "
                       &amp;lt;b&amp;gt;where a~aufnr = '001004193793'.&amp;lt;/b&amp;gt;
  write:/ wa_temp-ltxa1, wa_temp-vornr, wa_temp-arbei.
  append wa_temp to it_temp.
endselect.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, I have swapped the join for CAUFV and AFVC.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Feb 2006 20:23:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131975#M111955</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2006-02-13T20:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with joining tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131976#M111956</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nope, changing outer join to join didnt help.&lt;/P&gt;&lt;P&gt;I still get four rows as a result instead of 2&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Feb 2006 20:23:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131976#M111956</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-13T20:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with joining tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131977#M111957</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please see my previous post.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Feb 2006 20:25:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131977#M111957</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2006-02-13T20:25:49Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with joining tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131978#M111958</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a lot Rich! This did the job.&lt;/P&gt;&lt;P&gt;Now it works great. This forum is truly amazing, and you guys are great. Keep it up.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you explain your code to me? This aplzl field, is it an internal counter or what does it do?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Tomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Feb 2006 20:30:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131978#M111958</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-13T20:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with joining tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131979#M111959</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tomas,&lt;/P&gt;&lt;P&gt;  Change your internal table &amp;amp; populate the values like this to see whether your data is duplicating or not.&lt;/P&gt;&lt;P&gt;TYPES: BEGIN OF itab,&lt;/P&gt;&lt;P&gt;aufnr like caufv-aufnr,&lt;/P&gt;&lt;P&gt;aufpl like afvc-aufpl,&lt;/P&gt;&lt;P&gt;ltxa1 LIKE afvc-ltxa1,&lt;/P&gt;&lt;P&gt;vornr LIKE afvc-vornr,&lt;/P&gt;&lt;P&gt;arbei LIKE afvv-arbei,&lt;/P&gt;&lt;P&gt;END OF itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT a&lt;SUB&gt;aufnr b&lt;/SUB&gt;aufpl a&lt;SUB&gt;ltxa1 a&lt;/SUB&gt;vornr c~arbei&lt;/P&gt;&lt;P&gt;INTO (wa_temp-aufnr, wa_temp-aufpl, wa_temp-ltxa1, wa_temp-vornr, wa_temp-arbei)&lt;/P&gt;&lt;P&gt;FROM afvc AS a&lt;/P&gt;&lt;P&gt;JOIN caufv AS b&lt;/P&gt;&lt;P&gt;ON a&lt;SUB&gt;aufpl = b&lt;/SUB&gt;aufpl&lt;/P&gt;&lt;P&gt;OUTER JOIN afvv AS c&lt;/P&gt;&lt;P&gt;ON b&lt;SUB&gt;aufpl = c&lt;/SUB&gt;aufpl&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;b&lt;SUB&gt;aplzl = c&lt;/SUB&gt;aplzl&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;WHERE b~aufnr = '000005000240'.&lt;/P&gt;&lt;P&gt;WRITE:/ wa_temp-aufnr, wa_temp-aufpl, wa_temp-ltxa1, wa_temp-vornr, wa_temp-arbei.&lt;/P&gt;&lt;P&gt;APPEND wa_temp TO it_temp.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Phani Kiran Nudurupati&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Feb 2006 20:31:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131979#M111959</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-13T20:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with joining tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131980#M111960</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The reason that you need that is because of the relation between AFVC and AFVV.  Notice that the keys of these tables are the same.  Meaning that for every AFVC record, there is a corresponding AFVV record and they are joined by there keys AUFPL and APLZL.  The way you had you code earlier,  you were joining every record from AFVV with key AUFPL to each record of AFVC with key AUFPL.   Now you are joining 1 for 1 to the tables.  Did I confuse you more?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Feb 2006 20:36:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131980#M111960</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2006-02-13T20:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with joining tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131981#M111961</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello again,&lt;/P&gt;&lt;P&gt;Thanks for the code phani, great.&lt;/P&gt;&lt;P&gt;Also huge thanks for the explanation Rich. You didnt confuse me at all &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt; This made understand why I got four rows.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Tomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Feb 2006 20:40:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131981#M111961</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-13T20:40:47Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with joining tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131982#M111962</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tomas,&lt;/P&gt;&lt;P&gt;  Generally when you are selecting data from the tables make sure you take the key fields in your select,so that you will not get confused when you get multiple lines of similar data.If the key is present then it is quite easy to understand the data in the internal table.&lt;/P&gt;&lt;P&gt;While writing as a report,you can just write those fields which are required.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Feb 2006 20:46:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problems-with-joining-tables/m-p/1131982#M111962</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-13T20:46:12Z</dc:date>
    </item>
  </channel>
</rss>

