<?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: Performance Issue - Selecting cuplicate name from KNA1 table in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045337#M87736</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Apart from the good solutions given above you may like to give this a try -&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;REPORT ZTEST  .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA : BEGIN OF ITAB OCCURS 0,&lt;/P&gt;&lt;P&gt;    NAME1 TYPE KNA1-NAME1,&lt;/P&gt;&lt;P&gt;    KUNNR TYPE KNA1-KUNNR,&lt;/P&gt;&lt;P&gt;    STRAS TYPE KNA1-STRAS,&lt;/P&gt;&lt;P&gt;    ORT01 TYPE KNA1-ORT01,&lt;/P&gt;&lt;P&gt;    REGIO TYPE KNA1-REGIO,&lt;/P&gt;&lt;P&gt;    PSTLZ TYPE KNA1-PSTLZ,&lt;/P&gt;&lt;P&gt;    TELF1 TYPE KNA1-TELF1,&lt;/P&gt;&lt;P&gt;END OF ITAB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT NAME1 KUNNR STRAS ORT01 REGIO PSTLZ TELF1&lt;/P&gt;&lt;P&gt;FROM KNA1 AS F INTO TABLE ITAB&lt;/P&gt;&lt;P&gt;WHERE KTOKD = '0004'&lt;/P&gt;&lt;P&gt;AND EXISTS ( SELECT * FROM KNA1 WHERE KUNNR NE F~KUNNR AND NAME1 EQ&lt;/P&gt;&lt;P&gt;F~NAME1 ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF SY-SUBRC NE 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDIF.&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 20 Oct 2005 01:19:09 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2005-10-20T01:19:09Z</dc:date>
    <item>
      <title>Performance Issue - Selecting cuplicate name from KNA1 table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045324#M87723</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My colleague wrote this query and it takes more than 15 hours to finish in PROD. So now, I have to do the performance tuning. Please let me know if you have any idea ( i.e. split it or create index for name1) to make it faster? Purpose of this query is to search through the customer master table(KAN1) for all accounts in the Bill-to account group(0004) where there is more than one record with the same bill-to name.      &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT kunnr name1 stras ort01 regio pstlz telf1      &lt;/P&gt;&lt;P&gt;FROM kna1 INTO TABLE it_kna1                        &lt;/P&gt;&lt;P&gt;WHERE ktokd = '0004'&lt;/P&gt;&lt;P&gt;AND name1 IN &lt;/P&gt;&lt;P&gt;    ( select name1 FROM kna1                      &lt;/P&gt;&lt;P&gt;      WHERE ktokd = '0004'                          &lt;/P&gt;&lt;P&gt;      GROUP BY name1 HAVING COUNT( * ) &amp;gt; 1 )    &lt;/P&gt;&lt;P&gt;ORDER BY kunnr.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2005 16:06:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045324#M87723</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-10-19T16:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue - Selecting cuplicate name from KNA1 table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045325#M87724</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Kishore,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you have a reasonable number of customers, I would select the whole KNA1 table into an internal table, sort it by name and select the duplicates in a loop. We did this with about 50.000 customers without problems.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Rabanus&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2005 16:14:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045325#M87724</guid>
      <dc:creator>former_member517</dc:creator>
      <dc:date>2005-10-19T16:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue - Selecting cuplicate name from KNA1 table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045326#M87725</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This logic works pretty good in my system.  It may not look pretty, but it works pretty fast.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

report zrich_0002  .


data: it_kna1 type table of kna1 with header line.
data: it_kna12 type table of kna1 with header line.
data: it_kna13 type table of kna1 with header line.
data: counter type i.

select kunnr name1 stras ort01 regio pstlz telf1
         from kna1 into corresponding fields of table it_kna1
                where ktokd = '0004'.

it_kna12[] = it_kna1[].

sort it_kna1 ascending by name1.
delete adjacent duplicates from it_kna1 comparing name1.

loop at it_kna1.

  clear counter.
  loop at it_kna12 where name1 = it_kna1-name1.
    counter = counter + 1.
  endloop.
  check counter &amp;gt; 1.
  loop at it_kna12 where name1 = it_kna1-name1.
    move-corresponding it_kna12 to it_kna13.
    append it_kna13.
  endloop.



