<?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: Join query in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/join-query/m-p/2508307#M567139</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;check the foll code..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select mara~matnr&lt;/P&gt;&lt;P&gt;          makt~maktx&lt;/P&gt;&lt;P&gt;into table itab&lt;/P&gt;&lt;P&gt;from mara inner join makt on mara&lt;SUB&gt;matnr = makt&lt;/SUB&gt;matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;Navneeth K.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 12 Jul 2007 05:27:38 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-07-12T05:27:38Z</dc:date>
    <item>
      <title>Join query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/join-query/m-p/2508304#M567136</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all&lt;/P&gt;&lt;P&gt;        anyone can send the syntax of join query&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jul 2007 05:25:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/join-query/m-p/2508304#M567136</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-12T05:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: Join query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/join-query/m-p/2508305#M567137</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;JOIN predicate &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A JOIN predicate specifies a JOIN. A JOIN predicate can be specified with or without one or with two OUTER JOIN indicators.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Syntax&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;join_predicate&amp;gt; ::= &lt;/P&gt;&lt;P&gt;&amp;lt;expression&amp;gt; [&amp;lt;outer_join_indicator&amp;gt;] &amp;lt;comp_op&amp;gt; &amp;lt;expression&amp;gt; [&amp;lt;outer_join_indicator&amp;gt;]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;outer_join_indicator&amp;gt; ::= &lt;SPAN __jive_emoticon_name="plus"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;expression, comp_op&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Explanation&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Each expression must contain a column specification. A column specification must exist for the first and second expression so that both specifications refer to different table names or reference names.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let x be the value of the first expression and y the value of the second expression. The values x and y must be comparable with one another.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The rules outlined under comparison predicate apply here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If at least one OUTER JOIN indicator is specified in a JOIN predicate of a search condition, the corresponding table expression must be based on exactly two tables, or the following has to apply:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OUTER JOIN indicators are only specified for one of the tables in the FROM clause. &lt;/P&gt;&lt;P&gt;All of the JOIN predicates in this table to just one other table contain the OUTER JOIN indicator. &lt;/P&gt;&lt;P&gt;All other JOIN predicates contain no OUTER JOIN indicators.&lt;/P&gt;&lt;P&gt;If a JOIN requires more than two tables for the QUERY specification and if one of the rules above cannot be observed, a QUERY expression can also be used in the FROM clause.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Only those rows from the table that have a counterpart of the comparison operator in the JOIN predicate specified in the table are transferred to the result table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The OUTER JOIN indicator must be specified on the side of the comparison operator where the other table is specified if each row in a table is to appear at least once in the result table.&lt;/P&gt;&lt;P&gt;If it is not possible to find at least one counterpart for a table row in the other table, this row is used to build a row for the result table. The NULL value is then used for the output columns which are formed from the columns in the other table.&lt;/P&gt;&lt;P&gt;Since the OUTER JOIN indicator can be specified on both sides of the comparison operator if the table expression is based on just two tables, it can be ensured that each line in both tables appears at least once in the result table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The JOIN predicate is a special case of the comparison predicate. The number of JOIN predicates in a search condition is limited to 128.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;JOIN predicate&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Model tables customer, reservation&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a reservation for the customer 'Porter'? If so, for what date?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT reservation.rno, customer.name, reservation.arrival, departure&lt;/P&gt;&lt;P&gt;FROM customer, reservation&lt;/P&gt;&lt;P&gt;WHERE customer.name = 'Porter' AND customer.cno = reservation.cno&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;RNO&lt;/P&gt;&lt;P&gt; NAME&lt;/P&gt;&lt;P&gt; ARRIVAL&lt;/P&gt;&lt;P&gt; DEPARTURE&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;100&lt;/P&gt;&lt;P&gt; Porter&lt;/P&gt;&lt;P&gt; 13.11.1998&lt;/P&gt;&lt;P&gt; 15.11.1998&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;110&lt;/P&gt;&lt;P&gt; Porter&lt;/P&gt;&lt;P&gt; 24.12.1998&lt;/P&gt;&lt;P&gt; 06.01.1999&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Specifying an OUTER JOIN indicator&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Model tables hotel, reservation&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;List all the hotels in Chicago for which a reservation exists and those for which a reservation does not exist. Missing reservation numbers are assigned a NULL value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT hotel.hno, hotel.name, reservation.rno&lt;/P&gt;&lt;P&gt;FROM hotel, reservation&lt;/P&gt;&lt;P&gt;WHERE hotel.city = 'Chicago' AND hotel.hno = reservation.hno &lt;SPAN __jive_emoticon_name="plus"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HNO&lt;/P&gt;&lt;P&gt; NAME&lt;/P&gt;&lt;P&gt; RNO&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;40&lt;/P&gt;&lt;P&gt; Eight Avenue&lt;/P&gt;&lt;P&gt; ?&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;50&lt;/P&gt;&lt;P&gt; Lake Michigan&lt;/P&gt;&lt;P&gt; 120&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;80&lt;/P&gt;&lt;P&gt; Midtown&lt;/P&gt;&lt;P&gt; 100&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;80&lt;/P&gt;&lt;P&gt; Midtown&lt;/P&gt;&lt;P&gt; 140&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;P&gt; &lt;/P&gt;&lt;P&gt;rewards point if useful....&lt;/P&gt;&lt;P&gt;ABhay.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jul 2007 05:26:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/join-query/m-p/2508305#M567137</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-12T05:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: Join query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/join-query/m-p/2508306#M567138</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;The join syntax represents a recursively nestable join expression. A join expression consists of a left-hand and a right- hand side, which are joined either by means of [INNER] JOIN or LEFT [OUTER] JOIN. Depending on the type of join, a join expression can be either an inner (INNER) or an outer (LEFT OUTER) join. Every join expression can be enclosed in round brackets. If a join expression is used, the SELECT command circumvents SAP buffering. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On the left-hand side, either a single database table, a view dbtab_left, or a join expression join can be specified. On the right-hand side, a single database table or a view dbtab_right as well as join conditions join_cond can be specified after ON. In this way, a maximum of 24 join expressions that join 25 database tables or views with each other can be specified after FROM. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AS can be used to specify an alternative table name tabalias for each of the specified database table names or for every view. A database table or a view can occur multiple times within a join expression and, in this case, have various alternative names. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The syntax of the join conditions join_cond is the same as that of the sql_cond conditions after the addition WHERE, with the following differences: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At least one comparison must be specified after ON. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Individual comparisons may be joined using AND only. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All comparisons must contain a column in the database table or the view dbtab_right on the right-hand side as an operand. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The following additions not be used: NOT, LIKE, IN. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;No sub-queries may be used. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For outer joins, only equality comparisons (=, EQ) are possible. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If an outer join occurs after FROM, the join condition of every join expression must contain at least one comparison between columns on the left-hand and the right-hand side. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In outer joins, all comparisons that contain columns as operands in the database table or the view dbtab_right on the right-hand side must be specified in the corresponding join condition. In the WHERE condition of the same SELECT command, these columns are not allowed as operands. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Resulting set for inner join &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The inner join joins the columns of every selected line on the left- hand side with the columns of all lines on the right-hand side that jointly fulfil the join_cond condition. A line in the resulting set is created for every such line on the right-hand side. The content of the column on the left-hand side may be duplicated in this case. If none of the lines on the right-hand side fulfils the join_cond condition, no line is created in the resulting set. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Resulting set for outer join &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The outer join basically creates the same resulting set as the inner join, with the difference that at least one line is created in the resulting set for every selected line on the left-hand side, even if no line on the right-hand side fulfils the join_cond condition. The columns on the right-hand side that do not fulfil the join_cond condition are filled with null values. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note &lt;/P&gt;&lt;P&gt;If the same column name occurs in several database tables in a join expression, they have to be identified in all remaining additions of the SELECT statement by using the column selector ~. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example &lt;/P&gt;&lt;P&gt;Join the columns carrname, connid, fldate of the database tables scarr, spfli and sflight by means of two inner joins. A list is created of the flights from p_cityfr to p_cityto. Alternative names are used for every table. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PARAMETERS: p_cityfr TYPE spfli-cityfrom, &lt;/P&gt;&lt;P&gt;            p_cityto TYPE spfli-cityto. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF wa, &lt;/P&gt;&lt;P&gt;         fldate TYPE sflight-fldate, &lt;/P&gt;&lt;P&gt;         carrname TYPE scarr-carrname, &lt;/P&gt;&lt;P&gt;         connid   TYPE spfli-connid, &lt;/P&gt;&lt;P&gt;       END OF wa. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA itab LIKE SORTED TABLE OF wa &lt;/P&gt;&lt;P&gt;               WITH UNIQUE KEY fldate carrname connid. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT c&lt;SUB&gt;carrname p&lt;/SUB&gt;connid f~fldate &lt;/P&gt;&lt;P&gt;       INTO CORRESPONDING FIELDS OF TABLE itab &lt;/P&gt;&lt;P&gt;       FROM ( ( scarr AS c &lt;/P&gt;&lt;P&gt;         INNER JOIN spfli AS p ON p&lt;SUB&gt;carrid   = c&lt;/SUB&gt;carrid &lt;/P&gt;&lt;P&gt;                              AND p~cityfrom = p_cityfr &lt;/P&gt;&lt;P&gt;                              AND p~cityto   = p_cityto ) &lt;/P&gt;&lt;P&gt;         INNER JOIN sflight AS f ON f&lt;SUB&gt;carrid = p&lt;/SUB&gt;carrid &lt;/P&gt;&lt;P&gt;                                AND f&lt;SUB&gt;connid = p&lt;/SUB&gt;connid ). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT itab INTO wa. &lt;/P&gt;&lt;P&gt;  WRITE: / wa-fldate, wa-carrname, wa-connid. &lt;/P&gt;&lt;P&gt;ENDLOOP. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example &lt;/P&gt;&lt;P&gt;Join the columns carrid, carrname and connid of the database tables scarr and spfli using an outer join. The column connid is set to the null value for all flights that do not fly from p_cityfr. This null value is then converted to the appropriate initial value when it is transferred to the assigned data object. The LOOP returns all airlines that do not fly from p_cityfr. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PARAMETERS p_cityfr TYPE spfli-cityfrom. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF wa, &lt;/P&gt;&lt;P&gt;        carrid   TYPE scarr-carrid, &lt;/P&gt;&lt;P&gt;        carrname TYPE scarr-carrname, &lt;/P&gt;&lt;P&gt;        connid   TYPE spfli-connid, &lt;/P&gt;&lt;P&gt;      END OF wa, &lt;/P&gt;&lt;P&gt;      itab LIKE SORTED TABLE OF wa &lt;/P&gt;&lt;P&gt;                WITH NON-UNIQUE KEY carrid. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT s&lt;SUB&gt;carrid s&lt;/SUB&gt;carrname p~connid &lt;/P&gt;&lt;P&gt;       INTO CORRESPONDING FIELDS OF TABLE itab &lt;/P&gt;&lt;P&gt;       FROM scarr AS s &lt;/P&gt;&lt;P&gt;       LEFT OUTER JOIN spfli AS p ON s&lt;SUB&gt;carrid   =  p&lt;/SUB&gt;carrid &lt;/P&gt;&lt;P&gt;                                  AND p~cityfrom = p_cityfr. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT itab INTO wa. &lt;/P&gt;&lt;P&gt;  IF wa-connid = '0000'. &lt;/P&gt;&lt;P&gt;    WRITE: / wa-carrid, wa-carrname. &lt;/P&gt;&lt;P&gt;  ENDIF. &lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sesh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jul 2007 05:26:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/join-query/m-p/2508306#M567138</guid>
      <dc:creator>seshatalpasai_madala</dc:creator>
      <dc:date>2007-07-12T05:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: Join query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/join-query/m-p/2508307#M567139</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;check the foll code..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select mara~matnr&lt;/P&gt;&lt;P&gt;          makt~maktx&lt;/P&gt;&lt;P&gt;into table itab&lt;/P&gt;&lt;P&gt;from mara inner join makt on mara&lt;SUB&gt;matnr = makt&lt;/SUB&gt;matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;Navneeth K.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jul 2007 05:27:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/join-query/m-p/2508307#M567139</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-12T05:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: Join query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/join-query/m-p/2508308#M567140</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When multiple SAP tables are logically joined, it is always advisable to use inner join to read the data from them. This certainly reduces the load on the network. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let us take an example of 2 tables, zairln and zflight. The table zairln has the field airln, which is the airline code and the field lnnam, which is the name of the airline. The table zflight has the field airln, the airline code and other fields which hold the details of the flights that an airline operates.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since these 2 tables a re logically joined by the airln field, it is advisable to use the inner join.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;             Select a&lt;SUB&gt;airln a&lt;/SUB&gt;lnnam b&lt;SUB&gt;fligh b&lt;/SUB&gt;cntry into table int_airdet&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;            From zairln as a inner join zflight as b on a&lt;SUB&gt;airln = b&lt;/SUB&gt;airln.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; In order to restrict the data as per the selection criteria, a where clause can be added to the above inner join&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rewards point if useful....&lt;/P&gt;&lt;P&gt;abhay.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jul 2007 05:27:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/join-query/m-p/2508308#M567140</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-12T05:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: Join query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/join-query/m-p/2508309#M567141</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Check this:&lt;/P&gt;&lt;P&gt;&lt;A href="http://help.sap.com/saphelp_46c/helpdata/EN/50/a71ec8f65911d296390000e82de14a/content.htm" target="test_blank"&gt;http://help.sap.com/saphelp_46c/helpdata/EN/50/a71ec8f65911d296390000e82de14a/content.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Reward if useful!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jul 2007 05:27:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/join-query/m-p/2508309#M567141</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-12T05:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: Join query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/join-query/m-p/2508310#M567142</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Select statement with inner join is taking forever &lt;/P&gt;&lt;P&gt;Following is the select stmt which is taking forever. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  SELECT MKPF&lt;SUB&gt;BUDAT MKPF&lt;/SUB&gt;CPUTM &lt;/P&gt;&lt;P&gt;     MSEG&lt;SUB&gt;MATNR MSEG&lt;/SUB&gt;WERKS MSEG~EBELN  &lt;/P&gt;&lt;P&gt;      MSEG&lt;SUB&gt;EBELP  MSEG&lt;/SUB&gt;ERFMG &lt;/P&gt;&lt;P&gt;           INTO CORRESPONDING FIELDS OF TABLE  &lt;/P&gt;&lt;P&gt;           W_DTL_INVOICE &lt;/P&gt;&lt;P&gt;           FROM MKPF INNER JOIN MSEG &lt;/P&gt;&lt;P&gt;                  ON  MKPF&lt;SUB&gt;MBLNR = MSEG&lt;/SUB&gt;MBLNR &lt;/P&gt;&lt;P&gt;                  AND MKPF&lt;SUB&gt;MJAHR = MSEG&lt;/SUB&gt;MJAHR &lt;/P&gt;&lt;P&gt;           WHERE MKPF~BUDAT &amp;gt; '20040721' AND &lt;/P&gt;&lt;P&gt;                 MSEG~BWART = '101'       AND &lt;/P&gt;&lt;P&gt;                 MSEG~BUKRS = '1733'. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It does not have much records. &lt;/P&gt;&lt;P&gt;Can somebody let me know how to fine tune this statement. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kasi &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have gone through the same problem last year. This is the solution I made. My program spended more than an hour to  &lt;/P&gt;&lt;P&gt;select 5000 records from mkpf inner mseg(From a range of 100000 records) .  &lt;/P&gt;&lt;P&gt;Now it needs less than 15 seconds to perform the same task.  &lt;/P&gt;&lt;P&gt;Try this changes  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;UL&gt;&lt;LI level="2" type="ul"&gt;&lt;P&gt;in global data add these two hashed tables&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: begin of wa_mkpfmseg,&lt;/P&gt;&lt;P&gt;      mblnr like mkpf-mblnr,&lt;/P&gt;&lt;P&gt;      mjahr like mkpf-mjahr,&lt;/P&gt;&lt;P&gt;      zeile like mseg-zeile,&lt;/P&gt;&lt;P&gt;      bukrs like mseg-bukrs&lt;/P&gt;&lt;P&gt;        bwart like mseg-bwart,&lt;/P&gt;&lt;P&gt;        budat like mkpf-budat,&lt;/P&gt;&lt;P&gt;      cputm like mkpf-cputm,&lt;/P&gt;&lt;P&gt;        matnr like mseg-matnr,&lt;/P&gt;&lt;P&gt;     werks like mseg-werks,&lt;/P&gt;&lt;P&gt;        ebeln like mseg-ebeln,&lt;/P&gt;&lt;P&gt;        ebelp like mseg-ebelp,&lt;/P&gt;&lt;P&gt;        erfmg like mseg-erfmg,&lt;/P&gt;&lt;P&gt;        end of wa_mkpfmseg.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data ht_mkpfmseg like hashed table of wa_mkpfmseg&lt;/P&gt;&lt;P&gt;         with unique key mblnr mjahr zeile&lt;/P&gt;&lt;P&gt;       with header line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: begin of wa_mkpfmsegSel,&lt;/P&gt;&lt;P&gt;        budat like mkpf-budat,&lt;/P&gt;&lt;P&gt;      cputm like mkpf-cputm,&lt;/P&gt;&lt;P&gt;        matnr like mseg-matnr,&lt;/P&gt;&lt;P&gt;      werks like mseg-werks,&lt;/P&gt;&lt;P&gt;        ebeln like mseg-ebeln,&lt;/P&gt;&lt;P&gt;        ebelp like mseg-ebelp,&lt;/P&gt;&lt;P&gt;        erfmg like mseg-erfmg,&lt;/P&gt;&lt;P&gt;        end of wa_mkpfmseg.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data ht_mkpfmsegSel like hashed table of wa_mkpfmsegSel&lt;/P&gt;&lt;P&gt;         with unique key budat cputm matnr werks ebeln ebelp &lt;/P&gt;&lt;P&gt;       with header line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;UL&gt;&lt;LI level="2" type="ul"&gt;&lt;P&gt;change your select sentence to look like this:&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;&lt;P&gt;  select mkpf~mblnr&lt;/P&gt;&lt;P&gt;              mkpf~mjahr&lt;/P&gt;&lt;P&gt;              mseg~zeile&lt;/P&gt;&lt;P&gt;            mseg~bukrs &lt;/P&gt;&lt;P&gt;           mseg~bwart&lt;/P&gt;&lt;P&gt;        MKPF&lt;SUB&gt;BUDAT MKPF&lt;/SUB&gt;CPUTM&lt;/P&gt;&lt;P&gt;             MSEG&lt;SUB&gt;MATNR MSEG&lt;/SUB&gt;WERKS MSEG~EBELN &lt;/P&gt;&lt;P&gt;             MSEG&lt;SUB&gt;EBELP  MSEG&lt;/SUB&gt;ERFMG&lt;/P&gt;&lt;P&gt;                  INTO  TABLE ht_mkpfmseg&lt;/P&gt;&lt;P&gt;                  FROM MKPF INNER JOIN MSEG&lt;/P&gt;&lt;P&gt;                       ON   mkpf&lt;SUB&gt;mandt = mseg&lt;/SUB&gt;mandt &lt;/P&gt;&lt;P&gt;                  AND    MKPF&lt;SUB&gt;MBLNR = MSEG&lt;/SUB&gt;MBLNR&lt;/P&gt;&lt;P&gt;                  AND MKPF&lt;SUB&gt;MJAHR = MSEG&lt;/SUB&gt;MJAHR&lt;/P&gt;&lt;P&gt;                 where mkpf~budat &amp;gt; '20040721'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  loop at ht_mkpfmseg.&lt;/P&gt;&lt;P&gt;                check ht_mkpfmseg-bukrs = '1733' and ht_mkpfmseg-bwart = '101'          &lt;/P&gt;&lt;P&gt;                read table ht_mkpfmsegsel with table key   &lt;/P&gt;&lt;P&gt;                     budat = ht_mkpfmseg-budat&lt;/P&gt;&lt;P&gt;                     cputm = ht_mkpfmseg-cputm                                                                                &lt;/P&gt;&lt;P&gt;matnr  = ht_mkpfmseg-matnr          &lt;/P&gt;&lt;P&gt;                     werks  = ht_mkpfmseg-werks                                                   &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;                     ebeln = ht_mkpfmseg-ebeln   &lt;/P&gt;&lt;P&gt;                     ebelp  = ht_mkpfmseg-ebelp&lt;/P&gt;&lt;P&gt;                transporting erfmg.&lt;/P&gt;&lt;P&gt;                if sy-subrc &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt;                   move-corresponding ht_mkpfmseg to ht_mkpfmsegsel.&lt;/P&gt;&lt;P&gt;                   insert table ht_mkpfmsegsel.&lt;/P&gt;&lt;P&gt;                else.&lt;/P&gt;&lt;P&gt;                        ht_mkpfmsegSel-budat = ht_mkpfmseg-budat.&lt;/P&gt;&lt;P&gt;                        ht_mkpfmsegSel-cputm = ht_mkpfmseg-cputm.&lt;/P&gt;&lt;P&gt;                        ht_mkpfmsegSel-matnr = ht_mkpfmseg-matnr,&lt;/P&gt;&lt;P&gt;                        ht_mkpfmsegSel-werks = ht_mkpfmseg-werks.&lt;/P&gt;&lt;P&gt;                        ht_mkpfmsegSel-ebeln = ht_mkpfmseg-ebeln.&lt;/P&gt;&lt;P&gt;                        ht_mkpfmsegSel-ebelp = ht_mkpfmseg-ebelp.&lt;/P&gt;&lt;P&gt;                        add ht_mkpfmseg-erfmg to ht_mkpfmsegSel-erfmg.&lt;/P&gt;&lt;P&gt;                        modify table ht_mkpfmsegSel transporting erfmg.&lt;/P&gt;&lt;P&gt;                endif.&lt;/P&gt;&lt;P&gt;  endloop.&lt;/P&gt;&lt;P&gt;  " at this point ht_mkpfmsegSel has the data collected that you want. &lt;/P&gt;&lt;P&gt;  loop at ht_mkpfmsegSel.&lt;/P&gt;&lt;P&gt;        .... Here put the code between your select ... endselect.&lt;/P&gt;&lt;P&gt;   endloop.&lt;/P&gt;&lt;P&gt;This should run faster because of the next reasons: &lt;/P&gt;&lt;P&gt;1. you're not distracting the sql optimizer when it analizes the sql where clause.  It makes use of the first index declared  &lt;/P&gt;&lt;P&gt;on mkpf (budat-mblnr)-  &lt;/P&gt;&lt;P&gt;2. the data is selected into a hashed table which are the faster access tables provided by SAP from 4.0 up to 4.6c  &lt;/P&gt;&lt;P&gt;(I don't know about 4.7)  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. As the select isn't restricting bukrs and bwart (but there is a good reason on this: it's faster to read 100000 records into  &lt;/P&gt;&lt;P&gt;a hashed table and then filter the 80000 unwanted than to select the 20000 records via non index fields in the where clause.  &lt;/P&gt;&lt;P&gt;I tested it in my own programs). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this help you. If not, just let us know.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rewards point if useful......&lt;/P&gt;&lt;P&gt;Kind regards &lt;/P&gt;&lt;P&gt;abhay.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jul 2007 05:29:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/join-query/m-p/2508310#M567142</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-12T05:29:12Z</dc:date>
    </item>
    <item>
      <title>Re: Join query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/join-query/m-p/2508311#M567143</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;here is an example of inner join.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; SELECT&lt;/P&gt;&lt;P&gt;     a~omeng &lt;/P&gt;&lt;P&gt;     b~vgbel &lt;/P&gt;&lt;P&gt;     b~vgpos &lt;/P&gt;&lt;P&gt;     c~vbeln &lt;/P&gt;&lt;P&gt;     c~posnr &lt;/P&gt;&lt;P&gt;     c~klmeng &lt;/P&gt;&lt;P&gt;     c~netwr &lt;/P&gt;&lt;P&gt;INTO CORRESPONDING FIELDS OF TABLE it_tab&lt;/P&gt;&lt;P&gt;FROM vbbe AS a INNER JOIN lips AS b&lt;/P&gt;&lt;P&gt;   ON a&lt;SUB&gt;vbeln = b&lt;/SUB&gt;vbeln AND a&lt;SUB&gt;posnr = b&lt;/SUB&gt;posnr&lt;/P&gt;&lt;P&gt;                          INNER JOIN vbap AS c&lt;/P&gt;&lt;P&gt;   ON b&lt;SUB&gt;vgbel = c&lt;/SUB&gt;vbeln AND b&lt;SUB&gt;vgpos = c&lt;/SUB&gt;posnr&lt;/P&gt;&lt;P&gt;WHERE a~vbtyp = 'J'&lt;/P&gt;&lt;P&gt;      AND a~werks LIKE '21%'&lt;/P&gt;&lt;P&gt;      AND c~klmeng &amp;gt; 0.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jul 2007 05:54:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/join-query/m-p/2508311#M567143</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-12T05:54:49Z</dc:date>
    </item>
  </channel>
</rss>

