<?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 OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055746#M1175015</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This message was moderated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 08 Jan 2009 05:36:36 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-01-08T05:36:36Z</dc:date>
    <item>
      <title>Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055744#M1175013</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;Can some one please elaborate on the difference between the above ways of getting data. I have gone through the documentation, but it does not directly mention anything about performance differences between them, also please cite the link which can give more detailed info about this conceptually. Most of them show the syntax diagrams only and ways to use the cursor&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;ChK&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2009 05:25:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055744#M1175013</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-08T05:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055745#M1175014</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If documentation provided is not sufficient, just put a search using proper subject line on SCN.&lt;/P&gt;&lt;P&gt;You will get lots of threads.&lt;/P&gt;&lt;P&gt;Check this also [www.help.sap.com]&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2009 05:31:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055745#M1175014</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-08T05:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055746#M1175015</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This message was moderated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2009 05:36:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055746#M1175015</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-08T05:36:36Z</dc:date>
    </item>
    <item>
      <title>Re: Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055747#M1175016</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This message was moderated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2009 07:02:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055747#M1175016</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-08T07:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055748#M1175017</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;At database level, I think they are the same. But at ABAP level, there are some differences (just compare by yourself, and it may depend on the abap release you use) that the developer would prefer to use one, or the other.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2009 22:16:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055748#M1175017</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2009-01-08T22:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055749#M1175018</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;Refer to this link..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[Open Cursor Vs Open Sql (SELECT)|&lt;A class="jive_macro jive_macro_message" href="https://community.sap.com/" __jive_macro_name="message" modifiedtitle="true" __default_attr="4730745"&gt;&lt;/A&gt;]&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Jan 2009 02:08:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055749#M1175018</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-09T02:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055750#M1175019</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Avinash, this thread doesn't discuss about SELECT...ENDSELECT&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ChK, I have found nothing in SDN forums, blogs and wikis. It would be worth everybody participates in this thread to give some valuable feedback.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In google, I found one of the reasons to use OPEN CURSOR over SELECT...ENDSELECT and I agree (sorry to copy but I wanted to highlight it out) :&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; SLKorolev wrote on Fri Jun 08, 2007 9:14 am [in a sapfans thread|http://www.sapfans.com/forums/viewtopic.php?t=231963]  :&lt;/P&gt;&lt;P&gt;&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;gt; Suppose you need to extract some table content by portions, say in BW-R/3 interface which works technically by issuing several RFC calls (until the whole result set is tranfered). Certainly you can not use SELECT ENDSELECT here as it will open the same select every time the FM called. So, in that case you can declare OPEN CURSOR with HOLD and transfer every time next portion of query result set as the current cursor position will be saved between FM calls.&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Moreover, I have extracted (below) syntax diagrams for both constructs from [abap 7.1 documentation|http://help.sap.com/abapdocu/en/ABENABAP.htm], we see that there are very few differences.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
OPEN CURSOR [WITH HOLD] dbcur FOR 
  SELECT ... 
         FROM ... 
         [[FOR ALL ENTRIES IN itab]
           WHERE sql_cond] 
         [GROUP BY ...]
         [HAVING sql_cond] 
         [ORDER BY ...]. 

* Here you may repeat several FETCH
FETCH NEXT CURSOR dbcur 
    { { INTO { {[CORRESPONDING FIELDS OF] wa} | (dobj1, dobj2, ...) } } 
    | { INTO|APPENDING [CORRESPONDING FIELDS OF] TABLE itab 
                       [PACKAGE SIZE n] } }.

CLOSE CURSOR dbcur.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT ...
       FROM ...
    { { INTO { {[CORRESPONDING FIELDS OF] wa} | (dobj1, dobj2, ...) } } 
    | { INTO|APPENDING [CORRESPONDING FIELDS OF] TABLE itab 
                       [PACKAGE SIZE n] } }
         [[FOR ALL ENTRIES IN itab]
           WHERE sql_cond] 
         [GROUP BY ...]
         [HAVING sql_cond] 
         [ORDER BY ...]. 
  ... 