endloop.

loop at it_kna13.
write:/ it_kna13-kunnr, it_kna13-name1.
endloop.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just tested this logic on our KNA1 with 4757 records, it ran in under 5 seconds.&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>Wed, 19 Oct 2005 16:17:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045326#M87725</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-10-19T16:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue - Selecting cuplicate name from KNA1 table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045327#M87726</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do not do your count on the database. Instead, get the records into an internal table and do the search for duplicate names.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT kunnr name1 stras ort01 
       regio pstlz telf1  FROM kna1 
                    INTO TABLE it_kna1 
                   WHERE ktokd = '0004'.
it_kna2[] = it_kna1[].
sort it_kna1 by name1.
sort it_kna2 by name1.
delete adjacent duplicates from it_kna1 comparing name1.
loop at it_kna1.
 loop at it_kna2 where name1 = it_kna1-name1.
  count = count + 1.
 endloop.
 write:/ it_kna1-kunnr, count.
 clear count.
endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are options to optimize the loop processing also, but depending on your itab records, we can try that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Srinivas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2005 16:18:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045327#M87726</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-10-19T16:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue - Selecting cuplicate name from KNA1 table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045328#M87727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How many records do you have in KNA1 and how many are you selecting? I ran your select in our system and it took just a few seconds.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2005 16:28:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045328#M87727</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-10-19T16:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue - Selecting cuplicate name from KNA1 table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045329#M87728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rob,&lt;/P&gt;&lt;P&gt;We have 4,701,555 records in KNA1 table.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2005 16:46:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045329#M87728</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-10-19T16:46:56Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue - Selecting cuplicate name from KNA1 table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045330#M87729</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; Hi Rob,&lt;/P&gt;&lt;P&gt;&amp;gt; We have 4,701,555 records in KNA1 table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How many Bill-to records?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2005 16:51:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045330#M87729</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-10-19T16:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue - Selecting cuplicate name from KNA1 table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045331#M87730</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Wow.....  I'm not sure what to say.  &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;  I think that any processing of those records is going to take some time.  Maybe not 15 hours, but some time.&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>Wed, 19 Oct 2005 16:56:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045331#M87730</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-10-19T16:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue - Selecting cuplicate name from KNA1 table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045332#M87731</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Even with 4.000.000 customers I would try to do it with one internal table sorted by name. Then you could go through the table in a single loop with 2 pointers. If the last entry is unique, you can delete it . Otherwise you go forward until you find the next difference. My estimate is that this can be done under 1 hour.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Rabanus&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2005 17:15:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045332#M87731</guid>
      <dc:creator>former_member517</dc:creator>
      <dc:date>2005-10-19T17:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue - Selecting cuplicate name from KNA1 table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045333#M87732</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK that number changes the equation. Try this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT kunnr name1 stras ort01 
       regio pstlz telf1  FROM kna1 
                    INTO TABLE it_kna1 
                   WHERE ktokd = '0004'.
it_kna2[] = it_kna1[].
sort it_kna1 by name1.
sort it_kna2 by name1.
delete adjacent duplicates from it_kna1 comparing name1.
loop at it_kna1.
  clear v_index.
  read table it_kna2 with key name1 = it_kna1-name1 binary search.
  if sy-subrc = 0.
    v_index = sy-tabix + 1.
*-- check if there is another record. Since it is sorted 
*   by name1, the duplicate record should be right next
*   to this one.
    read table it_kna2 index v_index.
    if sy-subrc &amp;lt;&amp;gt; 0.
*-- no other record exists with the same name. delete it.
      delete it_kna2 where name1 = it_kna1-name1.
    endif.
  endif.
endloop.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;By the end of this loop, you should have only duplicate entries in the it_kna2 table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Srinivas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2005 17:30:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045333#M87732</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-10-19T17:30:41Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue - Selecting cuplicate name from KNA1 table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045334#M87733</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I like Srinivas's solution.  I think that this will be the fastest.&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>Wed, 19 Oct 2005 17:33:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045334#M87733</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-10-19T17:33:04Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue - Selecting cuplicate name from KNA1 table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045335#M87734</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I like Srinivas' solution too; but I'd be concerned about the sizes of the internal tables. I don't know how many rows will be selected, but if it's large, it could dump. In that case, you could try a less elegant solution:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT ztemp LINE-SIZE 80 MESSAGE-ID zc.

