<?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: Performance tips required for following Query: in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tips-required-for-following-query/m-p/3322375#M795809</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;what is slow and what is fast&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please run the SQL Trace at least two time, check the SQL statement summary and show the Top 10 in the list, what takes longest, how long, how many records are read?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;see&lt;/P&gt;&lt;P&gt;/people/siegfried.boes/blog/2007/09/05/the-sql-trace-st05-150-quick-and-easy&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your last SELECT seems to be o.k.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 30 Jan 2008 12:25:22 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-01-30T12:25:22Z</dc:date>
    <item>
      <title>Performance tips required for following Query:</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tips-required-for-following-query/m-p/3322374#M795808</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; TABLES: vbrk,   "Invoice Header&lt;/P&gt;&lt;P&gt;        vbrp,   "Invoice Details&lt;/P&gt;&lt;P&gt;        mkpf,   "Material document HEader&lt;/P&gt;&lt;P&gt;        mseg,   "Material Document Details&lt;/P&gt;&lt;P&gt;        aufk,   "Production order master&lt;/P&gt;&lt;P&gt;        afko.   "Header data of PP Orders&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TYPES: BEGIN OF t_mseg,&lt;/P&gt;&lt;P&gt;         mblnr   LIKE mseg-mblnr,    "Material document&lt;/P&gt;&lt;P&gt;         mjahr   LIKE mkpf-mjahr,&lt;/P&gt;&lt;P&gt;         budat   LIKE mkpf-budat,&lt;/P&gt;&lt;P&gt;         bwart   LIKE mseg-bwart,    "Movement type&lt;/P&gt;&lt;P&gt;         matnr   LIKE mseg-matnr,    "Material number&lt;/P&gt;&lt;P&gt;         charg   LIKE mseg-charg,    "Batch number&lt;/P&gt;&lt;P&gt;         lgort   LIKE mseg-lgort,    "Storage Location&lt;/P&gt;&lt;P&gt;         aufnr   LIKE mseg-aufnr,    "Production order&lt;/P&gt;&lt;P&gt;         auart   LIKE aufk-auart,    "Order type&lt;/P&gt;&lt;P&gt;         zmatnr  LIKE mseg-matnr,    "Converted material&lt;/P&gt;&lt;P&gt;         zpaufnr LIKE mseg-aufnr,    "Parent Production order&lt;/P&gt;&lt;P&gt;         gstri   LIKE afko-gstri,    "Production Start Date&lt;/P&gt;&lt;P&gt;         gltri   LIKE afko-gltri,    "Production End Date&lt;/P&gt;&lt;P&gt;         gsuzi   LIKE afko-gsuzi,    "Start Time&lt;/P&gt;&lt;P&gt;         geuzi   LIKE afko-geuzi,    "End Time&lt;/P&gt;&lt;P&gt;         noday   TYPE p DECIMALS 3,  "Number of days&lt;/P&gt;&lt;P&gt;         totdy   TYPE p DECIMALS 3,  "Total days&lt;/P&gt;&lt;P&gt;         prdqty  LIKE afko-igmng,    "Total produced quantity&lt;/P&gt;&lt;P&gt;       END OF t_mseg.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: w_sdate TYPE d,                   "Start Date&lt;/P&gt;&lt;P&gt;      w_edate TYPE d,                   "End Date&lt;/P&gt;&lt;P&gt;      w_gstri LIKE afko-gstri,&lt;/P&gt;&lt;P&gt;      w_gltri LIKE afko-gltri,&lt;/P&gt;&lt;P&gt;      w_gsuzi LIKE afko-gsuzi,&lt;/P&gt;&lt;P&gt;      w_geuzi LIKE afko-geuzi,&lt;/P&gt;&lt;P&gt;      w_duration TYPE p DECIMALS 3,&lt;/P&gt;&lt;P&gt;      w_prdqty LIKE afko-igmng.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF i_vbrk OCCURS 0,&lt;/P&gt;&lt;P&gt;        vbeln    LIKE vbrk-vbeln,   "Billing Document&lt;/P&gt;&lt;P&gt;        fkdat    LIKE vbrk-fkdat,   "Billing Date&lt;/P&gt;&lt;P&gt;        vkorg    LIKE vbrk-vkorg,   "Sales Org&lt;/P&gt;&lt;P&gt;        vtweg    LIKE vbrk-vtweg,   "Dist Channel&lt;/P&gt;&lt;P&gt;     END OF i_vbrk,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     BEGIN OF i_vbrp OCCURS 0,&lt;/P&gt;&lt;P&gt;        vbeln    LIKE vbrp-vbeln,   "Billing document&lt;/P&gt;&lt;P&gt;        posnr    LIKE vbrp-posnr,   "Billing Item&lt;/P&gt;&lt;P&gt;        matnr    LIKE vbrp-matnr,   "MAterial&lt;/P&gt;&lt;P&gt;        charg    LIKE vbrp-charg,   "Batch Number&lt;/P&gt;&lt;P&gt;        fklmg    LIKE vbrp-fklmg,   "Quantity&lt;/P&gt;&lt;P&gt;        spart    LIKE vbrp-spart,   "Division&lt;/P&gt;&lt;P&gt;        werks    LIKE vbrp-werks,   "Plant&lt;/P&gt;&lt;P&gt;        bwtar    LIKE vbrp-bwtar,   "Valuation type&lt;/P&gt;&lt;P&gt;        noday    TYPE p DECIMALS 3, "Number of days&lt;/P&gt;&lt;P&gt;        aufnr    LIKE afko-aufnr,&lt;/P&gt;&lt;P&gt;        gstri    LIKE afko-gstri,&lt;/P&gt;&lt;P&gt;        gltri    LIKE afko-gltri,&lt;/P&gt;&lt;P&gt;        gsuzi    LIKE afko-gsuzi,&lt;/P&gt;&lt;P&gt;        geuzi    LIKE afko-geuzi,&lt;/P&gt;&lt;P&gt;        igmng    LIKE afko-igmng,&lt;/P&gt;&lt;P&gt;        auart    LIKE aufk-auart,&lt;/P&gt;&lt;P&gt;     END OF i_vbrp,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     BEGIN OF i_matnr OCCURS 0,&lt;/P&gt;&lt;P&gt;       matnr LIKE vbrp-matnr,&lt;/P&gt;&lt;P&gt;       werks LIKE vbrp-werks,&lt;/P&gt;&lt;P&gt;       charg LIKE vbrp-charg,                          "Gyan3001&lt;/P&gt;&lt;P&gt;     END OF i_matnr,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     i_mseg TYPE SORTED TABLE OF t_mseg WITH NON-UNIQUE KEY matnr charg bwart lgort WITH HEADER LINE,&lt;/P&gt;&lt;P&gt;     i_mseg2 TYPE SORTED TABLE OF t_mseg WITH NON-UNIQUE KEY matnr charg bwart lgort WITH HEADER LINE,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     i_mseg1 TYPE SORTED TABLE OF t_mseg WITH NON-UNIQUE KEY zmatnr charg WITH HEADER LINE.&lt;/P&gt;&lt;P&gt;data:  idx type sy-tabix.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Selection Input&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.&lt;/P&gt;&lt;P&gt;*PARAMETERS p_bukrs LIKE bsis-bukrs.&lt;/P&gt;&lt;P&gt;SELECT-OPTIONS: s_date FOR mkpf-budat.      " default sy-datum.&lt;/P&gt;&lt;P&gt;SELECTION-SCREEN: END OF BLOCK blk1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;w_sdate = s_date-low.&lt;/P&gt;&lt;P&gt;w_edate = s_date-high.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;START-OF-SELECTION.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Collection of Invoice header data&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  SELECT vbrk~vbeln&lt;/P&gt;&lt;P&gt;         vbrk~fkdat&lt;/P&gt;&lt;P&gt;         vbrk~vkorg&lt;/P&gt;&lt;P&gt;         vbrk~vtweg&lt;/P&gt;&lt;P&gt;      INTO TABLE i_vbrk&lt;/P&gt;&lt;P&gt;      FROM vbrk&lt;/P&gt;&lt;P&gt;      WHERE fkdat &amp;gt;= w_sdate&lt;/P&gt;&lt;P&gt;      AND   fkdat &amp;lt;= w_edate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Collecting Data from VBRP&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  IF NOT i_vbrk[] IS INITIAL.&lt;/P&gt;&lt;P&gt;    SELECT vbrp~vbeln&lt;/P&gt;&lt;P&gt;           vbrp~posnr&lt;/P&gt;&lt;P&gt;           vbrp~matnr&lt;/P&gt;&lt;P&gt;           vbrp~charg&lt;/P&gt;&lt;P&gt;           vbrp~fklmg&lt;/P&gt;&lt;P&gt;           vbrp~spart&lt;/P&gt;&lt;P&gt;           vbrp~werks&lt;/P&gt;&lt;P&gt;           vbrp~bwtar&lt;/P&gt;&lt;P&gt;        INTO CORRESPONDING FIELDS OF TABLE i_vbrp&lt;/P&gt;&lt;P&gt;        FROM vbrp&lt;/P&gt;&lt;P&gt;        FOR ALL ENTRIES IN i_vbrk&lt;/P&gt;&lt;P&gt;        WHERE vbrp~vbeln = i_vbrk-vbeln&lt;/P&gt;&lt;P&gt;        AND   vbrp~fklmg &amp;gt; 0.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  FREE: i_vbrk.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  DELETE i_vbrp WHERE charg IS INITIAL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*----&lt;/P&gt;&lt;HR originaltext="----" /&gt;&lt;P&gt;Start -  Logic to be appended in the user exit&lt;/P&gt;&lt;P&gt;  LOOP AT i_vbrp.&lt;/P&gt;&lt;P&gt;    CLEAR i_matnr.&lt;/P&gt;&lt;P&gt;    i_matnr-matnr = i_vbrp-matnr.&lt;/P&gt;&lt;P&gt;    i_matnr-charg = i_vbrp-charg.                              "Gyan3001&lt;/P&gt;&lt;P&gt;    IF i_vbrp-bwtar = ' ' OR i_vbrp-bwtar = 'INT-SFG'.&lt;/P&gt;&lt;P&gt;      i_matnr-werks = i_vbrp-werks.&lt;/P&gt;&lt;P&gt;    ELSE.&lt;/P&gt;&lt;P&gt;      i_matnr-werks = i_vbrp-bwtar.&lt;/P&gt;&lt;P&gt;    ENDIF.&lt;/P&gt;&lt;P&gt;    COLLECT i_matnr.&lt;/P&gt;&lt;P&gt;  ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  IF i_matnr[] IS NOT INITIAL.&lt;/P&gt;&lt;P&gt;    SELECT  mkpf~mblnr&lt;/P&gt;&lt;P&gt;            mkpf~mjahr&lt;/P&gt;&lt;P&gt;            mkpf~budat&lt;/P&gt;&lt;P&gt;            mseg~bwart&lt;/P&gt;&lt;P&gt;            mseg~matnr&lt;/P&gt;&lt;P&gt;            mseg~charg&lt;/P&gt;&lt;P&gt;            mseg~lgort&lt;/P&gt;&lt;P&gt;            mseg~aufnr&lt;/P&gt;&lt;P&gt;            INTO TABLE i_mseg&lt;/P&gt;&lt;P&gt;            FROM mseg&lt;/P&gt;&lt;P&gt;            INNER JOIN mkpf ON  mkpf&lt;SUB&gt;mblnr = mseg&lt;/SUB&gt;mblnr&lt;/P&gt;&lt;P&gt;                            AND mkpf&lt;SUB&gt;mjahr = mseg&lt;/SUB&gt;mjahr&lt;/P&gt;&lt;P&gt;            FOR ALL entries IN i_matnr&lt;/P&gt;&lt;P&gt;             WHERE mseg~matnr = i_matnr-matnr&lt;/P&gt;&lt;P&gt;             AND   mseg~werks = i_matnr-werks&lt;/P&gt;&lt;P&gt;             AND   mseg~charg = i_matnr-charg                 "Gyan3001&lt;/P&gt;&lt;P&gt;             AND   mseg~bwart = '101'&lt;/P&gt;&lt;P&gt;             AND   mseg~lgort = 'PP01'&lt;/P&gt;&lt;P&gt;             AND   mkpf~budat &amp;lt;= w_edate.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Above program query is taking huge time to fetch data:&lt;/P&gt;&lt;P&gt;Anybody suggest any performance tips.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Jan 2008 08:42:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tips-required-for-following-query/m-p/3322374#M795808</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-30T08:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: Performance tips required for following Query:</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tips-required-for-following-query/m-p/3322375#M795809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;what is slow and what is fast&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please run the SQL Trace at least two time, check the SQL statement summary and show the Top 10 in the list, what takes longest, how long, how many records are read?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;see&lt;/P&gt;&lt;P&gt;/people/siegfried.boes/blog/2007/09/05/the-sql-trace-st05-150-quick-and-easy&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your last SELECT seems to be o.k.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Jan 2008 12:25:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tips-required-for-following-query/m-p/3322375#M795809</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-30T12:25:22Z</dc:date>
    </item>
    <item>
      <title>Re: Performance tips required for following Query:</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tips-required-for-following-query/m-p/3322376#M795810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A couple of things:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first SELECT (against VBRK) doesn't use an index. So this will be slow. But SD billing and FI are related. BKPF is indexed on posting date. You may be able use the FI document to get the information you need here. See [Quickly Retrieving FI document Data from BSEG|/people/rob.burbank/blog/2007/11/12/quickly-retrieving-fi-document-data-from-bseg]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The last SELECT (the JOIN on MKPF and MSEG) is using a portion of a non-unique index and should be pretty good. One thing I would try would be to move the fields you are SELECTing from in I_MATNR to another internal table and DELETE ADJACENT DUPLICATES from this table before using it in the SELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Jan 2008 14:32:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tips-required-for-following-query/m-p/3322376#M795810</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-30T14:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: Performance tips required for following Query:</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tips-required-for-following-query/m-p/3322377#M795811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the performance of the report allways mainly effects on the DATA BASE LOAD &lt;/P&gt;&lt;P&gt;if your program writen logic in better way then its works finely &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;see these points to improve performance &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ways of Performance Tuning&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Selection Criteria &lt;/P&gt;&lt;P&gt;2. Select Statements&lt;/P&gt;&lt;P&gt;&amp;#149; Select Queries&lt;/P&gt;&lt;P&gt;&amp;#149; SQL Interface&lt;/P&gt;&lt;P&gt;&amp;#149; Aggregate Functions&lt;/P&gt;&lt;P&gt;&amp;#149; For all Entries&lt;/P&gt;&lt;P&gt;Select Over more than one internal table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Selection Criteria&lt;/P&gt;&lt;P&gt;1. Restrict the data to the selection criteria itself, rather than filtering it out using the ABAP code using CHECK statement. &lt;/P&gt;&lt;P&gt;2. Select with selection list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM SBOOK INTO SBOOK_WA.&lt;/P&gt;&lt;P&gt;CHECK: SBOOK_WA-CARRID = 'LH' AND&lt;/P&gt;&lt;P&gt;SBOOK_WA-CONNID = '0400'.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK&lt;/P&gt;&lt;P&gt;WHERE SBOOK_WA-CARRID = 'LH' AND&lt;/P&gt;&lt;P&gt;SBOOK_WA-CONNID = '0400'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select Statements Select Queries&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Avoid nested selects&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM EKKO INTO EKKO_WA.&lt;/P&gt;&lt;P&gt;SELECT * FROM EKAN INTO EKAN_WA&lt;/P&gt;&lt;P&gt;WHERE EBELN = EKKO_WA-EBELN.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The above code can be much more optimized by the code written below.&lt;/P&gt;&lt;P&gt;SELECT P&lt;SUB&gt;F1 P&lt;/SUB&gt;F2 F&lt;SUB&gt;F3 F&lt;/SUB&gt;F4 INTO TABLE ITAB&lt;/P&gt;&lt;P&gt;FROM EKKO AS P INNER JOIN EKAN AS F&lt;/P&gt;&lt;P&gt;ON P&lt;SUB&gt;EBELN = F&lt;/SUB&gt;EBELN.&lt;/P&gt;&lt;P&gt;Note: A simple SELECT loop is a single database access whose result is passed to the ABAP program line by line. Nested SELECT loops mean that the number of accesses in the inner loop is multiplied by the number of accesses in the outer loop. One should therefore use nested SELECT loops only if the selection in the outer loop contains very few lines or the outer loop is a SELECT SINGLE statement.&lt;/P&gt;&lt;P&gt;2. Select all the records in a single shot using into table clause of select statement rather than to use Append statements. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM SBOOK INTO SBOOK_WA.&lt;/P&gt;&lt;P&gt;CHECK: SBOOK_WA-CARRID = 'LH' AND&lt;/P&gt;&lt;P&gt;SBOOK_WA-CONNID = '0400'.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list and puts the data in one shot using into table&lt;/P&gt;&lt;P&gt;SELECT CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK&lt;/P&gt;&lt;P&gt;WHERE SBOOK_WA-CARRID = 'LH' AND&lt;/P&gt;&lt;P&gt;SBOOK_WA-CONNID = '0400'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. When a base table has multiple indices, the where clause should be in the order of the index, either a primary or a secondary index. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To choose an index, the optimizer checks the field names specified in the where clause and then uses an index that has the same order of the fields. In certain scenarios, it is advisable to check whether a new index can speed up the performance of a program. This will come handy in programs that access data from the finance tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4. For testing existence, use Select.. Up to 1 rows statement instead of a Select-Endselect-loop with an Exit. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM SBOOK INTO SBOOK_WA&lt;/P&gt;&lt;P&gt;UP TO 1 ROWS&lt;/P&gt;&lt;P&gt;WHERE CARRID = 'LH'.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;The above code is more optimized as compared to the code mentioned below for testing existence of a record.&lt;/P&gt;&lt;P&gt;SELECT * FROM SBOOK INTO SBOOK_WA&lt;/P&gt;&lt;P&gt;WHERE CARRID = 'LH'.&lt;/P&gt;&lt;P&gt;EXIT.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;5. Use Select Single if all primary key fields are supplied in the Where condition .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If all primary key fields are supplied in the Where conditions you can even use Select Single. &lt;/P&gt;&lt;P&gt;Select Single requires one communication with the database system, whereas Select-Endselect needs two. &lt;/P&gt;&lt;P&gt;Select Statements SQL Interface&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Use column updates instead of single-row updates &lt;/P&gt;&lt;P&gt;to update your database tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM SFLIGHT INTO SFLIGHT_WA.&lt;/P&gt;&lt;P&gt;SFLIGHT_WA-SEATSOCC =&lt;/P&gt;&lt;P&gt;SFLIGHT_WA-SEATSOCC - 1.&lt;/P&gt;&lt;P&gt;UPDATE SFLIGHT FROM SFLIGHT_WA.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;The above mentioned code can be more optimized by using the following code&lt;/P&gt;&lt;P&gt;UPDATE SFLIGHT&lt;/P&gt;&lt;P&gt;SET SEATSOCC = SEATSOCC - 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. For all frequently used Select statements, try to use an index.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA&lt;/P&gt;&lt;P&gt;WHERE CARRID = 'LH'&lt;/P&gt;&lt;P&gt;AND CONNID = '0400'.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;The above mentioned code can be more optimized by using the following code&lt;/P&gt;&lt;P&gt;SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA&lt;/P&gt;&lt;P&gt;WHERE MANDT IN ( SELECT MANDT FROM T000 )&lt;/P&gt;&lt;P&gt;AND CARRID = 'LH'&lt;/P&gt;&lt;P&gt;AND CONNID = '0400'.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. Using buffered tables improves the performance considerably.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Bypassing the buffer increases the network considerably&lt;/P&gt;&lt;P&gt;SELECT SINGLE * FROM T100 INTO T100_WA&lt;/P&gt;&lt;P&gt;BYPASSING BUFFER&lt;/P&gt;&lt;P&gt;WHERE SPRSL = 'D'&lt;/P&gt;&lt;P&gt;AND ARBGB = '00'&lt;/P&gt;&lt;P&gt;AND MSGNR = '999'.&lt;/P&gt;&lt;P&gt;The above mentioned code can be more optimized by using the following code&lt;/P&gt;&lt;P&gt;SELECT SINGLE * FROM T100 INTO T100_WA&lt;/P&gt;&lt;P&gt;WHERE SPRSL = 'D'&lt;/P&gt;&lt;P&gt;AND ARBGB = '00'&lt;/P&gt;&lt;P&gt;AND MSGNR = '999'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select Statements Aggregate Functions&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;#149; If you want to find the maximum, minimum, sum and average value or the count of a database column, use a select list with aggregate functions instead of computing the aggregates yourself. &lt;/P&gt;&lt;P&gt;Some of the Aggregate functions allowed in SAP are MAX, MIN, AVG, SUM, COUNT, COUNT( * )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Consider the following extract.&lt;/P&gt;&lt;P&gt;Maxno = 0.&lt;/P&gt;&lt;P&gt;Select * from zflight where airln = &amp;#145;LF&amp;#146; and cntry = &amp;#145;IN&amp;#146;.&lt;/P&gt;&lt;P&gt;Check zflight-fligh &amp;gt; maxno.&lt;/P&gt;&lt;P&gt;Maxno = zflight-fligh.&lt;/P&gt;&lt;P&gt;Endselect.&lt;/P&gt;&lt;P&gt;The above mentioned code can be much more optimized by using the following code.&lt;/P&gt;&lt;P&gt;Select max( fligh ) from zflight into maxno where airln = &amp;#145;LF&amp;#146; and cntry = &amp;#145;IN&amp;#146;. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select Statements For All Entries&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;#149; The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the length of the WHERE clause. &lt;/P&gt;&lt;P&gt;The plus &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;#149; Large amount of data &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;#149; Mixing processing and reading of data &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;#149; Fast internal reprocessing of data &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;#149; Fast &lt;/P&gt;&lt;P&gt;The Minus &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;#149; Difficult to program/understand &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;#149; Memory could be critical (use FREE or PACKAGE size) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Points to be must considered FOR ALL ENTRIES &lt;/P&gt;&lt;P&gt;&amp;#149; Check that data is present in the driver table&lt;/P&gt;&lt;P&gt;&amp;#149; Sorting the driver table &lt;/P&gt;&lt;P&gt;&amp;#149; Removing duplicates from the driver table&lt;/P&gt;&lt;P&gt;Consider the following piece of extract&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Loop at int_cntry.&lt;/P&gt;&lt;P&gt;Select single * from zfligh into int_fligh&lt;/P&gt;&lt;P&gt;where cntry = int_cntry-cntry.&lt;/P&gt;&lt;P&gt;Append int_fligh. &lt;/P&gt;&lt;P&gt;Endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The above mentioned can be more optimized by using the following code.&lt;/P&gt;&lt;P&gt;Sort int_cntry by cntry.&lt;/P&gt;&lt;P&gt;Delete adjacent duplicates from int_cntry.&lt;/P&gt;&lt;P&gt;If NOT int_cntry[] is INITIAL.&lt;/P&gt;&lt;P&gt;Select * from zfligh appending table int_fligh&lt;/P&gt;&lt;P&gt;For all entries in int_cntry &lt;/P&gt;&lt;P&gt;Where cntry = int_cntry-cntry.&lt;/P&gt;&lt;P&gt;Endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select Statements Select Over more than one Internal table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Its better to use a views instead of nested Select statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM DD01L INTO DD01L_WA&lt;/P&gt;&lt;P&gt;WHERE DOMNAME LIKE 'CHAR%'&lt;/P&gt;&lt;P&gt;AND AS4LOCAL = 'A'.&lt;/P&gt;&lt;P&gt;SELECT SINGLE * FROM DD01T INTO DD01T_WA&lt;/P&gt;&lt;P&gt;WHERE DOMNAME = DD01L_WA-DOMNAME&lt;/P&gt;&lt;P&gt;AND AS4LOCAL = 'A'&lt;/P&gt;&lt;P&gt;AND AS4VERS = DD01L_WA-AS4VERS&lt;/P&gt;&lt;P&gt;AND DDLANGUAGE = SY-LANGU.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The above code can be more optimized by extracting all the data from view DD01V_WA &lt;/P&gt;&lt;P&gt;SELECT * FROM DD01V INTO DD01V_WA&lt;/P&gt;&lt;P&gt;WHERE DOMNAME LIKE 'CHAR%'&lt;/P&gt;&lt;P&gt;AND DDLANGUAGE = SY-LANGU.&lt;/P&gt;&lt;P&gt;ENDSELECT&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. To read data from several logically connected tables use a join instead of nested Select statements. Joins are preferred only if all the primary key are available in WHERE clause for the tables that are joined. If the primary keys are not provided in join the Joining of tables itself takes time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM EKKO INTO EKKO_WA.&lt;/P&gt;&lt;P&gt;SELECT * FROM EKAN INTO EKAN_WA&lt;/P&gt;&lt;P&gt;WHERE EBELN = EKKO_WA-EBELN.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;The above code can be much more optimized by the code written below.&lt;/P&gt;&lt;P&gt;SELECT P&lt;SUB&gt;F1 P&lt;/SUB&gt;F2 F&lt;SUB&gt;F3 F&lt;/SUB&gt;F4 INTO TABLE ITAB&lt;/P&gt;&lt;P&gt;FROM EKKO AS P INNER JOIN EKAN AS F&lt;/P&gt;&lt;P&gt;ON P&lt;SUB&gt;EBELN = F&lt;/SUB&gt;EBELN.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. Instead of using nested Select loops it is often better to use subqueries. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM SPFLI&lt;/P&gt;&lt;P&gt;INTO TABLE T_SPFLI&lt;/P&gt;&lt;P&gt;WHERE CITYFROM = 'FRANKFURT'&lt;/P&gt;&lt;P&gt;AND CITYTO = 'NEW YORK'.&lt;/P&gt;&lt;P&gt;SELECT * FROM SFLIGHT AS F&lt;/P&gt;&lt;P&gt;INTO SFLIGHT_WA&lt;/P&gt;&lt;P&gt;FOR ALL ENTRIES IN T_SPFLI&lt;/P&gt;&lt;P&gt;WHERE SEATSOCC &amp;lt; F~SEATSMAX&lt;/P&gt;&lt;P&gt;AND CARRID = T_SPFLI-CARRID&lt;/P&gt;&lt;P&gt;AND CONNID = T_SPFLI-CONNID&lt;/P&gt;&lt;P&gt;AND FLDATE BETWEEN '19990101' AND '19990331'.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;The above mentioned code can be even more optimized by using subqueries instead of for all entries.&lt;/P&gt;&lt;P&gt;SELECT * FROM SFLIGHT AS F INTO SFLIGHT_WA&lt;/P&gt;&lt;P&gt;WHERE SEATSOCC &amp;lt; F~SEATSMAX&lt;/P&gt;&lt;P&gt;AND EXISTS ( SELECT * FROM SPFLI&lt;/P&gt;&lt;P&gt;WHERE CARRID = F~CARRID&lt;/P&gt;&lt;P&gt;AND CONNID = F~CONNID&lt;/P&gt;&lt;P&gt;AND CITYFROM = 'FRANKFURT'&lt;/P&gt;&lt;P&gt;AND CITYTO = 'NEW YORK' )&lt;/P&gt;&lt;P&gt;AND FLDATE BETWEEN '19990101' AND '19990331'.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Table operations should be done using explicit work areas rather than via header lines.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;READ TABLE ITAB INTO WA WITH KEY K = 'X&amp;#145; BINARY SEARCH.&lt;/P&gt;&lt;P&gt;IS MUCH FASTER THAN USING&lt;/P&gt;&lt;P&gt;READ TABLE ITAB INTO WA WITH KEY K = 'X'.&lt;/P&gt;&lt;P&gt;If TAB has n entries, linear search runs in O( n ) time, whereas binary search takes only O( log2( n ) ). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. Always try to use binary search instead of linear search. But don&amp;#146;t forget to sort your internal table before that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;READ TABLE ITAB INTO WA WITH KEY K = 'X'. IS FASTER THAN USING &lt;/P&gt;&lt;P&gt;READ TABLE ITAB INTO WA WITH KEY (NAME) = 'X'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. A dynamic key access is slower than a static one, since the key specification must be evaluated at runtime.&lt;/P&gt;&lt;P&gt;4. A binary search using secondary index takes considerably less time.&lt;/P&gt;&lt;P&gt;5. LOOP ... WHERE is faster than LOOP/CHECK because LOOP ... WHERE evaluates the specified condition internally. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT ITAB INTO WA WHERE K = 'X'.&lt;/P&gt;&lt;P&gt;" ...&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;The above code is much faster than using &lt;/P&gt;&lt;P&gt;LOOP AT ITAB INTO WA.&lt;/P&gt;&lt;P&gt;CHECK WA-K = 'X'.&lt;/P&gt;&lt;P&gt;" ...&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;6. Modifying selected components using &amp;#147; MODIFY itab &amp;#133;TRANSPORTING f1 f2.. &amp;#147; accelerates the task of updating a line of an internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WA-DATE = SY-DATUM.&lt;/P&gt;&lt;P&gt;MODIFY ITAB FROM WA INDEX 1 TRANSPORTING DATE.&lt;/P&gt;&lt;P&gt;The above code is more optimized as compared to &lt;/P&gt;&lt;P&gt;WA-DATE = SY-DATUM.&lt;/P&gt;&lt;P&gt;MODIFY ITAB FROM WA INDEX 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;7. Accessing the table entries directly in a "LOOP ... ASSIGNING ..." accelerates the task of updating a set of lines of an internal table considerably&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Modifying selected components only makes the program faster as compared to Modifying all lines completely.&lt;/P&gt;&lt;P&gt;e.g,&lt;/P&gt;&lt;P&gt;LOOP AT ITAB ASSIGNING &amp;lt;WA&amp;gt;.&lt;/P&gt;&lt;P&gt;I = SY-TABIX MOD 2.&lt;/P&gt;&lt;P&gt;IF I = 0.&lt;/P&gt;&lt;P&gt;&amp;lt;WA&amp;gt;-FLAG = 'X'.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;The above code works faster as compared to&lt;/P&gt;&lt;P&gt;LOOP AT ITAB INTO WA.&lt;/P&gt;&lt;P&gt;I = SY-TABIX MOD 2.&lt;/P&gt;&lt;P&gt;IF I = 0.&lt;/P&gt;&lt;P&gt;WA-FLAG = 'X'.&lt;/P&gt;&lt;P&gt;MODIFY ITAB FROM WA.&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;8. If collect semantics is required, it is always better to use to COLLECT rather than READ BINARY and then ADD.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT ITAB1 INTO WA1.&lt;/P&gt;&lt;P&gt;READ TABLE ITAB2 INTO WA2 WITH KEY K = WA1-K BINARY SEARCH.&lt;/P&gt;&lt;P&gt;IF SY-SUBRC = 0.&lt;/P&gt;&lt;P&gt;ADD: WA1-VAL1 TO WA2-VAL1,&lt;/P&gt;&lt;P&gt;WA1-VAL2 TO WA2-VAL2.&lt;/P&gt;&lt;P&gt;MODIFY ITAB2 FROM WA2 INDEX SY-TABIX TRANSPORTING VAL1 VAL2.&lt;/P&gt;&lt;P&gt;ELSE.&lt;/P&gt;&lt;P&gt;INSERT WA1 INTO ITAB2 INDEX SY-TABIX.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;The above code uses BINARY SEARCH for collect semantics. READ BINARY runs in O( log2(n) ) time. The above piece of code can be more optimized by&lt;/P&gt;&lt;P&gt;LOOP AT ITAB1 INTO WA.&lt;/P&gt;&lt;P&gt;COLLECT WA INTO ITAB2.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;SORT ITAB2 BY K.&lt;/P&gt;&lt;P&gt;COLLECT, however, uses a hash algorithm and is therefore independent &lt;/P&gt;&lt;P&gt;of the number of entries (i.e. O(1)) .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;9. "APPEND LINES OF itab1 TO itab2" accelerates the task of appending a table to another table considerably as compared to &amp;#147; LOOP-APPEND-ENDLOOP.&amp;#148; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;APPEND LINES OF ITAB1 TO ITAB2.&lt;/P&gt;&lt;P&gt;This is more optimized as compared to&lt;/P&gt;&lt;P&gt;LOOP AT ITAB1 INTO WA.&lt;/P&gt;&lt;P&gt;APPEND WA TO ITAB2.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;10. &amp;#147;DELETE ADJACENT DUPLICATES&amp;#147; accelerates the task of deleting duplicate entries considerably as compared to &amp;#147; READ-LOOP-DELETE-ENDLOOP&amp;#148;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DELETE ADJACENT DUPLICATES FROM ITAB COMPARING K.&lt;/P&gt;&lt;P&gt;This is much more optimized as compared to&lt;/P&gt;&lt;P&gt;READ TABLE ITAB INDEX 1 INTO PREV_LINE.&lt;/P&gt;&lt;P&gt;LOOP AT ITAB FROM 2 INTO WA.&lt;/P&gt;&lt;P&gt;IF WA = PREV_LINE.&lt;/P&gt;&lt;P&gt;DELETE ITAB.&lt;/P&gt;&lt;P&gt;ELSE.&lt;/P&gt;&lt;P&gt;PREV_LINE = WA.&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;11. "DELETE itab FROM ... TO ..." accelerates the task of deleting a sequence of lines considerably as compared to &amp;#147; DO -DELETE-ENDDO&amp;#148;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DELETE ITAB FROM 450 TO 550.&lt;/P&gt;&lt;P&gt;This is much more optimized as compared to&lt;/P&gt;&lt;P&gt;DO 101 TIMES.&lt;/P&gt;&lt;P&gt;DELETE ITAB INDEX 450.&lt;/P&gt;&lt;P&gt;ENDDO.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;12. Copying internal tables by using &amp;#147;ITAB2[ ] = ITAB1[ ]&amp;#148; as compared to &amp;#147;LOOP-APPEND-ENDLOOP&amp;#148;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ITAB2] = ITAB1[.&lt;/P&gt;&lt;P&gt;This is much more optimized as compared to&lt;/P&gt;&lt;P&gt;REFRESH ITAB2.&lt;/P&gt;&lt;P&gt;LOOP AT ITAB1 INTO WA.&lt;/P&gt;&lt;P&gt;APPEND WA TO ITAB2.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;13. Specify the sort key as restrictively as possible to run the program faster. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;#147;SORT ITAB BY K.&amp;#148; makes the program runs faster as compared to &amp;#147;SORT ITAB.&amp;#148;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Internal Tables contd&amp;#133;&lt;/P&gt;&lt;P&gt;Hashed and Sorted tables&lt;/P&gt;&lt;P&gt;1. For single read access hashed tables are more optimized as compared to sorted tables.&lt;/P&gt;&lt;P&gt;2. For partial sequential access sorted tables are more optimized as compared to hashed tables&lt;/P&gt;&lt;P&gt;Hashed And Sorted Tables&lt;/P&gt;&lt;P&gt;Point # 1&lt;/P&gt;&lt;P&gt;Consider the following example where HTAB is a hashed table and STAB is a sorted table&lt;/P&gt;&lt;P&gt;DO 250 TIMES.&lt;/P&gt;&lt;P&gt;N = 4 * SY-INDEX.&lt;/P&gt;&lt;P&gt;READ TABLE HTAB INTO WA WITH TABLE KEY K = N.&lt;/P&gt;&lt;P&gt;IF SY-SUBRC = 0.&lt;/P&gt;&lt;P&gt;" ...&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;ENDDO.&lt;/P&gt;&lt;P&gt;This runs faster for single read access as compared to the following same code for sorted table&lt;/P&gt;&lt;P&gt;DO 250 TIMES.&lt;/P&gt;&lt;P&gt;N = 4 * SY-INDEX.&lt;/P&gt;&lt;P&gt;READ TABLE STAB INTO WA WITH TABLE KEY K = N.&lt;/P&gt;&lt;P&gt;IF SY-SUBRC = 0.&lt;/P&gt;&lt;P&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;Point # 2&lt;/P&gt;&lt;P&gt;Similarly for Partial Sequential access the STAB runs faster as compared to HTAB&lt;/P&gt;&lt;P&gt;LOOP AT STAB INTO WA WHERE K = SUBKEY.&lt;/P&gt;&lt;P&gt;" ...&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;This runs faster as compared to&lt;/P&gt;&lt;P&gt;LOOP AT HTAB INTO WA WHERE K = SUBKEY.&lt;/P&gt;&lt;P&gt;" ...&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;hi sir u can follow all these in any kind of queries.it may be helpful to u.&lt;/P&gt;&lt;P&gt;award points if helpful&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;sravani&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Feb 2008 04:39:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tips-required-for-following-query/m-p/3322377#M795811</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-04T04:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: Performance tips required for following Query:</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tips-required-for-following-query/m-p/3322378#M795812</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi anee,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) before using FOR ALL ENTRIES make sure the internal table which you are using is filled otherwise it will fetch all the data from the data base table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) instead of writing into corresponding fields define a structure type and than use into table table_name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3) you have not used any key field while using SELECT on VBRK so it will take time. if possible than add key fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;reward if helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2008 12:45:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tips-required-for-following-query/m-p/3322378#M795812</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-16T12:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: Performance tips required for following Query:</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tips-required-for-following-query/m-p/3322379#M795813</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Anne,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Besides, you can also avoid using&lt;/P&gt;&lt;P&gt;DELETE i_vbrp WHERE charg IS INITIAL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead, use some other intermediate table, say i_vbrp_temp and select all records in i_vbrp_temp and transfer it to i_vbrp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort i_vbrp_temp by charg descending&lt;/P&gt;&lt;UL&gt;&lt;UL&gt;&lt;LI level="2" type="ul"&gt;&lt;P&gt;all non initial will float above&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at i_vbrp_temp assigning &amp;lt;f_vbrp&amp;gt;.&lt;/P&gt;&lt;P&gt;if &amp;lt;f_vbrp&amp;gt;-charg is initial.&lt;/P&gt;&lt;P&gt;exit.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;i_vbrp = &amp;lt;f_vbrp&amp;gt;.&lt;/P&gt;&lt;P&gt;append i_vbrp&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;free i_vbrp_temp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mohaiyuddin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Apr 2008 11:23:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tips-required-for-following-query/m-p/3322379#M795813</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-17T11:23:20Z</dc:date>
    </item>
  </channel>
</rss>