ENDSELECT.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think the only differences are summarized here (excerpts from abap 7.1 documentation):&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;\[WITH HOLD...\] Leaves the cursor open in the case of an explicitly triggered database commit or database rollback&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;Within a SELECT-loop you cannot execute any statements that lead to a database commit, or database rollback and consequently cause the corresponding database cursor to close&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;A database cursor is opened implicitly to process a SELECT-loop, and is closed again when the loop is ended. You can end the loop using the statements from section leave loops&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, as I said in previous post, I still think that in older releases, there were some differences (if I remember well, package size was not available in one of the 2 constructs), and maybe one of the two was created after the other.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thus, you just have more functions with OPEN CURSOR...FETCH...CLOSE than with SELECT...ENDSELECT&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 10 Jan 2009 10:26:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055750#M1175019</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2009-01-10T10:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055751#M1175020</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sandra,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for compiling all the information into one piece. I think, we need to get more information on this to understand this better. I have analysed that, the Cursor performs better compared to the SELECT...ENDSELECT and also, SELECT statement if used normally.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;ChK&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jan 2009 05:35:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055751#M1175020</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-12T05:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055752#M1175021</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Harsha,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using of OPEN CURSOR..FETCH CURSOR..CLOSE is much better for performance than using of SELECT.....ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and for details just goto SE38 and write these keywords than press F1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think it will clear your Doubt.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sujeet.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jan 2009 05:58:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055752#M1175021</guid>
      <dc:creator>SujeetMishra</dc:creator>
      <dc:date>2009-01-12T05:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055753#M1175022</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sujeet,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;could you indicate the url to this doc because I couldn't find this information. What I just found are the performance notes here (similar to F1 in SE38 editor) : &lt;A href="http://help.sap.com/abapdocu/en/ABENOPEN_SQL_PERFO.htm" target="test_blank"&gt;http://help.sap.com/abapdocu/en/ABENOPEN_SQL_PERFO.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;There is nothing in cursor documentations : [OPEN CURSOR|http://help.sap.com/abapdocu/en/ABAPOPEN_CURSOR.htm], [FETCH|http://help.sap.com/abapdocu/en/ABAPFETCH.htm], [CLOSE CURSOR|http://help.sap.com/abapdocu/en/ABAPCLOSE_CURSOR.htm].&lt;/P&gt;&lt;P&gt;Neither in [SELECT|http://help.sap.com/abapdocu/en/ABAPSELECT.htm] and [ENDSELECT|http://help.sap.com/abapdocu/en/ABAPENDSELECT.htm]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway, it made me think that I could test performance by myself:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA curs TYPE cursor.
DATA bseg TYPE bseg.
OPEN CURSOR curs FOR SELECT * FROM bseg.
DO.
FETCH NEXT CURSOR curs INTO bseg.
IF sy-subrc &amp;lt;&amp;gt; 0.
  exit.
