<?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 Avoiding nested Loops in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoiding-nested-loops/m-p/10894570#M1889248</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;My loop condition is taking much time for execution. The tables used are BKPF &amp;amp; BSEG. Please find the condition given below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT T_BKPF WHERE SUPER = T_SUPER-NAME.&lt;/P&gt;&lt;P&gt;IF USNAM NE T_BKPF-USNAM.&lt;/P&gt;&lt;P&gt;MOVE T_BKPF-UNAM TO H-USNAM.&lt;/P&gt;&lt;P&gt;NEW-PAGE.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PERFORM OUT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT T_BSEG WHERE BELNR = T_BKPF-BELNR&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AND&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GJAHR = T_BKPF-GJAHE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CASE T_BSEG-KOART.&lt;/P&gt;&lt;P&gt;WHEN 'L'.&lt;/P&gt;&lt;P&gt;PERFOM....&lt;/P&gt;&lt;P&gt;...................&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDCASE.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please help me to over come this issue.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 04 Mar 2015 06:00:49 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2015-03-04T06:00:49Z</dc:date>
    <item>
      <title>Avoiding nested Loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoiding-nested-loops/m-p/10894570#M1889248</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;My loop condition is taking much time for execution. The tables used are BKPF &amp;amp; BSEG. Please find the condition given below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT T_BKPF WHERE SUPER = T_SUPER-NAME.&lt;/P&gt;&lt;P&gt;IF USNAM NE T_BKPF-USNAM.&lt;/P&gt;&lt;P&gt;MOVE T_BKPF-UNAM TO H-USNAM.&lt;/P&gt;&lt;P&gt;NEW-PAGE.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PERFORM OUT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT T_BSEG WHERE BELNR = T_BKPF-BELNR&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AND&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GJAHR = T_BKPF-GJAHE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CASE T_BSEG-KOART.&lt;/P&gt;&lt;P&gt;WHEN 'L'.&lt;/P&gt;&lt;P&gt;PERFOM....&lt;/P&gt;&lt;P&gt;...................&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDCASE.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please help me to over come this issue.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Mar 2015 06:00:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoiding-nested-loops/m-p/10894570#M1889248</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-03-04T06:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Avoiding nested Loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoiding-nested-loops/m-p/10894571#M1889249</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Barani,&lt;/P&gt;&lt;P&gt; Can you share the full code.&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;Rajkumar Narasimman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Mar 2015 06:11:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoiding-nested-loops/m-p/10894571#M1889249</guid>
      <dc:creator>rajkumarnarasimman</dc:creator>
      <dc:date>2015-03-04T06:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: Avoiding nested Loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoiding-nested-loops/m-p/10894572#M1889250</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;use field-symbols, do not use internal tables with header lines. That should be your 1st step.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Mar 2015 06:16:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoiding-nested-loops/m-p/10894572#M1889250</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-03-04T06:16:19Z</dc:date>
    </item>
    <item>
      <title>Re: Avoiding nested Loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoiding-nested-loops/m-p/10894573#M1889251</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Barani,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) Sort the Internal table before using where condition in loop,&lt;/P&gt;&lt;P&gt;2) Try to avoid using perform inside loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Vinodkumar.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Mar 2015 07:17:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoiding-nested-loops/m-p/10894573#M1889251</guid>
      <dc:creator>vinodkumar_thangavel</dc:creator>
      <dc:date>2015-03-04T07:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: Avoiding nested Loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoiding-nested-loops/m-p/10894574#M1889252</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Barani,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SORT T_BSEG BY belnr gjahr.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;LOOP AT T_BKPF WHERE SUPER = T_SUPER-NAME.&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;IF USNAM NE T_BKPF-USNAM.&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;MOVE T_BKPF-UNAM TO H-USNAM.&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;NEW-PAGE.&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;PERFORM OUT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;STRONG&gt;READ TABLE &lt;/STRONG&gt;&lt;STRONG style="font-size: 13.3333330154419px;"&gt;T_BSEG WITH KEY BELNR = T_BKPF-BELNR &lt;SPAN style="color: #333333; font-size: 12px;"&gt;GJAHR = T_BKPF-GJAHE &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;STRONG style="color: #333333; font-size: 12px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BINARY SEARCH.&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;STRONG style="color: #333333; font-size: 12px;"&gt;IF SY-SUBRC EQ 0.&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;LOOP AT T_BSEG&amp;nbsp; &lt;STRONG&gt;FROM INDEX sy-tabix&lt;/STRONG&gt;.&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;STRONG&gt;IF T_BSEG-BELNR EQ &lt;/STRONG&gt;&lt;STRONG style="font-size: 13.3333330154419px;"&gt;T_BKPF-BELNR AND &lt;SPAN style="color: #333333; font-size: 12px;"&gt;T_BSEG-&lt;/SPAN&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;&lt;STRONG&gt;GJAHR = T_BKPF-GJAHE.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;CASE T_BSEG-KOART.&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;WHEN 'L'.&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;PERFOM....&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;...................&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;ENDCASE.&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;STRONG&gt;ELSE.&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EXIT.&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;STRONG&gt;ENDIF.&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;STRONG&gt;ENDIF.&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;ENDLOOP.&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;ENDLOOP.&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;regards,&lt;/P&gt;&lt;P style="font-size: 12px; color: #333333; background: #ffffff;"&gt;Archer&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Mar 2015 07:57:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoiding-nested-loops/m-p/10894574#M1889252</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-03-04T07:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: Avoiding nested Loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoiding-nested-loops/m-p/10894575#M1889253</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;Really hard to say without the "surrounding code". As far as I can see you've a nested loop because you're performing a join at the abap side. In general I'd delegate that to the database, but for your case it would be interessting how and why t_bkpf and t_bseg are filled. As BESG is a cluster table it's also a special case.&lt;/P&gt;&lt;P&gt;But to answer the question how to avoid nested loops: I'd recommend to join at database.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Franz&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Mar 2015 08:05:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoiding-nested-loops/m-p/10894575#M1889253</guid>
      <dc:creator>franz_reitmayer2</dc:creator>
      <dc:date>2015-03-04T08:05:31Z</dc:date>
    </item>
    <item>
      <title>Re: Avoiding nested Loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoiding-nested-loops/m-p/10894576#M1889254</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Barani,&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;There are two concerns here. &lt;/SPAN&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10pt;"&gt;Using Nested loop which decreases the performance. Instead of that we can use parallel cursor method, which fetches the data using index method. &lt;/SPAN&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;A href="http://wiki.scn.sap.com/wiki/display/Snippets/ABAP+Code+for+Parallel+Cursor+-+Loop+Processing" title="http://wiki.scn.sap.com/wiki/display/Snippets/ABAP+Code+for+Parallel+Cursor+-+Loop+Processing"&gt;ABAP Code for Parallel Cursor - Loop Processing - Code Gallery - SCN Wiki&lt;/A&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10pt;"&gt;Second one is instead of fetching the data from BSEG cluster table, we can fetch from some index table&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 11px; text-decoration: underline;"&gt;&lt;STRONG&gt;INDEX TABLES:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 11px;"&gt;&lt;STRONG&gt;BSID-&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #333333; font-size: 11px;"&gt; Accounting: Secondary Index for Customers (Open Items)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 11px;"&gt;&lt;STRONG&gt;BSAD-&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #333333; font-size: 11px;"&gt; Accounting: Secondary Index for Customers (Cleared Items)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 11px;"&gt;&lt;STRONG&gt;BSIK-&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #333333; font-size: 11px;"&gt; Accounting: Secondary Index for Vendors (Open Items)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 11px;"&gt;&lt;STRONG&gt;BSAK-&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #333333; font-size: 11px;"&gt; Accounting: Secondary Index for Vendors (Cleared Items)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 11px;"&gt;&lt;STRONG&gt;BSIS-&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #333333; font-size: 11px;"&gt; Accounting: Secondary Index for G/L Accounts (Open Items)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 11px;"&gt;&lt;STRONG&gt;BSAS-&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #333333; font-size: 11px;"&gt; Accounting: Secondary Index for G/L Accounts (Cleared Item)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 11px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 11px;"&gt;Please find the link below. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 11px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 11px;"&gt;&lt;A href="http://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=180356001" title="http://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=180356001"&gt;How SAP addressed the performance issues with cluster table BSEG? - ABAP Development - SCN Wiki&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&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;Rajkumar Narasimman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Mar 2015 08:10:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoiding-nested-loops/m-p/10894576#M1889254</guid>
      <dc:creator>rajkumarnarasimman</dc:creator>
      <dc:date>2015-03-04T08:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: Avoiding nested Loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/avoiding-nested-loops/m-p/10894577#M1889255</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;Hi Barani,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;If nested loop cannot be able to avoid, please try with below sample if it helps.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;it's a litter bit difference with the code from &lt;A _jive_internal="true" data-avatarid="48087" data-userid="567390" data-username="dengyong.zhang" href="https://answers.sap.com/people/dengyong.zhang" style="font-size: 12px; color: #8ca9cd; background: #ffffff;"&gt;Dengyong Zhang.&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;&lt;STRONG&gt;T_BKPF_BACKUP = T_BKPF.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;&lt;STRONG&gt;* Remove all unneeded entry to improve performance&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;&lt;STRONG&gt;DELETE T_BKPF_BACKUP WHERE SUPER &amp;lt;&amp;gt; T_SUPER-NAME.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;SORT: T_BKPF_BACKUP BY BUKRS BELNR GJAHR,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; T_BSEG&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BY BUKRS BELNR GJAHR.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;&lt;STRONG&gt;lv_tabix = 1.&amp;nbsp; "Set the starting index 1&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;LOOP AT T_BKPF_BACKUP.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;IF USNAM NE T_BKPF-USNAM.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;MOVE T_BKPF-UNAM TO H-USNAM.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;NEW-PAGE.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;ENDIF.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;PERFORM OUT.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;&amp;nbsp; LOOP AT T_BSEG &lt;STRONG&gt;FROM lv_tabix.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;*&amp;nbsp;&amp;nbsp; Save index &amp;amp; Exit the loop, if the keys are not same&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF T_BKPF_BACKUP-BUKRS &amp;lt;&amp;gt; T_BSEG-BUKRS&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OR T_BKPF_BACKUP-BELNR &amp;lt;&amp;gt; T_BSEG-BELNR&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OR T_BKPF_BACKUP-GJAHR &amp;lt;&amp;gt; T_BSEG-GJAHR.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lv_tabix = sy-tabix.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EXIT.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ENDIF.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;CASE T_BSEG-KOART.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;WHEN 'L'.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;PERFOM....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;...................&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;ENDCASE.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;ENDLOOP.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;ENDLOOP.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Mar 2015 08:57:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/avoiding-nested-loops/m-p/10894577#M1889255</guid>
      <dc:creator>former_member37854</dc:creator>
      <dc:date>2015-03-04T08:57:05Z</dc:date>
    </item>
  </channel>
</rss>

