<?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: For all entries - Performance Issue in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-performance-issue/m-p/8346316#M1639616</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The DELETE ADJACENT DUPLICATES is actually not the best solution for this task, especially if you need the table including the duplicates later again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Much more elegant is the solution to define a hashed table with a unique key consisting of the fields needed in the FAE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hash   type hashed table of st_fields  with unique table key field1 field2 field3. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and to use a COLLECT!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT itab ASSIGNING &amp;lt;fs&amp;gt;.
   wa-field1 = &amp;lt;fs&amp;gt;-field1.
   wa-field1 = &amp;lt;fs&amp;gt;-field1.
   wa-field1 = &amp;lt;fs&amp;gt;-field1.
   COLLECT wa INTO hash.
ENDLOOP.

SELECT   ...
       FOR ALL ENTRIES in hash
       WHERE field1 = hash-field1
       AND       field2 = hash-field2
       AND       field3 = hash-field3.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The COLLECT is faster, it copies only the columns which are really needed not large data columns, and &lt;/P&gt;&lt;P&gt;is unique already by construction.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I doubt that you can measure the overhead, it will be smaller than the usual variations of the SELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 22 Nov 2011 09:14:26 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2011-11-22T09:14:26Z</dc:date>
    <item>
      <title>For all entries - Performance Issue</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-performance-issue/m-p/8346311#M1639611</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; I developed a code in which I use for all entries on various tables(for about 40 tables in different select queries)...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, when I reviewed the code by a standard tool of our company, it is showing the warning message-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DELETE ADJACENT DUPLICATE before using FOR ALL ENTRIES..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I want to maintain Duplicate entries in that table..&lt;/P&gt;&lt;P&gt;To work that way out, I copied the table into another internal table.. sorted it.. deleted adjacent duplicates.. and used that copy in FOR ALL ENTRIES..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&lt;STRONG&gt;But doing like above for around 40 internal tables,(copying, sorting &amp;amp; deleting adjacent duplicates) my performance has really gone down..&lt;/STRONG&gt;*&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there any alternative that I can do??&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 19 Nov 2011 11:24:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-performance-issue/m-p/8346311#M1639611</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-11-19T11:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: For all entries - Performance Issue</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-performance-issue/m-p/8346312#M1639612</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;After each DELETE ADJACENT DUPLICATES statement and before the SELECT, did you put a clause to ensure that the internal table has some entries in it? Not doing so will make the SELECT query unrestricted when some internal table is empty&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ensure your coding is like below (if it is not already so)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DELETE ADJACENT DUPLICATES FROM itab COMPARING key1 key2 ...

IF NOT itab[] IS INITIAL.
  SELECT xxxx
    FROM dbtable
      FOR ALL ENTRIES IN itab
        WHERE xxx
ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 19 Nov 2011 11:34:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-performance-issue/m-p/8346312#M1639612</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-11-19T11:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: For all entries - Performance Issue</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-performance-issue/m-p/8346313#M1639613</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;Along that coparing internal table should not be inital and note in your where clause you are comaring with more than one internal table or one interal table and select-options the performace of the program will degraded.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ex: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data: s_matnr type s_matnr.
selct-options : s_sel  type s_matnr.
-------------------------------
-----------------------------------
if it_tab1[] is not initial.
 select field1
            field2
            from &amp;lt;DB&amp;gt; into it_tab2
            for all entries in it_tab1
             where &amp;lt;field&amp;gt; = it_tab1-&amp;lt;field&amp;gt;
              and    &amp;lt;field1&amp;gt; in s_sel.  --------------------&amp;gt; this will degrade the performace of the program.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;            &lt;/P&gt;&lt;P&gt;In this case btter write a join or make a view.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Phani.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 19 Nov 2011 13:58:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-performance-issue/m-p/8346313#M1639613</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-11-19T13:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: For all entries - Performance Issue</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-performance-issue/m-p/8346314#M1639614</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;FIRST&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;If you might have observed, the resultant table that you fetch from the database does not have the duplicate entries when you use for all entries.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Eg. If the code is -&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if itab1[] is not initial.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select * into table itab2&lt;/P&gt;&lt;P&gt;from table db_tab2&lt;/P&gt;&lt;P&gt;for all entries in itab1&lt;/P&gt;&lt;P&gt;where field1 eq itab1-field1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&amp;gt; then there wont be any duplicate entries in itab2. =&amp;gt; because for all entries automatically deletes the duplicate entries.&lt;/P&gt;&lt;P&gt;-&amp;gt; you might have duplicate entries if you dont include the keyfields in the structure of itab2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SECOND&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Also, if there are any duplicate entries in itab1 - it results in duplicate efforts to fetch the data from database.&lt;/P&gt;&lt;P&gt;-&amp;gt; you can verify this by doing SQL trace ST05 on that query.&lt;/P&gt;&lt;P&gt;-&amp;gt; when you use for all entries, the system basically splits the query in multiple queries and fetches data and then deletes any duplicates from the resultant table if any.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;CONCLUSION&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;These are the only 2 things related to duplication and for all entries.&lt;/P&gt;&lt;P&gt;The tool you are using for evaluation must be a custom tool. Dont use the tool blindly. Understand what the error is for. There must be a user manual with someone within team.&lt;/P&gt;&lt;P&gt;Its upto your judgement wheather you want to accept the suggestion (as it is a warning) given by your tool. You can choose to ignore it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway, using 40 for all entries in the program is also an indication of a bad design. Please do a peer-review of your code, to avoid any performance issue in production.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 Nov 2011 08:19:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-performance-issue/m-p/8346314#M1639614</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-11-20T08:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: For all entries - Performance Issue</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-performance-issue/m-p/8346315#M1639615</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Chinmay..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Very helpful reply..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a ton!! Very informative and well written...:)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 Nov 2011 08:33:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-performance-issue/m-p/8346315#M1639615</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-11-20T08:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: For all entries - Performance Issue</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-performance-issue/m-p/8346316#M1639616</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The DELETE ADJACENT DUPLICATES is actually not the best solution for this task, especially if you need the table including the duplicates later again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Much more elegant is the solution to define a hashed table with a unique key consisting of the fields needed in the FAE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hash   type hashed table of st_fields  with unique table key field1 field2 field3. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and to use a COLLECT!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT itab ASSIGNING &amp;lt;fs&amp;gt;.
   wa-field1 = &amp;lt;fs&amp;gt;-field1.
   wa-field1 = &amp;lt;fs&amp;gt;-field1.
   wa-field1 = &amp;lt;fs&amp;gt;-field1.
   COLLECT wa INTO hash.
ENDLOOP.

SELECT   ...
       FOR ALL ENTRIES in hash
       WHERE field1 = hash-field1
       AND       field2 = hash-field2
       AND       field3 = hash-field3.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The COLLECT is faster, it copies only the columns which are really needed not large data columns, and &lt;/P&gt;&lt;P&gt;is unique already by construction.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I doubt that you can measure the overhead, it will be smaller than the usual variations of the SELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Nov 2011 09:14:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-performance-issue/m-p/8346316#M1639616</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-11-22T09:14:26Z</dc:date>
    </item>
  </channel>
</rss>