TABLES: kna1.

DATA: BEGIN OF it_kna1 OCCURS 0.
        INCLUDE STRUCTURE kna1.
DATA: END   OF it_kna1.

DATA: BEGIN OF it2_kna1 OCCURS 0.
        INCLUDE STRUCTURE kna1.
DATA: END   OF it2_kna1.

DATA: BEGIN OF it_kunnr OCCURS 0,
        kunnr LIKE kna1-kunnr,
      END   OF it_kunnr.

DATA: old_name1 LIKE kna1-name1,
      old_kunnr LIKE kna1-kunnr.

SELECT kunnr name1 FROM kna1 INTO (kna1-kunnr, kna1-name1)
WHERE ktokd = '0004'
ORDER BY name1.
  IF kna1-name1 &amp;lt;&amp;gt; old_name1.
    old_name1 = kna1-name1.
    old_kunnr = kna1-kunnr.
  ELSE.
    it_kunnr-kunnr = kna1-kunnr.
    APPEND it_kunnr.
    it_kunnr-kunnr = old_kunnr.
    APPEND it_kunnr.
  ENDIF.
ENDSELECT.

SORT it_kunnr BY kunnr.
DELETE ADJACENT DUPLICATES FROM it_kunnr COMPARING kunnr.

SELECT kunnr name1 stras ort01 regio pstlz telf1
  FROM kna1 INTO CORRESPONDING FIELDS OF TABLE it_kna1
  FOR ALL ENTRIES IN it_kunnr
  WHERE kunnr = it_kunnr-kunnr.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I think the original problem is partly caused by having this all done by the database server (generally a good idea, but in this case not working very well). I wouldn't try this unless there are problems with the other solution. (This one could actually run longer.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I changed the account group back to what was in the original post.&lt;/P&gt;&lt;P&gt;Message was edited by: Rob Burbank&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2005 18:24:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045335#M87734</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-10-19T18:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue - Selecting cuplicate name from KNA1 table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045336#M87735</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Kishore,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can try this also.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
TYPES:
  BEGIN OF ty_kna1,
    name1 TYPE kna1-name1,
    kunnr TYPE kna1-kunnr,
    stras TYPE kna1-stras,
    ort01 TYPE kna1-ort01,
    regio TYPE kna1-regio,
    pstlz TYPE kna1-pstlz,
    telf1 TYPE kna1-telf1,
  END OF ty_kna1.

DATA:
  t_kna1 TYPE SORTED TABLE OF ty_kna1
    WITH NON-UNIQUE KEY name1
    INITIAL SIZE 1000.
DATA:
  v_count TYPE sy-tabix.

FIELD-SYMBOLS:
  &amp;lt;fs_kna1&amp;gt; TYPE ty_kna1.

SELECT name1 kunnr stras ort01 regio pstlz telf1
  INTO TABLE t_kna1
  FROM kna1
  WHERE ktokd EQ '0004'.

*--- TEST SECTION 1 BEGIN
**--- Test data for concept
*DATA: s_kna1 type ty_kna1.
*REFRESH t_kna1.
*s_kna1-name1 = 'A'. INSERT s_kna1 INTO TABLE t_kna1.
*s_kna1-name1 = 'B'. INSERT s_kna1 INTO TABLE t_kna1.
*s_kna1-name1 = 'B'. INSERT s_kna1 INTO TABLE t_kna1.
*s_kna1-name1 = 'E'. INSERT s_kna1 INTO TABLE t_kna1.
*s_kna1-name1 = 'B'. INSERT s_kna1 INTO TABLE t_kna1.
*s_kna1-name1 = 'F'. INSERT s_kna1 INTO TABLE t_kna1.
*s_kna1-name1 = 'D'. INSERT s_kna1 INTO TABLE t_kna1.
*s_kna1-name1 = 'F'. INSERT s_kna1 INTO TABLE t_kna1.
*s_kna1-name1 = 'G'. INSERT s_kna1 INTO TABLE t_kna1.
*--- TEST SECTION 1 END