endif.
ENDDO.
CLOSE CURSOR curs.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;compared to&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA bseg TYPE bseg.
SELECT * FROM bseg INTO bseg.
ENDSELECT.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;BSEG contains around 40000 lines.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It gives the following results (I ran it many times to be sure, it doesn't change) :&lt;/P&gt;&lt;P&gt;with cursor:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;2.490.985 microseconds&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;with select...endselect :&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;2.490.317 microseconds&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also looked at the SQL trace, the statements are absolutely identical !&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hence, this prooves that they are technically equivalent (or did I miss something?)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sandra&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jan 2009 10:41:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055753#M1175022</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2009-01-12T10:41:27Z</dc:date>
    </item>
    <item>
      <title>Re: Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055754#M1175023</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;We use OPEN CURSOR..FETCH CURSOR..CLOSE statements to retrieve data from different server (NON SAP table) or a heavy table like POS (Point of sale) table.&lt;/P&gt;&lt;P&gt;Also when we use these statement we use NATIVE SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT .... ENDSELECT can not be used to get data a table which is in the different server.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Subhankar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jan 2009 10:49:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055754#M1175023</guid>
      <dc:creator>Subhankar</dc:creator>
      <dc:date>2009-01-12T10:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055755#M1175024</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sandra,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a completely different results when I ran the code using CURSOR and SELECT statements for the following code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the code extract that demonstrates the time taken to fetch records from the table VBAK.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;GET RUN TIME FIELD F1.&lt;/P&gt;&lt;P&gt;SELECT VBELN ERNAM VBTYP AUART INTO CORRESPONDING FIELDS OF ITAB&lt;/P&gt;&lt;P&gt;FROM VBAK UP TO 100 ROWS.&lt;/P&gt;&lt;P&gt;APPEND ITAB.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;GET RUN TIME FIELD F2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;f3 = f2 - f1.&lt;/P&gt;&lt;P&gt;WRITE:/'Runtime test1 F3',F3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;GET RUN TIME FIELD F1. u201CFetches runtime for executing the data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;u201CThis is to Open the Cursor for the SELECT statement.&lt;/P&gt;&lt;P&gt;OPEN CURSOR c_cursor FOR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT VBELN ERNAM VBTYP AUART&lt;/P&gt;&lt;P&gt;FROM VBAK UP TO 100 ROWS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;u201CMove the data from the Cursor into the target area.&lt;/P&gt;&lt;P&gt;FETCH NEXT CURSOR c_cursor INTO&lt;/P&gt;&lt;P&gt;  TABLE itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;u201CClose the Cursor to complete the operation.&lt;/P&gt;&lt;P&gt;CLOSE CURSOR c_cursor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;GET RUN TIME FIELD F2. u201CFetches runtime info from previous RUNTIME command.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;f3 = f2 - f1.&lt;/P&gt;&lt;P&gt;WRITE:/'Runtime test2 F3',F3. u201C Time taken to execute statements between the two RUNTIME statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; Data from the test run can be found in the following screen shots. ( 4 Test runs taken )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Runtime test1 F3=&amp;gt; Runtime performance for SELECTu2026ENDSELECT&lt;/P&gt;&lt;P&gt;Runtime test2 F3=&amp;gt; Runtime performance for CURSOR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Test Run 1: Selecting 10 rows from VBAK table.      1095         548&lt;/P&gt;&lt;P&gt;Test Run 2: Selecting 100 rows from VBAK table.    1629        1721&lt;/P&gt;&lt;P&gt;Test Run 3: Selecting 1000 rows from VBAK table.  18198      12160&lt;/P&gt;&lt;P&gt;Test Run 4: Selecting 10000 rows from VBAK table. 252172   185468&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;bold&lt;/STRONG&gt;Performance Analysis for CURSOR Vs SELECT Statement&lt;STRONG&gt;bold&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the code extract that demonstrates the time taken to fetch records from the table VBAK. (Using a SELECT statement into an internal table with Header Line)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;GET RUN TIME FIELD F1.&lt;/P&gt;&lt;P&gt;GET RUN TIME FIELD F1.&lt;/P&gt;&lt;P&gt;SELECT VBELN ERNAM VBTYP AUART INTO TABLE ITAB&lt;/P&gt;&lt;P&gt;FROM VBAK UP TO 100 ROWS.&lt;/P&gt;&lt;P&gt;GET RUN TIME FIELD F2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;f3 = f2 - f1.&lt;/P&gt;&lt;P&gt;WRITE:/'Runtime test1 F3',F3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;GET RUN TIME FIELD F1. u201CFetches runtime for executing the data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;u201CThis is to Open the Cursor for the SELECT statement.&lt;/P&gt;&lt;P&gt;OPEN CURSOR c_cursor FOR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT VBELN ERNAM VBTYP AUART&lt;/P&gt;&lt;P&gt;FROM VBAK UP TO 100 ROWS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;u201CMove the data from the Cursor into the target area.&lt;/P&gt;&lt;P&gt;FETCH NEXT CURSOR c_cursor INTO&lt;/P&gt;&lt;P&gt;  TABLE itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;u201CClose the Cursor to complete the operation.&lt;/P&gt;&lt;P&gt;CLOSE CURSOR c_cursor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;GET RUN TIME FIELD F2. u201CFetches runtime info from previous RUNTIME command.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;f3 = f2 - f1.&lt;/P&gt;&lt;P&gt;WRITE:/'Runtime test2 F3',F3. u201C Time taken to execute statements between the two RUNTIME statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; Data from the test run can be found in the following screen shots. (4 Test runs taken)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Runtime test1 F3=&amp;gt; Runtime performance for SELECTu2026INTOu2026&lt;/P&gt;&lt;P&gt;Runtime test2 F3=&amp;gt; Runtime performance for CURSOR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Test Run 1: Selecting 10 rows from VBAK table.            964,                 582&lt;/P&gt;&lt;P&gt;Test Run 2: Selecting 100 rows from VBAK table.         1686,               1533&lt;/P&gt;&lt;P&gt;Test Run 3: Selecting 1000 rows from VBAK table.     33,382,            11,350&lt;/P&gt;&lt;P&gt;Test Run 4: Selecting 10000 rows from VBAK table.  220,920,          113,165&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jan 2009 10:58:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055755#M1175024</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-12T10:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055756#M1175025</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please find further information on this in Wiki " SELECT Statements and CURSOR statement - Performance Analysis ". Updated a few minutes ago.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; Regards&lt;/P&gt;&lt;P&gt;Harsha&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jan 2009 11:20:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055756#M1175025</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-12T11:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055757#M1175026</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Harsha,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First of all, I think there is something wrong how you use the UP TO ROWS and FETCH.&lt;/P&gt;&lt;P&gt;UP TO ROWS just limit the &lt;STRONG&gt;maximum&lt;/STRONG&gt; number of lines that you can get from database. If you call FETCH only once you are not sure to get all lines, as FETCH reads one package at a time and you don't know the &lt;STRONG&gt;package size&lt;/STRONG&gt; (if it is calculated by the system to be let say 50, the fetch will return only 50 lines instead of expected 100). You must also use PACKAGE SIZE to set the &lt;STRONG&gt;minimum&lt;/STRONG&gt; number of lines. Do the same for SELECT...ENDSELECT so that you can compare results on the same basis.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, I see the following 2 problems :&lt;/P&gt;&lt;P&gt;- For the first program, your test is not correct as you don't use the same statements for both tests : You use APPEND itab for SELECT...ENDSELECT but you use INTO TABLE for FETCH. It's a very good reason for FETCH test to be faster according to me.&lt;/P&gt;&lt;P&gt;- For the second program, your test is not correct as you use SELECT INTO TABLE without ENDSELECT. I think you had problems with the syntax INTO TABLE because you didn't use PACKAGE SIZE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can code your SELECT this way and repeat your tests:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT VBELN ERNAM VBTYP AUART INTO TABLE itab
   FROM VBAK UP TO 100 ROWS PACKAGE SIZE 100.
* nothing
ENDSELECT.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and :&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;OPEN CURSOR c_cursor FOR
   SELECT VBELN ERNAM VBTYP AUART
   FROM VBAK UP TO 100 ROWS.
FETCH NEXT CURSOR c_cursor INTO TABLE itab PACKAGE SIZE 100.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Again, I get no difference between the 2 methods.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jan 2009 11:48:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055757#M1175026</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2009-01-12T11:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055758#M1175027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't find the wiki, which url is it ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jan 2009 11:50:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055758#M1175027</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2009-01-12T11:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055759#M1175028</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://www.sdn.sap.com/irj/scn/wiki" target="test_blank"&gt;https://www.sdn.sap.com/irj/scn/wiki&lt;/A&gt;&lt;/P&gt;&lt;P&gt;     SELECT Statements and CURSOR statement - Performance Analysis...I have updated it 33 mins ago&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Harsha Cheruku on Jan 12, 2009 12:59 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jan 2009 11:59:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055759#M1175028</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-12T11:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055760#M1175029</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;okay I found it : [wiki SELECT Statements and CURSOR statement - Performance Analysis|https://wiki.sdn.sap.com/wiki/display/ABAP/SELECT&lt;EM&gt;Statements&lt;/EM&gt;and&lt;EM&gt;CURSOR&lt;/EM&gt;statement&lt;EM&gt;-&lt;/EM&gt;Performance+Analysis.]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That's great that you share your experience with people, thank you very much!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jan 2009 12:08:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055760#M1175029</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2009-01-12T12:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055761#M1175030</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you!!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jan 2009 12:20:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055761#M1175030</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-12T12:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055762#M1175031</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have found the answer&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jan 2009 12:20:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055762#M1175031</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-12T12:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: Difference  between OPEN CURSOR..FETCH CURSOR..CLOSE and SELECT...ENDSELECT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055763#M1175032</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Which is what?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jan 2009 13:29:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/difference-between-open-cursor-fetch-cursor-close-and-select-endselect/m-p/5055763#M1175032</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2009-01-12T13:29:34Z</dc:date>
    </item>
  </channel>
</rss>

