<?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 How to avoid select query in loop in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-select-query-in-loop/m-p/6278587#M1387827</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;&lt;/P&gt;&lt;P&gt;I have to select entries from table iclpay looping it_dfkkop and delete the entries in it_dfkkop_tmp which are not present in iclpay.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For this If use below code its working fine, but there is performance issue&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    CLEAR: it_iclpay[],it_iclpay.&lt;/P&gt;&lt;P&gt;    LOOP AT it_dfkkop_tmp.&lt;/P&gt;&lt;P&gt;      SELECT claim documentref paycat status FROM iclpay&lt;/P&gt;&lt;P&gt;                APPENDING CORRESPONDING FIELDS OF TABLE it_iclpay&lt;/P&gt;&lt;P&gt;                        WHERE&lt;/P&gt;&lt;P&gt;                              active = c_active AND&lt;/P&gt;&lt;P&gt;                              claim = it_dfkkop_tmp-claim AND&lt;/P&gt;&lt;P&gt;                              documentref = it_dfkkop_tmp-opbel.&lt;/P&gt;&lt;P&gt;      IF sy-subrc NE 0.&lt;/P&gt;&lt;P&gt;        DELETE it_dfkkop_tmp.&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;&lt;/P&gt;&lt;P&gt;If I write the code like below its not working&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    SELECT claim documentref paycat status FROM iclpay&lt;/P&gt;&lt;P&gt;            INTO TABLE it_iclpay&lt;/P&gt;&lt;P&gt;                    FOR ALL ENTRIES IN it_dfkkop_tmp WHERE&lt;/P&gt;&lt;P&gt;                          active = c_active AND&lt;/P&gt;&lt;P&gt;                          claim = it_dfkkop_tmp-claim AND&lt;/P&gt;&lt;P&gt;                          documentref = it_dfkkop_tmp-opbel.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone help on this.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 26 Oct 2009 10:54:35 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-10-26T10:54:35Z</dc:date>
    <item>
      <title>How to avoid select query in loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-select-query-in-loop/m-p/6278587#M1387827</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;&lt;/P&gt;&lt;P&gt;I have to select entries from table iclpay looping it_dfkkop and delete the entries in it_dfkkop_tmp which are not present in iclpay.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For this If use below code its working fine, but there is performance issue&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    CLEAR: it_iclpay[],it_iclpay.&lt;/P&gt;&lt;P&gt;    LOOP AT it_dfkkop_tmp.&lt;/P&gt;&lt;P&gt;      SELECT claim documentref paycat status FROM iclpay&lt;/P&gt;&lt;P&gt;                APPENDING CORRESPONDING FIELDS OF TABLE it_iclpay&lt;/P&gt;&lt;P&gt;                        WHERE&lt;/P&gt;&lt;P&gt;                              active = c_active AND&lt;/P&gt;&lt;P&gt;                              claim = it_dfkkop_tmp-claim AND&lt;/P&gt;&lt;P&gt;                              documentref = it_dfkkop_tmp-opbel.&lt;/P&gt;&lt;P&gt;      IF sy-subrc NE 0.&lt;/P&gt;&lt;P&gt;        DELETE it_dfkkop_tmp.&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;&lt;/P&gt;&lt;P&gt;If I write the code like below its not working&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    SELECT claim documentref paycat status FROM iclpay&lt;/P&gt;&lt;P&gt;            INTO TABLE it_iclpay&lt;/P&gt;&lt;P&gt;                    FOR ALL ENTRIES IN it_dfkkop_tmp WHERE&lt;/P&gt;&lt;P&gt;                          active = c_active AND&lt;/P&gt;&lt;P&gt;                          claim = it_dfkkop_tmp-claim AND&lt;/P&gt;&lt;P&gt;                          documentref = it_dfkkop_tmp-opbel.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone help on this.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Oct 2009 10:54:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-select-query-in-loop/m-p/6278587#M1387827</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-26T10:54:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to avoid select query in loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-select-query-in-loop/m-p/6278588#M1387828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What do you mean by not working? The purpose of using FOR ALL ENTRIES is to avoid select query within loop. Are you getting any error or dump with your second select query?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Oct 2009 11:07:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-select-query-in-loop/m-p/6278588#M1387828</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-26T11:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to avoid select query in loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-select-query-in-loop/m-p/6278589#M1387829</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It did not dump but did not get final(required) output.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I got the solution now.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot for responding.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have written the below code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT claim&lt;/P&gt;&lt;P&gt;           documentref&lt;/P&gt;&lt;P&gt;           paycat&lt;/P&gt;&lt;P&gt;           status&lt;/P&gt;&lt;P&gt;           FROM&lt;/P&gt;&lt;P&gt;           iclpay&lt;/P&gt;&lt;P&gt;           APPENDING CORRESPONDING FIELDS OF TABLE it_iclpay&lt;/P&gt;&lt;P&gt;           FOR ALL ENTRIES IN it_dfkkop_tmp WHERE&lt;/P&gt;&lt;P&gt;                              active = c_active AND&lt;/P&gt;&lt;P&gt;                              claim = it_dfkkop_tmp-claim AND&lt;/P&gt;&lt;P&gt;                              documentref = it_dfkkop_tmp-opbel.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    SORT it_dfkkop_tmp BY claim opbel.&lt;/P&gt;&lt;P&gt;    LOOP AT it_dfkkop_tmp.&lt;/P&gt;&lt;P&gt;      READ TABLE it_iclpay INTO  wa_iclpay WITH KEY&lt;/P&gt;&lt;P&gt;                          claim        = it_dfkkop_tmp-claim&lt;/P&gt;&lt;P&gt;                          documentref  = it_dfkkop_tmp-opbel.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      IF sy-subrc NE 0.&lt;/P&gt;&lt;P&gt;        DELETE it_dfkkop_tmp.&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>Mon, 26 Oct 2009 12:04:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-select-query-in-loop/m-p/6278589#M1387829</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-26T12:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to avoid select query in loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-select-query-in-loop/m-p/6278590#M1387830</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Answered&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Oct 2009 12:05:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-select-query-in-loop/m-p/6278590#M1387830</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-26T12:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to avoid select query in loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-select-query-in-loop/m-p/6278591#M1387831</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;if it selects nothing, then there probably nothing to delete.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your FAE looks fine to me:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What you need is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;define itab1 as SORTED TABLE ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
if NOT ( itab IS INITIAL).
  SELECT 
       INTO TABLE itab1
       ...
       FOR ALL ENTRIES itab0
       ... 
ENDIF.

if NOT ( itab1 IS INITIAL).
  LOOP AT itab0 INTO wa0.
     READ TABLE itab1 WITH KEY ...
     IF ( sy/subrc ne 0 ).
       APPEND wa TO itab2.
      ENDIF.
   ENDLOOP.
   DELETE dbtab FROM TABLE itab2.
  ENDIF.
ELSE
   DELETE dbtab FROM TABLE itab0.
ENDIF.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;details are not hard to figure out!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Oct 2009 12:08:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-select-query-in-loop/m-p/6278591#M1387831</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-26T12:08:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to avoid select query in loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-select-query-in-loop/m-p/6278592#M1387832</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Answered&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;only half&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Oct 2009 12:09:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-select-query-in-loop/m-p/6278592#M1387832</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-26T12:09:31Z</dc:date>
    </item>
  </channel>
</rss>

