<?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: Merging two internal tables in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968347#M69092</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sharath has the right answer.  Avoid nesting a loop at where clause inside another loop.  It can get slow very easily.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only thing to add would be to only read table2 when the keys changed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 24 Sep 2005 00:40:57 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2005-09-24T00:40:57Z</dc:date>
    <item>
      <title>Merging two internal tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968338#M69083</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt; I have two internal tables it_tab1 and it_tab2. The fields are,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it_tab1                        it_tab2&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="--------" /&gt;&lt;P&gt;		     -&lt;/P&gt;&lt;HR originaltext="-----------" /&gt;&lt;P&gt;F1				F1&lt;/P&gt;&lt;P&gt;F2				F2&lt;/P&gt;&lt;P&gt;F3				F4&lt;/P&gt;&lt;P&gt;F6				F5&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to &amp;lt;b&amp;gt;merge&amp;lt;/b&amp;gt;(coloumn wise) these two internal tables into a new internal table it_tab3 where it_tab3 has fields,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;F1, F2, F3, F4, F5, F6.(All the fields)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here, in it_tab1 and in it_tab2 the fields &amp;lt;b&amp;gt;F1 and F2 are the key fields&amp;lt;/b&amp;gt;.The number of records in the two internal tables are different.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anybody help me. thanx for spending ur time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Sep 2005 06:29:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968338#M69083</guid>
      <dc:creator>aaruljothi</dc:creator>
      <dc:date>2005-09-23T06:29:25Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two internal tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968339#M69084</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Identify which tab has the maximum no of records.&lt;/P&gt;&lt;P&gt;if itab1 has the maximum then &lt;/P&gt;&lt;P&gt;identify the no of records using describe stmt&lt;/P&gt;&lt;P&gt;create the structure of itab3 as required.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab1.&lt;/P&gt;&lt;P&gt;loop at itab2 wher f1 = itab1- f1 and f2 = itab1-f2.&lt;/P&gt;&lt;P&gt;move the field values to itab3 .&lt;/P&gt;&lt;P&gt;append itab3 .&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Sep 2005 06:35:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968339#M69084</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-23T06:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two internal tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968340#M69085</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 the no of records in both the tables are different then do we need to update only the common records in both the table to the final table?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With Regards,&lt;/P&gt;&lt;P&gt;Ranganthan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Sep 2005 06:36:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968340#M69085</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-23T06:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two internal tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968341#M69086</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Winnie Chan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Sep 2005 06:37:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968341#M69086</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-23T06:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two internal tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968342#M69087</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;SInce u have mentioned the key fields are present in both the internal tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can -&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;declare it_itab3 with all the fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort it_itab2 by F1 F2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Loop at t_itab1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it_itab3-f1 = t_itab1-F1.&lt;/P&gt;&lt;P&gt;it_itab3-f2 = t_itab1-F2.&lt;/P&gt;&lt;P&gt;it_itab3-f3 = t_itab1-F3.&lt;/P&gt;&lt;P&gt;it_itab3-f6 = t_itab1-F6.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read table t_itab2 with key F1 = t_itab1-F1&lt;/P&gt;&lt;P&gt;                            F2 = t_itab1-F2&lt;/P&gt;&lt;P&gt;                            binary search.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if sy-subrc eq 0.&lt;/P&gt;&lt;P&gt;it_itab3-f4 = t_itab2-f4.&lt;/P&gt;&lt;P&gt;it_itab3-f5 = t_itab2-f5.&lt;/P&gt;&lt;P&gt;append it_itab3.&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 u want the records even if the corresponding values of F1, F2 of itab1 is not there in iTAB2 then use append outside the if statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Sep 2005 06:40:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968342#M69087</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-23T06:40:21Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two internal tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968343#M69088</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi try similar to this code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: BEGIN OF itab1 OCCURS 0,
       no TYPE c,
     END OF itab1.

DATA: BEGIN OF itab2 OCCURS 0,
       no TYPE c,
     END OF itab2.
DATA: BEGIN OF itab3 OCCURS 0,
       no TYPE c,
     END OF itab3.

itab1-no = 'A'.
APPEND itab1.
itab1-no = 'B'.
APPEND itab1.
itab1-no = 'C'.
APPEND itab1.
itab1-no = 'D'.
APPEND itab1.
itab1-no = 'E'.
APPEND itab1.

