<?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: Difference between select and open cursor + fetch cursor in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-select-and-open-cursor-fetch-cursor/m-p/7285304#M1532077</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi  Suraj Shenoy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do not think there is much difference. The OPEN CURSOR .. fetch technique is rarely seen in any newly-developed programs. The PACKAGE SIZE can be used without cursor and fetch. It makes sense if you process each package directly sfter gettin it from  the database.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Meanwhile, after the database optimizer has been improved a lot, you really do not have to care about it too much. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Performance can be gained by selecting required data from the database exactly once and by fetching only the fields you really need.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A table like MARA may have quite big size in the system. This makes it worth first to analyze what fields you really need and then put the fieldnames you need into an internal table, i.e. lt_required_fields type table of fieldname, then select and process blockwise with some experimenting on constant gc_mara_PACKAGE SIZE type sy-dbcnt value 10000.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT (lt_required_fields) 
  INTO CORRESPONDING FIELDS OF TABLE lt_mara_fields
  FROM MARA
  PACKAGE SIZE gc_mara_PACKAGE SIZE
  WHERE ...
* process the entries

ENDSELECT.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would not use the 'open cursor' .. 'fetch' technique any longer because there is no obvious advantage and for maintenance it may be not easy to understand. The FETCH statement decouples the INTO clause from the other clauses in the SELECT statement but I just do not see any advantage. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The documentation on [Using a Cursor to Read Data|http://help.sap.com/erp2005_ehp_04/helpdata/EN/fc/eb3b23358411d1829f0000e829fbfe/content.htm] notes that this programming method is quicker for nested databse access with outer and inner loop than using nested SELECT statements, since the cursor for the inner loop does not continually have to be reopened.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think nested database accesses are no good idea at all.&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;Clemens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 19 Sep 2010 12:52:51 GMT</pubDate>
    <dc:creator>Clemenss</dc:creator>
    <dc:date>2010-09-19T12:52:51Z</dc:date>
    <item>
      <title>Difference between select and open cursor + fetch cursor</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-select-and-open-cursor-fetch-cursor/m-p/7285301#M1532074</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have the following two pieces of code. Could you please let me know the difference in performance / database time  and load on the system when this code is executed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assume the table contains 100000 records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-----------------------------------------" /&gt;&lt;P&gt;case1:&lt;/P&gt;&lt;P&gt;select * from mara into corresponding fields of table &amp;lt;internal_table&amp;gt;.&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-----------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-----------------------------------------" /&gt;&lt;P&gt;case2: &lt;/P&gt;&lt;P&gt;open cursor g_cursor with hold for select * from mara package size 5000.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do.&lt;/P&gt;&lt;P&gt;fetch next cursor g_cursor appending corresponding fields of table &amp;lt;internal_table&amp;gt;.&lt;/P&gt;&lt;P&gt;enddo.&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-----------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Suraj&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Sep 2010 09:47:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-select-and-open-cursor-fetch-cursor/m-p/7285301#M1532074</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-09-16T09:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between select and open cursor + fetch cursor</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-select-and-open-cursor-fetch-cursor/m-p/7285302#M1532075</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;Slight change in code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------------------------------------------------------------------------------" /&gt;&lt;P&gt;case1:&lt;/P&gt;&lt;P&gt;select * from mara into corresponding fields of table &amp;lt;internal_table&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------------------------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------------------------------------------------------------------------------" /&gt;&lt;P&gt;case2: &lt;/P&gt;&lt;P&gt;open cursor g_cursor with hold for select * from mara package size 5000.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do.&lt;/P&gt;&lt;P&gt;           fetch next cursor g_cursor appending corresponding fields of table &amp;lt;internal_table&amp;gt;.&lt;/P&gt;&lt;P&gt;           if sy-subrc &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt;                &amp;lt;exit the do loop&amp;gt;&lt;/P&gt;&lt;P&gt;           endif.&lt;/P&gt;&lt;P&gt;enddo.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------------------------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Suraj&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Sep 2010 09:52:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-select-and-open-cursor-fetch-cursor/m-p/7285302#M1532075</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-09-16T09:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between select and open cursor + fetch cursor</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-select-and-open-cursor-fetch-cursor/m-p/7285303#M1532076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt;  Could you please let me know the difference in performance / database time  and load on the system when this code is executed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;why don't youmeasure it yourself with ST05 / ST04 ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Sep 2010 09:54:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-select-and-open-cursor-fetch-cursor/m-p/7285303#M1532076</guid>
      <dc:creator>HermannGahm</dc:creator>
      <dc:date>2010-09-16T09:54:25Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between select and open cursor + fetch cursor</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-select-and-open-cursor-fetch-cursor/m-p/7285304#M1532077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi  Suraj Shenoy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do not think there is much difference. The OPEN CURSOR .. fetch technique is rarely seen in any newly-developed programs. The PACKAGE SIZE can be used without cursor and fetch. It makes sense if you process each package directly sfter gettin it from  the database.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Meanwhile, after the database optimizer has been improved a lot, you really do not have to care about it too much. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Performance can be gained by selecting required data from the database exactly once and by fetching only the fields you really need.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A table like MARA may have quite big size in the system. This makes it worth first to analyze what fields you really need and then put the fieldnames you need into an internal table, i.e. lt_required_fields type table of fieldname, then select and process blockwise with some experimenting on constant gc_mara_PACKAGE SIZE type sy-dbcnt value 10000.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT (lt_required_fields) 
  INTO CORRESPONDING FIELDS OF TABLE lt_mara_fields
  FROM MARA
  PACKAGE SIZE gc_mara_PACKAGE SIZE
  WHERE ...
* process the entries

ENDSELECT.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would not use the 'open cursor' .. 'fetch' technique any longer because there is no obvious advantage and for maintenance it may be not easy to understand. The FETCH statement decouples the INTO clause from the other clauses in the SELECT statement but I just do not see any advantage. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The documentation on [Using a Cursor to Read Data|http://help.sap.com/erp2005_ehp_04/helpdata/EN/fc/eb3b23358411d1829f0000e829fbfe/content.htm] notes that this programming method is quicker for nested databse access with outer and inner loop than using nested SELECT statements, since the cursor for the inner loop does not continually have to be reopened.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think nested database accesses are no good idea at all.&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;Clemens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 19 Sep 2010 12:52:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-select-and-open-cursor-fetch-cursor/m-p/7285304#M1532077</guid>
      <dc:creator>Clemenss</dc:creator>
      <dc:date>2010-09-19T12:52:51Z</dc:date>
    </item>
  </channel>
</rss>