LOOP AT t_kna1 ASSIGNING &amp;lt;fs_kna1&amp;gt;.
* The ASSIGNING statement saves time by skipping a copy
* to header/work area
  AT NEW name1.
* Clear counter for every unique name
    CLEAR v_count.
  ENDAT.

  ADD 1 TO v_count.

  AT END OF name1.
    IF v_count EQ 1.
* Only one instance of NAME1 found
      DELETE t_kna1.
    ENDIF.
  ENDAT.
ENDLOOP.

* At this point, only records with duplicate records should be left

*--- TEST SECTION 2 BEGIN
**--- Output test data begin
*LOOP AT t_kna1 into s_kna1.
*  WRITE:/ s_kna1-name1.
*ENDLOOP.
*--- TEST SECTION 2 END
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This eliminates the second internal table and the reads on it saving memory and time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to test it, remove the comments in the test section and you will see it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you go with this solution, then remove the code of the test sections and move it up.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rich/AK/Rob If there is any problem with it, please let me know so I can correct myself for the future.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;-Ramesh&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Changed code to save a few milli seconds &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt; by using the Field symbol.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2005 21:23:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045336#M87735</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-10-19T21:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue - Selecting cuplicate name from KNA1 table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045337#M87736</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Apart from the good solutions given above you may like to give this a try -&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;REPORT ZTEST  .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA : BEGIN OF ITAB OCCURS 0,&lt;/P&gt;&lt;P&gt;    NAME1 TYPE KNA1-NAME1,&lt;/P&gt;&lt;P&gt;    KUNNR TYPE KNA1-KUNNR,&lt;/P&gt;&lt;P&gt;    STRAS TYPE KNA1-STRAS,&lt;/P&gt;&lt;P&gt;    ORT01 TYPE KNA1-ORT01,&lt;/P&gt;&lt;P&gt;    REGIO TYPE KNA1-REGIO,&lt;/P&gt;&lt;P&gt;    PSTLZ TYPE KNA1-PSTLZ,&lt;/P&gt;&lt;P&gt;    TELF1 TYPE KNA1-TELF1,&lt;/P&gt;&lt;P&gt;END OF ITAB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT NAME1 KUNNR STRAS ORT01 REGIO PSTLZ TELF1&lt;/P&gt;&lt;P&gt;FROM KNA1 AS F INTO TABLE ITAB&lt;/P&gt;&lt;P&gt;WHERE KTOKD = '0004'&lt;/P&gt;&lt;P&gt;AND EXISTS ( SELECT * FROM KNA1 WHERE KUNNR NE F~KUNNR AND NAME1 EQ&lt;/P&gt;&lt;P&gt;F~NAME1 ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF SY-SUBRC NE 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDIF.&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Oct 2005 01:19:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045337#M87736</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-10-20T01:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue - Selecting cuplicate name from KNA1 table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045338#M87737</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;one thing you have to take care while using internal tables is memory issue. you might get the short dump with message &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TSV_TNEW_PAGE_ALLOC_FAILED&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;refer to OSS note 20527 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Oct 2005 05:50:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045338#M87737</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-10-20T05:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue - Selecting cuplicate name from KNA1 table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045339#M87738</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could also try your original select but using MCOD1 instead of NAME1:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT kunnr name1 stras ort01 regio pstlz telf1
  FROM kna1 INTO CORRESPONDING FIELDS OF TABLE it_kna1
  WHERE ktokd = '0004'
  AND mcod1 IN
    ( select mcod1 from KNA1
        WHERE ktokd = '0004'
        GROUP by mcod1 HAVING COUNT( * ) &amp;gt; 1 )
        ORDER BY kunnr.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;MCOD1 is a secondary index based on NAME1 (but shorter). It has the advantage of being case insensitive, so it will match Jones with JONES, while the original select won't.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Changed the account group again.&lt;/P&gt;&lt;P&gt;Message was edited by: Rob Burbank&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Oct 2005 13:41:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-selecting-cuplicate-name-from-kna1-table/m-p/1045339#M87738</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-10-20T13:41:52Z</dc:date>
    </item>
  </channel>
</rss>

