<?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: Comparing 2 tables in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-2-tables/m-p/1380183#M185746</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Might records be deleted from the first table?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 04 Jul 2006 14:47:30 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2006-07-04T14:47:30Z</dc:date>
    <item>
      <title>Comparing 2 tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-2-tables/m-p/1380180#M185743</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I am new to ABAP programming. I have simple task to perform.&lt;/P&gt;&lt;P&gt;I have 2 SE11 tables, and in ABAP program, i have to compare 2 tables, if there are some new records or modified(i can get this info by checking a flag, a table field) in table1 then i have to update table2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you please send me a sameple code? I will try to simulate it to my requirement.&lt;/P&gt;&lt;P&gt;&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>Tue, 04 Jul 2006 14:40:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-2-tables/m-p/1380180#M185743</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-04T14:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing 2 tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-2-tables/m-p/1380181#M185744</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can loop at the first and read the second with a key to see if it has a correponding record.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Loop at itab1 .

 read table itab2 with key fld1 = itab1-fld1.
if sy-subrc = 0.
* Yes, there is a corresponding record in ITAB2.
endif.

endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&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>Tue, 04 Jul 2006 14:42:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-2-tables/m-p/1380181#M185744</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2006-07-04T14:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing 2 tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-2-tables/m-p/1380182#M185745</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;select *&lt;/P&gt;&lt;P&gt;from ztab1&lt;/P&gt;&lt;P&gt;into itab1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select *&lt;/P&gt;&lt;P&gt;from ztab2&lt;/P&gt;&lt;P&gt;into itab2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab1.&lt;/P&gt;&lt;P&gt;read table itab2 with key field1 = itab1-field1.&lt;/P&gt;&lt;P&gt;if sy-subrc &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt;flag = 'X'.&lt;/P&gt;&lt;P&gt;exit.&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;if flag = 'X'.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;modify table ztab2.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&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>Tue, 04 Jul 2006 14:44:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-2-tables/m-p/1380182#M185745</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-04T14:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing 2 tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-2-tables/m-p/1380183#M185746</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Might records be deleted from the first table?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Jul 2006 14:47:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-2-tables/m-p/1380183#M185746</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-04T14:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing 2 tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-2-tables/m-p/1380184#M185747</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hai Ravi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check the following code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT ITAB1.&lt;/P&gt;&lt;P&gt;   READ TABLE ITAB2 WITH KEY FIELD = ITAB1-FIELD.&lt;/P&gt;&lt;P&gt;   IF SY-SUBRC &amp;lt;&amp;gt; 0. &lt;/P&gt;&lt;P&gt;      v_flag = 'X'.     &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;if v_flag = 'X'.&lt;/P&gt;&lt;P&gt; DELETE ITAB1. &lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; regards&lt;/P&gt;&lt;P&gt;Sreeni&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Sreenivasulu Ponnadi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Jul 2006 14:47:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-2-tables/m-p/1380184#M185747</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-04T14:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing 2 tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-2-tables/m-p/1380185#M185748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Ravi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Declare to internal tables.&lt;/P&gt;&lt;P&gt;Say Itab1 &amp;amp; Itab2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Fetch the data from table 1 &amp;amp; 2 to internal table 1 &amp;amp; 2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab1.&lt;/P&gt;&lt;P&gt;read table itab2 with key f1 = itab1=f1.&lt;/P&gt;&lt;P&gt;if sy-subrc NE =0.&lt;/P&gt;&lt;P&gt;flag = 'X'.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt; Hope this will be useful for u.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward the points&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Vasanth&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Jul 2006 14:50:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-2-tables/m-p/1380185#M185748</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-04T14:50:04Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing 2 tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-2-tables/m-p/1380186#M185749</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ravi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Consider the code below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT as.

TYPES : BEGIN OF tp_test,
        item(5),
        quan(2),
        END OF tp_test.
DATA : it_test1 TYPE STANDARD TABLE OF tp_test,
       wa_test1 TYPE tp_test,
       it_test2 TYPE STANDARD TABLE OF tp_test,
       wa_test2 TYPE tp_test,
       it_result TYPE STANDARD TABLE OF tp_test.

&amp;lt;b&amp;gt;*Scenario 1&amp;lt;/b&amp;gt;

Internal Table : it_test1
&amp;lt;b&amp;gt;item   quan&amp;lt;/b&amp;gt;
mfg03  50
mfg04  100
mfg05  20

Internal Table : it_test2
&amp;lt;b&amp;gt;item   quan&amp;lt;/b&amp;gt;
mfg03  50
mfg04  120
mfg05  220

*Loop the second Table

LOOP AT it_test2 INTO wa_test2.

*Read the first table

  READ TABLE it_test1 INTO wa_test1 WITH KEY item = wa_test2-item
                                             quan = wa_test2-quan.


*If no entry present in the first table for entry in second table then append
*then append the second table entry.

  IF sy-subrc NE 0.
    APPEND wa_test2 TO it_result.
  ENDIF.

ENDLOOP.


&amp;lt;b&amp;gt;*Scenario 2&amp;lt;/b&amp;gt;

Internal Table : it_test1
&amp;lt;b&amp;gt;item   quan&amp;lt;/b&amp;gt;
mfg03  50
mfg04  100
mfg05  20

Internal Table : it_test2
&amp;lt;b&amp;gt;item   quan&amp;lt;/b&amp;gt;
mfg03  70
mfg03  80
mfg05  230
mfg04  120
mfg04  160


&amp;lt;b&amp;gt;*Or if there are fields with same values for the key fields (Line items) in both the tables then use this.&amp;lt;/b&amp;gt;

LOOP AT it_test1 INTO wa_test1.
  LOOP AT it_test2 INTO wa_test2 WHERE item NE wa_test1-item.

    APPEND wa_test2 TO it_result.
  ENDLOOP.
ENDLOOP.


*Now updating the Table.

MODIFY &amp;lt;DB TABLE name&amp;gt; FROM table it_result.

IF sy-subrc EQ 0.
  WRITE : / 'Table updated successfully'.

ENDIF.


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&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;Arun Sambargi.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Arun Sambargi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Jul 2006 14:55:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-2-tables/m-p/1380186#M185749</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-04T14:55:20Z</dc:date>
    </item>
  </channel>
</rss>