itab2-no = 'A'.
APPEND itab2.
itab2-no = 'B'.
APPEND itab2.
itab2-no = 'D'.
APPEND itab2.
itab2-no = 'F'.
APPEND itab2.
itab2-no = 'H'.
APPEND itab2.

SORT itab1.
SORT itab2.

clear itab1.
clear itab2.
clear itab3.
itab3[] =  itab1[].
APPEND itab3.
clear itab3.

INSERT LINES OF itab2 INTO TABLE itab3.

SORT itab3.
DELETE ADJACENT DUPLICATES FROM itab3.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Sep 2005 06:49:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968343#M69088</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-23T06:49:41Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two internal tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968344#M69089</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;Here is the sample code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Loop at itab1 into wa1.&lt;/P&gt;&lt;P&gt;read table itab2 into wa2 with key f1 = wa1-f1 &lt;/P&gt;&lt;P&gt;                                   f2 = wa1-fa2.&lt;/P&gt;&lt;P&gt;if sy-subrc eq 0.&lt;/P&gt;&lt;P&gt;move-corresponding wa1 to wa3.&lt;/P&gt;&lt;P&gt;move-corresponding wa2 to wa3.&lt;/P&gt;&lt;P&gt;append wa3 to itab3.&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;Kindly reward points by clicking the star on the left of reply,if it is useful.Get back if you need clarifications.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Sep 2005 06:56:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968344#M69089</guid>
      <dc:creator>jayanthi_jayaraman</dc:creator>
      <dc:date>2005-09-23T06:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two internal tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968345#M69090</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;try this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab1 - first&lt;/P&gt;&lt;P&gt;itab2 - second&lt;/P&gt;&lt;P&gt;itab3 - both&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data l_count type i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;l_count = 1.&lt;/P&gt;&lt;P&gt;loop at itab1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read table itab2 with key f1 = itab1-f1 f2 = itab1-f2.&lt;/P&gt;&lt;P&gt;itab3 = itab1&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if sy-subrc is initial&lt;/P&gt;&lt;P&gt;   itab3-field6 = itab2-field3.&lt;/P&gt;&lt;P&gt;   itab3-field7 = itab2-field4.&lt;/P&gt;&lt;P&gt;   append itab3.&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;loop at itab2.&lt;/P&gt;&lt;P&gt;itab3 = itab2&lt;/P&gt;&lt;P&gt;read table itab1 with key f1 = itab2-f1 f2 = itab2-f2.&lt;/P&gt;&lt;P&gt; if sy-subrc is initial&lt;/P&gt;&lt;P&gt;   itab3-field6 = itab1-field3.&lt;/P&gt;&lt;P&gt;   itab3-field7 = itab1-field4.&lt;/P&gt;&lt;P&gt;   append itab3.&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;sort itab3 by f1 f2.&lt;/P&gt;&lt;P&gt;delete adjacent duplicates by comparing f1 f2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope this will solve your problem&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers,&lt;/P&gt;&lt;P&gt;sasi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Sasi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Sep 2005 06:56:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968345#M69090</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-23T06:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two internal tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968346#M69091</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Little alteration to what  Bala Muthu Raja replied.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use this logic so that you also capture the records from itab1 for which there is no entry in itab2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab1.&lt;/P&gt;&lt;P&gt;    loop at itab2 wher f1 = itab1- f1 and f2 = itab1-f2.&lt;/P&gt;&lt;P&gt;      move the fields from itab2 to itab3 .&lt;/P&gt;&lt;P&gt;    endloop.&lt;/P&gt;&lt;P&gt;Move fields from itab1 to itab 3&lt;/P&gt;&lt;P&gt;append itab3 .&lt;/P&gt;&lt;P&gt; endloop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Sep 2005 07:00:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968346#M69091</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-23T07:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two internal tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968347#M69092</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sharath has the right answer.  Avoid nesting a loop at where clause inside another loop.  It can get slow very easily.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only thing to add would be to only read table2 when the keys changed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 24 Sep 2005 00:40:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/merging-two-internal-tables/m-p/968347#M69092</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-24T00:40:57Z</dc:date>
    </item>
  </channel>
</rss>

