<?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: retrieving data from 3 tables in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/retrieving-data-from-3-tables/m-p/2878575#M675923</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 set Break-point &amp;amp; debug the code .Then u can find out where the Problem occurs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Padmam.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 27 Sep 2007 11:05:42 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-09-27T11:05:42Z</dc:date>
    <item>
      <title>retrieving data from 3 tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/retrieving-data-from-3-tables/m-p/2878574#M675922</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 am working on a report where I have to retrieve data from 3 tables(marc,mara,makt).For this I have used 3 select statements for retriving data from 3 tables.There r some fields which r not present in marc table where as present in mara and makt tables.So added thos fields in marc internal table t_marc.I have looped at marc table and used the read statement to read the data from mara table using the key field matnr from both the tables.This read statement is giving the sy-subrc value as 4.Could u pls tell me why this is happening?I am sending my code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT matnr&lt;/P&gt;&lt;P&gt;       werks&lt;/P&gt;&lt;P&gt;       pstat&lt;/P&gt;&lt;P&gt;       lvorm&lt;/P&gt;&lt;P&gt; FROM  marc&lt;/P&gt;&lt;P&gt; INTO  TABLE t_marc&lt;/P&gt;&lt;P&gt; PACKAGE SIZE 500&lt;/P&gt;&lt;P&gt; WHERE matnr IN s_matnr&lt;/P&gt;&lt;P&gt; AND   werks IN s_werks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; IF NOT t_marc[] IS INITIAL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; SELECT matnr&lt;/P&gt;&lt;P&gt;        ersda&lt;/P&gt;&lt;P&gt;        laeda&lt;/P&gt;&lt;P&gt;        meins&lt;/P&gt;&lt;P&gt;   FROM mara&lt;/P&gt;&lt;P&gt;   INTO TABLE t_mara&lt;/P&gt;&lt;P&gt;   FOR ALL ENTRIES IN t_marc&lt;/P&gt;&lt;P&gt;   WHERE matnr = t_marc-matnr&lt;/P&gt;&lt;P&gt;   AND   ersda IN s_ersda&lt;/P&gt;&lt;P&gt;   AND   laeda IN s_laeda.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  IF NOT t_mara[] IS INITIAL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     SELECT matnr&lt;/P&gt;&lt;P&gt;            maktx&lt;/P&gt;&lt;P&gt;     FROM  makt&lt;/P&gt;&lt;P&gt;     INTO  TABLE t_makt&lt;/P&gt;&lt;P&gt;     FOR ALL ENTRIES IN t_mara&lt;/P&gt;&lt;P&gt;     WHERE matnr = t_mara-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   LOOP AT t_marc INTO wa_marc.&lt;/P&gt;&lt;P&gt;     READ TABLE t_mara INTO wa_mara WITH KEY matnr = t_marc-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     IF sy-subrc IS INITIAL.&lt;/P&gt;&lt;P&gt;        wa_marc-meins = wa_mara-meins.&lt;/P&gt;&lt;P&gt;        MODIFY t_marc.&lt;/P&gt;&lt;P&gt;        APPEND wa_marc TO t_output.&lt;/P&gt;&lt;P&gt;      ENDIF.&lt;/P&gt;&lt;P&gt;      READ TABLE t_makt INTO wa_makt WITH KEY matnr = t_marc-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      IF sy-subrc IS INITIAL.&lt;/P&gt;&lt;P&gt;        wa_marc-maktx = wa_makt-maktx.&lt;/P&gt;&lt;P&gt;        MODIFY t_marc.&lt;/P&gt;&lt;P&gt;        APPEND wa_marc TO t_output.&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>Thu, 27 Sep 2007 11:00:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/retrieving-data-from-3-tables/m-p/2878574#M675922</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-27T11:00:22Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving data from 3 tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/retrieving-data-from-3-tables/m-p/2878575#M675923</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 set Break-point &amp;amp; debug the code .Then u can find out where the Problem occurs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Padmam.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Sep 2007 11:05:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/retrieving-data-from-3-tables/m-p/2878575#M675923</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-27T11:05:42Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving data from 3 tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/retrieving-data-from-3-tables/m-p/2878576#M675924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi hema,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dont use three select stements for this scenario.&lt;/P&gt;&lt;P&gt;Just use innerjoin and join all the three tables.&lt;/P&gt;&lt;P&gt;Three tables should contain  MATNR (material number).&lt;/P&gt;&lt;P&gt;By using that retrieve data from 3 tables by using a single select statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Eg:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT DISTINCT a~matnr    "MATERIAL NUMBER
         a~ersda    "CREATED ON
         a~mtart    "MATERIAL TYPE
         a~meins    "BASE UNIT OF MEASURE
         a~bstme    "ORDER UNIT
         b~maktx    "MATERIAL DESCRIPTION
         c~bwkey    "VALUATION AREA
         c~lbkum    "TOTAL VALUED STOCK
         c~salk3    "VALUE OF TOTAL VALUED STOCK
         c~stprs    "STANDARD PRICE
         c~peinh    "PRICE UNIT
         c~bklas    "VALUATION CLASS
         INTO TABLE it_matdetails
         FROM mara AS a INNER JOIN makt AS b ON a~matnr = b~matnr
                        INNER JOIN mbew AS c ON a~matnr = c~matnr
                        INNER JOIN marc AS d ON a~matnr = d~matnr
                        INNER JOIN mard AS e ON a~matnr = e~matnr
         WHERE b~spras = sy-langu AND a~matnr IN matnr AND d~werks IN werks AND e~lgort IN lgort.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;pls reward if helpful.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Sep 2007 11:05:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/retrieving-data-from-3-tables/m-p/2878576#M675924</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-27T11:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving data from 3 tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/retrieving-data-from-3-tables/m-p/2878577#M675925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;small mistake you done.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;just do this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT matnr&lt;/P&gt;&lt;P&gt;werks&lt;/P&gt;&lt;P&gt;pstat&lt;/P&gt;&lt;P&gt;lvorm&lt;/P&gt;&lt;P&gt;FROM marc&lt;/P&gt;&lt;P&gt;INTO TABLE t_marc&lt;/P&gt;&lt;P&gt;PACKAGE SIZE 500&lt;/P&gt;&lt;P&gt;WHERE matnr IN s_matnr&lt;/P&gt;&lt;P&gt;AND werks IN s_werks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF NOT t_marc[] IS INITIAL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT matnr&lt;/P&gt;&lt;P&gt;ersda&lt;/P&gt;&lt;P&gt;laeda&lt;/P&gt;&lt;P&gt;meins&lt;/P&gt;&lt;P&gt;FROM mara&lt;/P&gt;&lt;P&gt;INTO TABLE t_mara&lt;/P&gt;&lt;P&gt;FOR ALL ENTRIES IN t_marc&lt;/P&gt;&lt;P&gt;WHERE matnr = t_marc-matnr&lt;/P&gt;&lt;P&gt;AND ersda IN s_ersda&lt;/P&gt;&lt;P&gt;AND laeda IN s_laeda.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF NOT t_mara[] IS INITIAL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT matnr&lt;/P&gt;&lt;P&gt;maktx&lt;/P&gt;&lt;P&gt;FROM makt&lt;/P&gt;&lt;P&gt;INTO TABLE t_makt&lt;/P&gt;&lt;P&gt;FOR ALL ENTRIES IN t_mara&lt;/P&gt;&lt;P&gt;WHERE matnr = t_mara-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT t_marc INTO wa_marc.&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;READ TABLE t_mara INTO wa_mara WITH KEY matnr = wa_marc-matnr.&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;IF sy-subrc IS INITIAL.&lt;/P&gt;&lt;P&gt;wa_marc-meins = wa_mara-meins.&lt;/P&gt;&lt;P&gt;MODIFY t_marc.&lt;/P&gt;&lt;P&gt;APPEND wa_marc TO t_output.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;READ TABLE t_makt INTO wa_makt WITH KEY matnr = wa_marc-matnr.&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF sy-subrc IS INITIAL.&lt;/P&gt;&lt;P&gt;wa_marc-maktx = wa_makt-maktx.&lt;/P&gt;&lt;P&gt;MODIFY t_marc.&lt;/P&gt;&lt;P&gt;APPEND wa_marc TO t_output.&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>Thu, 27 Sep 2007 11:10:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/retrieving-data-from-3-tables/m-p/2878577#M675925</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-27T11:10:31Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving data from 3 tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/retrieving-data-from-3-tables/m-p/2878578#M675926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;LOOP AT t_marc INTO wa_marc.&lt;/P&gt;&lt;P&gt;READ TABLE t_mara INTO wa_mara WITH KEY matnr = t_marc-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Don't u think this should be&lt;/P&gt;&lt;P&gt;READ TABLE t_mara INTO wa_mara WITH KEY matnr = wa_marc-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;because u are taking values from t_marc into wa_marc&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Sep 2007 11:12:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/retrieving-data-from-3-tables/m-p/2878578#M675926</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-27T11:12:50Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving data from 3 tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/retrieving-data-from-3-tables/m-p/2878579#M675927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi&lt;/P&gt;&lt;P&gt;good&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i think you r doing some mistake in the if statement ,check that in the debugging mode and change accordingly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;mrutyun^&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Sep 2007 11:13:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/retrieving-data-from-3-tables/m-p/2878579#M675927</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-27T11:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving data from 3 tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/retrieving-data-from-3-tables/m-p/2878580#M675928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SELECT matnr&lt;/P&gt;&lt;P&gt;werks&lt;/P&gt;&lt;P&gt;pstat&lt;/P&gt;&lt;P&gt;lvorm&lt;/P&gt;&lt;P&gt;FROM marc&lt;/P&gt;&lt;P&gt;INTO TABLE t_marc&lt;/P&gt;&lt;P&gt;PACKAGE SIZE 500&lt;/P&gt;&lt;P&gt;WHERE matnr IN s_matnr&lt;/P&gt;&lt;P&gt;AND werks IN s_werks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF NOT t_marc[] IS INITIAL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT matnr&lt;/P&gt;&lt;P&gt;ersda&lt;/P&gt;&lt;P&gt;laeda&lt;/P&gt;&lt;P&gt;meins&lt;/P&gt;&lt;P&gt;FROM mara&lt;/P&gt;&lt;P&gt;INTO TABLE t_mara&lt;/P&gt;&lt;P&gt;FOR ALL ENTRIES IN t_marc&lt;/P&gt;&lt;P&gt;WHERE matnr = t_marc-matnr&lt;/P&gt;&lt;P&gt;AND ersda IN s_ersda&lt;/P&gt;&lt;P&gt;AND laeda IN s_laeda.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF NOT t_mara[] IS INITIAL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT matnr&lt;/P&gt;&lt;P&gt;maktx&lt;/P&gt;&lt;P&gt;FROM makt&lt;/P&gt;&lt;P&gt;INTO TABLE t_makt&lt;/P&gt;&lt;P&gt;FOR ALL ENTRIES IN t_mara&lt;/P&gt;&lt;P&gt;WHERE matnr = t_mara-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT t_marc INTO wa_marc.&lt;/P&gt;&lt;P&gt;READ TABLE t_mara INTO wa_mara WITH KEY matnr = wa_marc-matnr.&lt;/P&gt;&lt;P&gt;IF sy-subrc IS INITIAL.&lt;/P&gt;&lt;P&gt;wa_marc-meins = wa_mara-meins.&lt;/P&gt;&lt;P&gt;MODIFY t_marc.&lt;/P&gt;&lt;P&gt;APPEND wa_marc TO t_output.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;READ TABLE t_makt INTO wa_makt WITH KEY matnr = wa_marc-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF sy-subrc IS INITIAL.&lt;/P&gt;&lt;P&gt;wa_marc-maktx = wa_makt-maktx.&lt;/P&gt;&lt;P&gt;MODIFY t_marc.&lt;/P&gt;&lt;P&gt;APPEND wa_marc TO t_output.&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>Thu, 27 Sep 2007 11:37:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/retrieving-data-from-3-tables/m-p/2878580#M675928</guid>
      <dc:creator>mahaboob_pathan</dc:creator>
      <dc:date>2007-09-27T11:37:38Z</dc:date>
    </item>
  </channel>
</rss>

