<?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: extracting data from multiple tables in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-data-from-multiple-tables/m-p/4265588#M1017741</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hii!&lt;/P&gt;&lt;P&gt;  Check this sample code. Here I'm fetching the data from two tables&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT z_sdn.
TABLES:
  sflight.

SELECT-OPTIONS:
  s_carrid FOR sflight-carrid,
  s_connid FOR sflight-connid.

DATA:
  BEGIN OF fs_flight,
    carrid   TYPE sflight-carrid,
    connid   TYPE sflight-connid,
    fldate   TYPE sflight-fldate,
    bookid   TYPE sbook-bookid,
    customid TYPE sbook-customid,
  END OF fs_flight.

DATA:
  t_flight LIKE
     TABLE OF
           fs_flight.


START-OF-SELECTION.

SELECT f~carrid
       f~connid
       f~fldate
       b~bookid
       b~customid
  FROM ( sflight AS f
         INNER JOIN sbook AS b ON f~carrid = b~carrid
                              AND f~connid = b~connid
                              AND f~fldate = b~fldate )
  INTO TABLE t_flight
 WHERE f~carrid IN s_carrid
   AND f~connid IN s_connid.

 LOOP AT t_flight INTO fs_flight.
   WRITE: / fs_flight-carrid,
            fs_flight-connid,
            fs_flight-fldate,
            fs_flight-bookid,
            fs_flight-customid.
 ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Abhijeet&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 09 Aug 2008 06:20:12 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-08-09T06:20:12Z</dc:date>
    <item>
      <title>extracting data from multiple tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-data-from-multiple-tables/m-p/4265585#M1017738</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;how to extract data from multiple tables? plz give sample code&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Aug 2008 06:05:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-data-from-multiple-tables/m-p/4265585#M1017738</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-09T06:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: extracting data from multiple tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-data-from-multiple-tables/m-p/4265586#M1017739</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;You can use inner joins  and outer joins..&lt;/P&gt;&lt;P&gt;See this : &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT a&lt;SUB&gt;mblnr a&lt;/SUB&gt;mjahr a&lt;SUB&gt;zeile a&lt;/SUB&gt;bwart a&lt;SUB&gt;matnr a&lt;/SUB&gt;werks a~lgort&lt;/P&gt;&lt;P&gt;a&lt;SUB&gt;sobkz a&lt;/SUB&gt;menge a&lt;SUB&gt;meins b&lt;/SUB&gt;budat&lt;/P&gt;&lt;P&gt;FROM mseg AS a INNER JOIN mkpf AS b&lt;/P&gt;&lt;P&gt;ON a&lt;SUB&gt;mblnr = b&lt;/SUB&gt;mblnr&lt;/P&gt;&lt;P&gt;AND a&lt;SUB&gt;mjahr = b&lt;/SUB&gt;mjahr&lt;/P&gt;&lt;P&gt;INTO TABLE it_mseg&lt;/P&gt;&lt;P&gt;FOR ALL ENTRIES IN it_mara&lt;/P&gt;&lt;P&gt;WHERE a~bwart IN s_bwart&lt;/P&gt;&lt;P&gt;AND a~matnr EQ it_mara-matnr&lt;/P&gt;&lt;P&gt;AND a~werks = p_werks&lt;/P&gt;&lt;P&gt;AND b~budat &amp;gt;= v_start&lt;/P&gt;&lt;P&gt;AND b~budat &amp;lt;= v_finish.&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;Nishant&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Aug 2008 06:12:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-data-from-multiple-tables/m-p/4265586#M1017739</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-09T06:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: extracting data from multiple tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-data-from-multiple-tables/m-p/4265587#M1017740</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;if u want to extract just use the following code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select matnr mbrsh mtart from mara into table i_mara where matnr in s_matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if not i_mara[] is initial.&lt;/P&gt;&lt;P&gt;select matnr werks from marc into table i_marc for all entries in i_mara where matnr = i_mara-matnr.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i hope this can be useful to you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Aug 2008 06:19:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-data-from-multiple-tables/m-p/4265587#M1017740</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-09T06:19:56Z</dc:date>
    </item>
    <item>
      <title>Re: extracting data from multiple tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-data-from-multiple-tables/m-p/4265588#M1017741</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hii!&lt;/P&gt;&lt;P&gt;  Check this sample code. Here I'm fetching the data from two tables&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT z_sdn.
TABLES:
  sflight.

SELECT-OPTIONS:
  s_carrid FOR sflight-carrid,
  s_connid FOR sflight-connid.

DATA:
  BEGIN OF fs_flight,
    carrid   TYPE sflight-carrid,
    connid   TYPE sflight-connid,
    fldate   TYPE sflight-fldate,
    bookid   TYPE sbook-bookid,
    customid TYPE sbook-customid,
  END OF fs_flight.

DATA:
  t_flight LIKE
     TABLE OF
           fs_flight.


START-OF-SELECTION.

SELECT f~carrid
       f~connid
       f~fldate
       b~bookid
       b~customid
  FROM ( sflight AS f
         INNER JOIN sbook AS b ON f~carrid = b~carrid
                              AND f~connid = b~connid
                              AND f~fldate = b~fldate )
  INTO TABLE t_flight
 WHERE f~carrid IN s_carrid
   AND f~connid IN s_connid.

 LOOP AT t_flight INTO fs_flight.
   WRITE: / fs_flight-carrid,
            fs_flight-connid,
            fs_flight-fldate,
            fs_flight-bookid,
            fs_flight-customid.
 ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Abhijeet&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Aug 2008 06:20:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-data-from-multiple-tables/m-p/4265588#M1017741</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-09T06:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: extracting data from multiple tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-data-from-multiple-tables/m-p/4265589#M1017742</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To perform selection from multiple tables, check for the common fields preferably key fields are required to establish the relationship. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can achieve it by using Joins/for all entries. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Joins(Preferably Inner Joins) is really a good approach.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check this query.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here I am using two tables MKPF and MSEG.&lt;/P&gt;&lt;P&gt;MKPF(Material Document Header)&lt;/P&gt;&lt;P&gt;MSEG(Material Document Segment)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Both the tables contains the common fields MBLNR and GJAHR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now check the query.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select a&lt;SUB&gt;mblnr a&lt;/SUB&gt;gjahr b&lt;SUB&gt;mblnr b&lt;/SUB&gt;gjahr b&lt;SUB&gt;matnr b&lt;/SUB&gt;menge b&lt;SUB&gt;meins from mkpf as a inner join mseg as b on a&lt;/SUB&gt;mblnr = b~mblnr where mblnr in &amp;lt;select-options&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now here you can place several conditions based on your program.  "a" is called the alias name for MKPF table and "b" is called as the alias name for MSEG table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Similarly you can establish the link with several tables. Now based on the material in MSEG table You can establish link to MARC(Plant data) etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is very similar for adding the other tables in the same select query, but follow the rules of establishing links using joins. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also follow the "Indexes" properly so that database performance is optimized.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Santosh Kumar M.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Aug 2008 06:20:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/extracting-data-from-multiple-tables/m-p/4265589#M1017742</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-08-09T06:20:49Z</dc:date>
    </item>
  </channel>
</rss>

