<?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: Cross Join in ABAP Open SQL in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/cross-join-in-abap-open-sql/m-p/1322640#M165942</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If cross joins are the same as inner joins, then yes you can do that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Select * into corresponding fields of table itab
             from mara
                  inner join marc
                       on mara~matnr = marc~matnr
                                 where matnr in s_matnr.&lt;/CODE&gt;&lt;/PRE&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>Wed, 31 May 2006 15:25:44 GMT</pubDate>
    <dc:creator>RichHeilman</dc:creator>
    <dc:date>2006-05-31T15:25:44Z</dc:date>
    <item>
      <title>Cross Join in ABAP Open SQL</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cross-join-in-abap-open-sql/m-p/1322637#M165939</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi guys!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to implement a CROSS JOIN (cartesian product) based on two tables. To my understanding there is no construct to implement a cross join in OPEN SQL. So the question is first is this correct? And secondly in which way would you then implement a cross join of two tables with the constructs at hand in ABAP?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have come up with the following solution of cross joining two tables, but would like to know if there is a better (not so ugly way).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;SELECT * FROM tab1 AS t1 JOIN tab2 AS t2 ON t1&lt;SUB&gt;mandt = t2&lt;/SUB&gt;mandt INTO CORRESPONDING FIELDS OF itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that this only works if the tables tab1 and tab2 is client dependent.&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>Wed, 31 May 2006 15:19:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cross-join-in-abap-open-sql/m-p/1322637#M165939</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-05-31T15:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: Cross Join in ABAP Open SQL</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cross-join-in-abap-open-sql/m-p/1322638#M165940</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Christian,&lt;/P&gt;&lt;P&gt;  What do you exactly mean by cross join?&lt;/P&gt;&lt;P&gt;I don't find anything ugly about your statement..;-)..&lt;/P&gt;&lt;P&gt;Thats the way to do it and moreover it doesn't make any sense to pull the data from two disjoint tables(Which have no field in common(MANDT is one such common field for all client dependent tables).&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ravi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 May 2006 15:25:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cross-join-in-abap-open-sql/m-p/1322638#M165940</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-05-31T15:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: Cross Join in ABAP Open SQL</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cross-join-in-abap-open-sql/m-p/1322639#M165941</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Well if you want to join two tables with out any condition (other than MANDT), then I guess you are on the right track.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Else, work around could be to fetch the data from the two tables indivudally into internal tables and then loop at one of the internal table and then loop at the table without any conditions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ravi&lt;/P&gt;&lt;P&gt;Note :Please mark the helpful answers&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 May 2006 15:25:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cross-join-in-abap-open-sql/m-p/1322639#M165941</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-05-31T15:25:39Z</dc:date>
    </item>
    <item>
      <title>Re: Cross Join in ABAP Open SQL</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cross-join-in-abap-open-sql/m-p/1322640#M165942</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If cross joins are the same as inner joins, then yes you can do that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Select * into corresponding fields of table itab
             from mara
                  inner join marc
                       on mara~matnr = marc~matnr
                                 where matnr in s_matnr.&lt;/CODE&gt;&lt;/PRE&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>Wed, 31 May 2006 15:25:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cross-join-in-abap-open-sql/m-p/1322640#M165942</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2006-05-31T15:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: Cross Join in ABAP Open SQL</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cross-join-in-abap-open-sql/m-p/1322641#M165943</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi and thanks alot for the quick answers!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, what I mean with a cross join is a join without condition. Which will result in the cartesian product (all combinations) being selected from tab1 and tab2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This would be useful for selecting all possible material / location combinations based on a table with materials and a table with locations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there no better way of doing this than using the mandt column to implement a "always true" condition as I described above?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/ Christian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 May 2006 15:34:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cross-join-in-abap-open-sql/m-p/1322641#M165943</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-05-31T15:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: Cross Join in ABAP Open SQL</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cross-join-in-abap-open-sql/m-p/1322642#M165944</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; i think there no use doing cross join.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what u can do is select data in 2 different internal tables. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in this way u will have all the data but in 2 different internal tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it will space effective.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;later in ur program u can use read statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i dont know why u want cross join.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 May 2006 15:38:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cross-join-in-abap-open-sql/m-p/1322642#M165944</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-05-31T15:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: Cross Join in ABAP Open SQL</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cross-join-in-abap-open-sql/m-p/1322643#M165945</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Christian,&lt;/P&gt;&lt;P&gt;   The other way is to go for two different select statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select * from tab1 into table it_tab1 where &amp;lt;where con&amp;gt;.&lt;/P&gt;&lt;P&gt;select * from tab2 into table it_tab2 where &amp;lt;where con&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at it_itab1.&lt;/P&gt;&lt;P&gt;loop at it_itab2.&lt;/P&gt;&lt;P&gt;move-corresponding it_itab1 to it_final.&lt;/P&gt;&lt;P&gt;move-corresponding it_itab2 to it_final.&lt;/P&gt;&lt;P&gt;append it_final.&lt;/P&gt;&lt;P&gt;clear it_final.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Where it_final has all the fields from tab1 and tab2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ravi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;P.S: Don't know how ugly is this..;-)..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 May 2006 15:40:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cross-join-in-abap-open-sql/m-p/1322643#M165945</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-05-31T15:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: Cross Join in ABAP Open SQL</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cross-join-in-abap-open-sql/m-p/1322644#M165946</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi christian,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;declare it_final with all the fiels in tables itab1 and itab2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select * from itab1 into corresponding fields of table it_final.&lt;/P&gt;&lt;P&gt;if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;select * from itab2 into corresponding fields of table it_final.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at it_final.&lt;/P&gt;&lt;P&gt;write:/ it_final-fd1,...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;hope this helps.&lt;/P&gt;&lt;P&gt;Do reward if helpful.&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;keerthi.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 May 2006 16:08:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cross-join-in-abap-open-sql/m-p/1322644#M165946</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-05-31T16:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: Cross Join in ABAP Open SQL</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/cross-join-in-abap-open-sql/m-p/1322645#M165947</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Christian,&lt;/P&gt;&lt;P&gt;  There's no cross join construct in abap. Join statement results in a cartesin product rarely because of completely obsolete statistics missing selection or join conditions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try the following join to get result similar to cartesian product&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select tab1&lt;SUB&gt;location tab2&lt;/SUB&gt;matnr into itab &lt;/P&gt;&lt;P&gt;  from tab1 join tab2 on tab1&lt;SUB&gt;location ne tab2&lt;/SUB&gt;matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you really want to implement cross join, use native sql, try the following code, &lt;/P&gt;&lt;P&gt;beware of cartesian products, Basis folks doesn't like em.... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: begin of itab occurs 0,&lt;/P&gt;&lt;P&gt;  loc like tab1-sloc&lt;/P&gt;&lt;P&gt;  matnr like tab2-matnr,&lt;/P&gt;&lt;P&gt;end of itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;exec sql performing append_itab.&lt;/P&gt;&lt;P&gt;  select a.loc, b.matnr&lt;/P&gt;&lt;P&gt;    into :itab&lt;/P&gt;&lt;P&gt;    from tab1 a&lt;/P&gt;&lt;P&gt;    cross join tab2 b&lt;/P&gt;&lt;P&gt;endexec.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;form append_itab.&lt;/P&gt;&lt;P&gt;  append itab.&lt;/P&gt;&lt;P&gt;endform.                &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Sridhar.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Jun 2006 01:17:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/cross-join-in-abap-open-sql/m-p/1322645#M165947</guid>
      <dc:creator>sridhar_k1</dc:creator>
      <dc:date>2006-06-01T01:17:49Z</dc:date>
    </item>
  </channel>
</rss>

