<?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: How to join multiple tables ! in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-join-multiple-tables/m-p/3142989#M747070</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Inner join&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF p_bsart IS INITIAL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT ekko~bukrs&lt;/P&gt;&lt;P&gt;ekko~lifnr&lt;/P&gt;&lt;P&gt;ekko~ebeln&lt;/P&gt;&lt;P&gt;ekko~waers&lt;/P&gt;&lt;P&gt;ekko~bsart&lt;/P&gt;&lt;P&gt;ekko~ekorg&lt;/P&gt;&lt;P&gt;ekko~ekgrp&lt;/P&gt;&lt;P&gt;ekpo~ebelp&lt;/P&gt;&lt;P&gt;ekpo~txz01&lt;/P&gt;&lt;P&gt;ekpo~matnr&lt;/P&gt;&lt;P&gt;ekpo~werks&lt;/P&gt;&lt;P&gt;ekpo~menge&lt;/P&gt;&lt;P&gt;ekpo~meins&lt;/P&gt;&lt;P&gt;ekpo~netpr&lt;/P&gt;&lt;P&gt;ekpo~netwr&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;INTO TABLE t_itab1 FROM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ekko INNER JOIN ekpo ON ekko&lt;SUB&gt;ebeln = ekpo&lt;/SUB&gt;ebeln&lt;/P&gt;&lt;P&gt;WHERE ekko~ebeln IN s_ebeln AND&lt;/P&gt;&lt;P&gt;ekko~bukrs IN s_bukrs AND&lt;/P&gt;&lt;P&gt;ekko~lifnr IN s_lifnr AND&lt;/P&gt;&lt;P&gt;ekko~ekorg IN s_ekorg AND&lt;/P&gt;&lt;P&gt;ekko~ekgrp IN s_ekgrp AND&lt;/P&gt;&lt;P&gt;ekpo~matnr IN s_matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The difference between an INNER JOIN and an OUTER JOIN is the following. If a query on an INNER JOIN of VBAK (outer table) and VBAP (inner table) finds a record in VBAK but no matching records in VBAP, then no data is retrieved from the database because the inner table is empty. If you still want to keep VBAK rows for which there are no matching VBAP rows, you need to use the OUTER JOIN construct available in ABAP/4 Open SQL in 4.x..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Syntax&lt;/P&gt;&lt;P&gt;... [(] {dbtab_left [AS tabalias_left]} | join&lt;/P&gt;&lt;P&gt;{[INNER] JOIN}|{LEFT [OUTER] JOIN}&lt;/P&gt;&lt;P&gt;{dbtab_right [AS tabalias_right] ON join_cond} [)] ... .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&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 language elements may not be used: BETWEEN, 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;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;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;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 17 Dec 2007 12:09:30 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-12-17T12:09:30Z</dc:date>
    <item>
      <title>How to join multiple tables !</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-join-multiple-tables/m-p/3142986#M747067</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Give me the Example to join multiple tables 1&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Dec 2007 12:05:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-join-multiple-tables/m-p/3142986#M747067</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-17T12:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to join multiple tables !</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-join-multiple-tables/m-p/3142987#M747068</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;see this example code.&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;rgds,&lt;/P&gt;&lt;P&gt;bharat.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Dec 2007 12:08:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-join-multiple-tables/m-p/3142987#M747068</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-17T12:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to join multiple tables !</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-join-multiple-tables/m-p/3142988#M747069</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 link..&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sap-img.com/ab010.htm" target="test_blank"&gt;http://www.sap-img.com/ab010.htm&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Dec 2007 12:08:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-join-multiple-tables/m-p/3142988#M747069</guid>
      <dc:creator>former_member188829</dc:creator>
      <dc:date>2007-12-17T12:08:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to join multiple tables !</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-join-multiple-tables/m-p/3142989#M747070</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Inner join&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF p_bsart IS INITIAL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT ekko~bukrs&lt;/P&gt;&lt;P&gt;ekko~lifnr&lt;/P&gt;&lt;P&gt;ekko~ebeln&lt;/P&gt;&lt;P&gt;ekko~waers&lt;/P&gt;&lt;P&gt;ekko~bsart&lt;/P&gt;&lt;P&gt;ekko~ekorg&lt;/P&gt;&lt;P&gt;ekko~ekgrp&lt;/P&gt;&lt;P&gt;ekpo~ebelp&lt;/P&gt;&lt;P&gt;ekpo~txz01&lt;/P&gt;&lt;P&gt;ekpo~matnr&lt;/P&gt;&lt;P&gt;ekpo~werks&lt;/P&gt;&lt;P&gt;ekpo~menge&lt;/P&gt;&lt;P&gt;ekpo~meins&lt;/P&gt;&lt;P&gt;ekpo~netpr&lt;/P&gt;&lt;P&gt;ekpo~netwr&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;INTO TABLE t_itab1 FROM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ekko INNER JOIN ekpo ON ekko&lt;SUB&gt;ebeln = ekpo&lt;/SUB&gt;ebeln&lt;/P&gt;&lt;P&gt;WHERE ekko~ebeln IN s_ebeln AND&lt;/P&gt;&lt;P&gt;ekko~bukrs IN s_bukrs AND&lt;/P&gt;&lt;P&gt;ekko~lifnr IN s_lifnr AND&lt;/P&gt;&lt;P&gt;ekko~ekorg IN s_ekorg AND&lt;/P&gt;&lt;P&gt;ekko~ekgrp IN s_ekgrp AND&lt;/P&gt;&lt;P&gt;ekpo~matnr IN s_matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The difference between an INNER JOIN and an OUTER JOIN is the following. If a query on an INNER JOIN of VBAK (outer table) and VBAP (inner table) finds a record in VBAK but no matching records in VBAP, then no data is retrieved from the database because the inner table is empty. If you still want to keep VBAK rows for which there are no matching VBAP rows, you need to use the OUTER JOIN construct available in ABAP/4 Open SQL in 4.x..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Syntax&lt;/P&gt;&lt;P&gt;... [(] {dbtab_left [AS tabalias_left]} | join&lt;/P&gt;&lt;P&gt;{[INNER] JOIN}|{LEFT [OUTER] JOIN}&lt;/P&gt;&lt;P&gt;{dbtab_right [AS tabalias_right] ON join_cond} [)] ... .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&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 language elements may not be used: BETWEEN, 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;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;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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Dec 2007 12:09:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-join-multiple-tables/m-p/3142989#M747070</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-17T12:09:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to join multiple tables !</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-join-multiple-tables/m-p/3142990#M747071</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;   U can Inner or outer join to join the tables but it will affect on performance so better to use FOR ALL ENTRIES&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EX of inner join&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; SELECT a~vbeln                            "Billing document&lt;/P&gt;&lt;P&gt;         a~fkdat                            "Billing date&lt;/P&gt;&lt;P&gt;         a~fktyp                            "Billing category&lt;/P&gt;&lt;P&gt;         a~fkart                            "Billing type&lt;/P&gt;&lt;P&gt;         a~vtweg                            "Distribution channel&lt;/P&gt;&lt;P&gt;         a~knumv                            "Number of doc condition&lt;/P&gt;&lt;P&gt;         b~posnr                            "Billing item&lt;/P&gt;&lt;P&gt;         b~matnr                            "Material Number&lt;/P&gt;&lt;P&gt;         b~werks                            "Plant&lt;/P&gt;&lt;P&gt;         b~vgbel                            "Referance&lt;/P&gt;&lt;P&gt;         b~kzwi2                            "Subtotal 2&lt;/P&gt;&lt;P&gt;         b~wavwr                            "Cost in document currency&lt;/P&gt;&lt;P&gt;         c~kunnr                            "Partner function&lt;/P&gt;&lt;P&gt;         FROM vbrk AS a&lt;/P&gt;&lt;P&gt;         INNER JOIN vbrp AS b&lt;/P&gt;&lt;P&gt;         ON a&lt;SUB&gt;vbeln EQ b&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;         INNER JOIN vbpa AS c&lt;/P&gt;&lt;P&gt;         ON  b&lt;SUB&gt;vbeln EQ c&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;         INTO CORRESPONDING FIELDS OF TABLE it_vbrp&lt;/P&gt;&lt;P&gt;         WHERE fkdat IN s_erdat&lt;/P&gt;&lt;P&gt;         AND   parvw EQ 'ZS'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  IF sy-subrc EQ 0.&lt;/P&gt;&lt;P&gt;*--Sort table by Referance&lt;/P&gt;&lt;P&gt;    SORT it_vbrp BY vgbel1.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ex of For all entries&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;      Form  SUB_READ_VBRK&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      text&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FORM sub_read_vbrk.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  SELECT vbeln&lt;/P&gt;&lt;P&gt;         rplnr&lt;/P&gt;&lt;P&gt;         bukrs&lt;/P&gt;&lt;P&gt;         FROM vbrk&lt;/P&gt;&lt;P&gt;         INTO TABLE it_vbrk&lt;/P&gt;&lt;P&gt;         WHERE vbeln IN s_vbeln&lt;/P&gt;&lt;P&gt;         AND   rplnr NE ' '.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  IF sy-subrc EQ 0.&lt;/P&gt;&lt;P&gt;    SORT it_vbrk BY rplnr.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDFORM.                    " SUB_READ_VBRK&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;      Form  SUB_READ_FPLTC&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      text&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FORM sub_read_fpltc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  IF NOT it_vbrk[] IS INITIAL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    SELECT fplnr&lt;/P&gt;&lt;P&gt;           fpltr&lt;/P&gt;&lt;P&gt;           ccnum&lt;/P&gt;&lt;P&gt;           FROM fpltc&lt;/P&gt;&lt;P&gt;           INTO TABLE it_fpltc&lt;/P&gt;&lt;P&gt;           FOR ALL ENTRIES IN it_vbrk&lt;/P&gt;&lt;P&gt;           WHERE fplnr EQ it_vbrk-rplnr&lt;/P&gt;&lt;P&gt;           AND   ccins EQ 'GIFC'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    IF sy-subrc EQ 0.&lt;/P&gt;&lt;P&gt;      SORT it_fpltc BY fplnr.&lt;/P&gt;&lt;P&gt;    ENDIF.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDFORM.                    " SUB_READ_FPLTC&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;      Form  SUB_COLLECT_DATA&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      text&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FORM sub_collect_data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*--Local variables&lt;/P&gt;&lt;P&gt;  DATA : lv_count(3) TYPE c.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  IF NOT it_fpltc[] IS INITIAL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    LOOP AT it_fpltc INTO wa_fpltc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      lv_count = wa_fpltc-fpltr+3(3).&lt;/P&gt;&lt;P&gt;      wa_final-ccnum = wa_fpltc-ccnum.&lt;/P&gt;&lt;P&gt;      wa_final-rfzei = lv_count.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      CLEAR : wa_vbrk.&lt;/P&gt;&lt;P&gt;      READ TABLE it_vbrk INTO wa_vbrk WITH KEY rplnr = wa_fpltc-fplnr&lt;/P&gt;&lt;P&gt;                                               BINARY SEARCH.&lt;/P&gt;&lt;P&gt;      IF sy-subrc EQ 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;        wa_final-vbeln = wa_vbrk-vbeln.&lt;/P&gt;&lt;P&gt;        wa_final-bukrs = wa_vbrk-bukrs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      APPEND wa_final TO it_final.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      CLEAR : wa_vbrk,&lt;/P&gt;&lt;P&gt;              wa_fpltc,&lt;/P&gt;&lt;P&gt;              lv_count.&lt;/P&gt;&lt;P&gt;    ENDLOOP.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDFORM.                    " SUB_COLLECT_DATA&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;PRashant&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Dec 2007 12:10:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-join-multiple-tables/m-p/3142990#M747071</guid>
      <dc:creator>former_member386202</dc:creator>
      <dc:date>2007-12-17T12:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to join multiple tables !</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-join-multiple-tables/m-p/3142991#M747072</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;check this thread...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="jive_macro jive_macro_message" href="https://community.sap.com/" __jive_macro_name="message" modifiedtitle="true" __default_attr="3239605"&gt;&lt;/A&gt;&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;Chandru&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Dec 2007 12:14:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-join-multiple-tables/m-p/3142991#M747072</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-17T12:14:31Z</dc:date>
    </item>
  </channel>
</rss>

