<?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: Looping constructs in ABAP in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/looping-constructs-in-abap/m-p/2752005#M640133</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The first approach is always better.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First select all the data you REQUIRE from the database. Once the data is available in the application server you can use the LOOP to process the data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The second approach is a big Performance issue. Each pass of the loop the system will go to database. Try avoiding the second option.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt; VJ&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 12 Sep 2007 18:22:49 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-09-12T18:22:49Z</dc:date>
    <item>
      <title>Looping constructs in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/looping-constructs-in-abap/m-p/2752003#M640131</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;I have seen many times as first records are fetched using select statement and then they are manipulated and displayed using LOOP...ENDLOOP. and sometimes first LOOP...ENDLOOP is implemented and within it there exists a OPEN SQL statement to fetch the resultset to be manipulated or processed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Which approach is widely used or what are the situations in which former and later approach is used.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks and Regards&lt;/P&gt;&lt;P&gt;Ameet&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Sep 2007 18:15:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/looping-constructs-in-abap/m-p/2752003#M640131</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-12T18:15:39Z</dc:date>
    </item>
    <item>
      <title>Re: Looping constructs in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/looping-constructs-in-abap/m-p/2752004#M640132</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;both are same,,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but first approach is good compare to second one.bec performance wise &lt;/P&gt;&lt;P&gt;first we select the data and process it in loop and enloop.&lt;/P&gt;&lt;P&gt;in case of second apporche system will take lot of time to select the&lt;/P&gt;&lt;P&gt;data with in a loop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Sep 2007 18:18:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/looping-constructs-in-abap/m-p/2752004#M640132</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-12T18:18:37Z</dc:date>
    </item>
    <item>
      <title>Re: Looping constructs in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/looping-constructs-in-abap/m-p/2752005#M640133</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The first approach is always better.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First select all the data you REQUIRE from the database. Once the data is available in the application server you can use the LOOP to process the data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The second approach is a big Performance issue. Each pass of the loop the system will go to database. Try avoiding the second option.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt; VJ&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Sep 2007 18:22:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/looping-constructs-in-abap/m-p/2752005#M640133</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-12T18:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: Looping constructs in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/looping-constructs-in-abap/m-p/2752006#M640134</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ameet,&lt;/P&gt;&lt;P&gt;I prefer doing select at first then loop the values to process data further.&lt;/P&gt;&lt;P&gt;It will cause additional time for some cases, &lt;/P&gt;&lt;P&gt;but the second method will ALWAYS add some unneeded times to your programs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using SELECT from inside of LOOP is the most cause of similar queries.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try the following codes, then compare the trace result of both method using ST05.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : &lt;/P&gt;&lt;P&gt;begin of it_vbap occurs 1000, &lt;/P&gt;&lt;P&gt;vbeln like vbap-vbeln,&lt;/P&gt;&lt;P&gt;posnr like vbap-posnr,&lt;/P&gt;&lt;P&gt;matnr like vbap-matnr,&lt;/P&gt;&lt;P&gt;maktx like makt-maktx,&lt;/P&gt;&lt;P&gt;end of it_vbap,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;begin of it_makt occurs 1000,&lt;/P&gt;&lt;P&gt;matnr like makt-matnr,&lt;/P&gt;&lt;P&gt;maktx like makt-maktx,&lt;/P&gt;&lt;P&gt;end of it_makt,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it_vbapm like it_vbap occurs 1000 with header line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select vbeln posnr matnr from vbap into it_vbap up to 1000 rows.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at it_vbap.&lt;/P&gt;&lt;P&gt; select single maktx into it_vbap-maktx from makt&lt;/P&gt;&lt;P&gt; where matnr = it_vbap-mantr.&lt;/P&gt;&lt;P&gt; modify it_vbap.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;break-point.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select vbeln posnr matnr from vbap into it_vbap up to 1000 rows.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort it_vbap by matnr.&lt;/P&gt;&lt;P&gt;it_vbapm[] = it_vbap[].&lt;/P&gt;&lt;P&gt;delete adjacent duplicates from it_vbapm comparing matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if it_vbapm[] is not initial.&lt;/P&gt;&lt;P&gt;  select matnr maktx from makt into table it_makt &lt;/P&gt;&lt;P&gt;  for all entries of it_vbapm where matnr = it_vbapm-matnr.&lt;/P&gt;&lt;P&gt; sort it_makt by matnr.&lt;/P&gt;&lt;P&gt;endif.   &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at it_vbap.&lt;/P&gt;&lt;P&gt; read table it_makt with key matnr = it_vbap-matnr binary search.&lt;/P&gt;&lt;P&gt; if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;  it_vbap-maktx = it_makt-maktx.&lt;/P&gt;&lt;P&gt;  modify it_vbap.&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>Wed, 12 Sep 2007 20:16:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/looping-constructs-in-abap/m-p/2752006#M640134</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-09-12T20:16:10Z</dc:date>
    </item>
  </channel>
</rss>

