<?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 tuning. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning/m-p/3096650#M734665</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try using this code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: BEGIN OF ty_ekpo,
         ebeln TYPE ekpo-ebeln,
         ebelp TYPE ekpo-ebelp,
         matnr TYPE ekpo-matnr,
         meins TYPE ekpo-meins,
         elikz TYPE ekpo-elikz,
       END OF ty_ekpo,

       BEGIN OF ty_ekko,
         ebeln TYPE ekko-ebeln,
         lifnr TYPE ekko-lifnr,
       END OF ty_ekko,

       BEGIN OF ty_ekes,
         ebeln TYPE ekes-ebeln,
         ebelp TYPE ekes-ebelp,
         etens TYPE ekes-etens,
         menge TYPE ekes-menge,
         dabmg TYPE ekes-dabmg,
       END OF ty_ekes,

       BEGIN OF ty_ekpo_final,
         ebeln TYPE ekpo-ebeln,
         ebelp TYPE ekpo-ebelp,
         etens TYPE ekes-etens,
         matnr TYPE ekpo-matnr,
         meins TYPE ekpo-meins,
         lifnr TYPE ekko-lifnr,
         elikz TYPE ekpo-elikz,
         menge TYPE ekes-menge,
         dabmg TYPE ekes-dabmg,
       END OF ty_ekpo_final.


DATA: w_ekpo           TYPE          ty_ekpo             ,
      w_ekes           TYPE          ty_ekes             ,
      w_ekko           TYPE          ty_ekko             ,
      w_edit_cle       LIKE          itb_edit_cle        ,
      w_ekpo_final     TYPE          ty_ekpo_final       ,

      itb_edit_cle_tmp LIKE TABLE OF itb_edit_cle        ,
      t_ekpo           TYPE SORTED TABLE OF ty_ekpo
        WITH NON-UNIQUE KEY ebeln matnr                  ,
      t_ekpo_tmp       TYPE        TABLE OF ty_ekpo      ,
      t_ekes           TYPE SORTED TABLE OF ty_ekes
        WITH NON-UNIQUE KEY ebeln ebelp                  ,
      t_ekko           TYPE SORTED TABLE OF ty_ekko
        WITH NON-UNIQUE KEY lifnr                        ,
      itb_ekpo         TYPE        TABLE OF ty_ekpo_final.


REFRESH itb_ekpo.

IF NOT itb_edit_cle[] IS INITIAL.

  itb_edit_cle_tmp[] = itb_edit_cle[].
  SORT itb_edit_cle_tmp BY matnr.
  DELETE ADJACENT DUPLICATES FROM itb_edit_cle_tmp COMPARING matnr.

  SELECT ebeln
         ebelp
         matnr
         meins
         elikz
    FROM ekpo
    INTO TABLE t_ekpo
    FOR ALL ENTRIES IN itb_edit_cle_tmp
    WHERE matnr EQ itb_edit_cle_tmp-matnr
    AND   werks EQ p_werks
    AND   bstyp EQ 'F'
    AND   loekz EQ space.

  IF sy-subrc EQ 0.

    t_ekpo_tmp[] = t_ekpo[].

    SORT t_ekpo_tmp BY ebeln ebelp.

    SELECT ebeln
           ebelp
           etens
           menge
           dabmg
      FROM ekes
      INTO TABLE t_ekes
      FOR ALL ENTRIES IN t_ekpo_tmp
      WHERE ebeln EQ t_ekpo_tmp-ebeln
      AND   ebelp EQ t_ekpo_tmp-ebelp
      AND   ebtyp EQ 'AL'.


    DELETE ADJACENT DUPLICATES FROM t_ekpo_tmp COMPARING ebeln.

    SELECT ebeln
           lifnr
      FROM ekko
      INTO TABLE t_ekko
      FOR ALL ENTRIES IN t_ekpo_tmp
      WHERE ebeln EQ t_ekpo_tmp-ebeln.

  ENDIF.


  LOOP AT itb_edit_cle INTO w_edit_cle.

    READ TABLE t_ekko INTO w_ekko WITH KEY lifnr = w_edit_cle-lifnr
                                           TRANSPORTING
                                             ebeln.

    CHECK sy-subrc EQ 0.

    LOOP AT t_ekpo INTO w_ekpo WHERE ebeln EQ w_ekko-ebeln
                               AND   matnr EQ w_edit_cle-matnr.

      LOOP AT t_ekes INTO w_ekes WHERE ebeln EQ w_ekpo-ebeln
                                 AND   ebelp EQ w_ekpo-ebelp.


        IF ( ( w_ekpo-elikz EQ space
        OR     w_ekes-dabmg LE 0
        OR     w_ekes-menge LE 0 )
        AND    w_ekes-menge GT 0
        AND    w_ekes-dabmg LT w_ekes-menge ).

          w_ekpo_final-ebeln = w_ekpo-ebeln          .
          w_ekpo_final-ebelp = w_ekpo-ebelp          .
          w_ekpo_final-etens = w_ekes-etens          .
          w_ekpo_final-matnr = w_ekpo-matnr          .
          w_ekpo_final-meins = w_ekpo-meins          .
          w_ekpo_final-lifnr = w_edit_cle-lifnr      .
          w_ekpo_final-elikz = w_ekpo-elikz          .
          w_ekpo_final-menge = w_ekes-menge          .
          w_ekpo_final-dabmg = w_ekes-dabmg          .
          APPEND w_ekpo_final TO itb_ekpo.
          CLEAR  w_ekpo_final.

        ENDIF.

      ENDLOOP.

    ENDLOOP.

  ENDLOOP.

ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 21 Nov 2007 18:04:52 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-11-21T18:04:52Z</dc:date>
    <item>
      <title>performance tuning.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning/m-p/3096644#M734659</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi, m an abap fresher. i m working on a performance tuning.can u help me in reducing performance time of this select query.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT ekpo&lt;SUB&gt;ebeln ekpo&lt;/SUB&gt;ebelp ekes&lt;SUB&gt;etens ekpo&lt;/SUB&gt;matnr ekpo~meins&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;           ekko&lt;SUB&gt;lifnr ekpo&lt;/SUB&gt;elikz ekes&lt;SUB&gt;menge ekes&lt;/SUB&gt;dabmg&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;           INTO TABLE itb_ekpo&lt;/P&gt;&lt;P&gt;           FROM ekko INNER JOIN ekpo  ON ekko&lt;SUB&gt;ebeln EQ ekpo&lt;/SUB&gt;ebeln&lt;/P&gt;&lt;P&gt;                     INNER JOIN ekes           ON ekpo&lt;SUB&gt;ebeln EQ ekes&lt;/SUB&gt;ebeln&lt;/P&gt;&lt;P&gt;                                                        AND ekpo&lt;SUB&gt;ebelp EQ ekes&lt;/SUB&gt;ebelp&lt;/P&gt;&lt;P&gt;           FOR ALL entries IN itb_edit_cle&lt;/P&gt;&lt;P&gt;           WHERE ekko~lifnr EQ itb_edit_cle-lifnr&lt;/P&gt;&lt;P&gt;           AND   ekpo~matnr EQ itb_edit_cle-matnr&lt;/P&gt;&lt;P&gt;           AND   ekpo~werks EQ p_werks                    &lt;/P&gt;&lt;P&gt;           AND   ekpo~bstyp EQ 'F'  &lt;/P&gt;&lt;P&gt;           AND   ekpo~loekz EQ ' '&lt;/P&gt;&lt;P&gt;           AND ( ( ekpo~elikz EQ ' '&lt;/P&gt;&lt;P&gt;               OR  ekes~dabmg LE 0&lt;/P&gt;&lt;P&gt;               OR  ekes~menge LE 0 )&lt;/P&gt;&lt;P&gt;               AND ekes~menge GT 0&lt;/P&gt;&lt;P&gt;               AND ekes&lt;SUB&gt;dabmg LT ekes&lt;/SUB&gt;menge )&lt;/P&gt;&lt;P&gt;           AND   ekes~ebtyp EQ 'AL'. &lt;/P&gt;&lt;P&gt;    IF sy-dbcnt GT 0.&lt;/P&gt;&lt;P&gt;      SORT itb_ekpo BY matnr lifnr.&lt;/P&gt;&lt;P&gt;    ENDIF.&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;&lt;/P&gt;&lt;P&gt;itb_edit_cle is an internal table.should i replace 2 inner joins with a select for all entries. and if so how?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Nov 2007 11:46:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning/m-p/3096644#M734659</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-11-21T11:46:31Z</dc:date>
    </item>
    <item>
      <title>Re: performance tuning.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning/m-p/3096645#M734660</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;USE FOR ALL ENTRIES INSTEAD OF JOINS &lt;/P&gt;&lt;P&gt;IT WILL  IMPROVE THE PERFORMANCE &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF YOU USE JOINS THEN THE DATA BASE CONNECTION WITH  THAT TABLES EXIST UP TO THE PROGRAM EXECUTION SO RESULT IN LOAD ON DATABASE &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I AM SENDING YOU SOME POINTS BELOW USE THAT POINTS FOR FETURE REFERENCE &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ways of Performance Tuning&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;Points # 1/2&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;&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;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;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;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;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;Point # 1&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;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;&lt;/P&gt;&lt;P&gt;Point # 2&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;&lt;/P&gt;&lt;P&gt;Point # 3&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;Point # 4&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;Point # 5&lt;/P&gt;&lt;P&gt;If all primary key fields are supplied in the Where condition 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;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select Statements           contd..  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;2.	For all frequently used Select statements, try to use an index.&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;&lt;/P&gt;&lt;P&gt;Point # 1&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;Point # 2&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;Point # 3&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;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select Statements       contd&amp;#133;           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    contd&amp;#133;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;&amp;#149;	Large amount of data &lt;/P&gt;&lt;P&gt;&amp;#149;	Mixing processing and reading of data &lt;/P&gt;&lt;P&gt;&amp;#149;	Fast internal reprocessing of data &lt;/P&gt;&lt;P&gt;&amp;#149;	Fast &lt;/P&gt;&lt;P&gt;	The Minus &lt;/P&gt;&lt;P&gt;&amp;#149;	Difficult to program/understand &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;&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;&lt;/P&gt;&lt;P&gt;Consider the following piece of extract&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    contd&amp;#133;  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;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;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;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Point # 1&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;Point # 2&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;Point # 3&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;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;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;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;Point # 2&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;Point # 3&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;Point # 5&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;Point # 6&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;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;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;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;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;&lt;/P&gt;&lt;P&gt;Point # 7&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;Point # 8&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;Point # 9&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;Point # 10&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;Point # 11&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;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;Point # 12&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;Point # 13&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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Nov 2007 11:57:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning/m-p/3096645#M734660</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-11-21T11:57:50Z</dc:date>
    </item>
    <item>
      <title>Re: performance tuning.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning/m-p/3096646#M734661</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;do like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;IF itb_edit_cle[] IS NOT INITIAL.
  SELECT lifnr FROM ekko INTO TABLE git_ekko 
   FOR ALL ENTRIES IN itb_edit_cle
    WHERE lifnr = itb_edit_cle-lifnr.
  IF sy-subrc = 0.
   SELECT ebeln ebelp matnr meins elikz FROM ekpo 
    INTO TABLE git_ekpo 
     FOR ALL ENTRIES IN itb_edit_cle
      WHERE matnr = itb_edit_cle-matnr.
        and ekpo~werks eq p_werks
        and ekpo~bstyp eq 'F'
        and ekpo~loekz eq ' '
        and ekpo~elikz eq ' '.
   IF sy-subrc = 0.
     SELECT etens menge dabmg FROM ekes INTO TABLE git_ekes
       FOR ALL ENTRIES IN git_ekpo
          WHERE ebeln = git_ekpo-ebeln
            AND ebelp = git_ekpo-ebelp
             OR dabmg LE 0
            AND ebtyp EQ 'AL'.
    ENDIF.
  ENDIF.
ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort all internal tables by there key fields&lt;/P&gt;&lt;P&gt;loop through first internal table and use read statements to move to final internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward Points if this helps,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Satish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Nov 2007 12:24:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning/m-p/3096646#M734661</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-11-21T12:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: performance tuning.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning/m-p/3096647#M734662</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can anybody explain me, how an FOR ALL ENTRIES should improve a join.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A join is a nested loop on the database, and FOR ALL ENTRIES is a nested loop partly in ABAP and in the database.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the join is optimized, then it must be better than the FOR ALL ENTRIES. Some join do not automatically work correctly, but with suitable indexes and maybe database hints it should be possible to improve them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try the join and the FOR ALL ENTRIES and the version below, measure the runtimes (GET RUNTIME FIELD) and execute them 10 times in a loop. Which one is better?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Beware that this condition is a bit hard to handle&lt;/P&gt;&lt;P&gt;AND ( ( ekpo~elikz EQ ' '&lt;/P&gt;&lt;P&gt;OR ekes~dabmg LE 0&lt;/P&gt;&lt;P&gt;OR ekes~menge LE 0 )&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, 21 Nov 2007 12:38:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning/m-p/3096647#M734662</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-11-21T12:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: performance tuning.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning/m-p/3096648#M734663</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Siegfried Boes: You have said  very genuine points.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For all entries is never never going to give you the results in fast way. I am also suffering with this and I have noticed that for all entries will be ok if that particular &lt;/P&gt;&lt;P&gt;internal table has very less data other wise this will take a good amout of time.&lt;/P&gt;&lt;P&gt;Join is not at all a bad deal.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Nov 2007 12:59:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning/m-p/3096648#M734663</guid>
      <dc:creator>former_member190178</dc:creator>
      <dc:date>2007-11-21T12:59:34Z</dc:date>
    </item>
    <item>
      <title>Re: performance tuning.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning/m-p/3096649#M734664</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, the SELECT looks pretty good. You have at least two secondary index fields in the WHERE (lifnr and matrnr), so you'd think it would be ok. I wonder if the database is getting confused and not picking the correct index. Can you please run an SQL performance trace (ST05) on this statement and then look at the EXPLAIN to see if it is using an index?&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, 21 Nov 2007 14:38:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning/m-p/3096649#M734664</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-11-21T14:38:17Z</dc:date>
    </item>
    <item>
      <title>Re: performance tuning.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning/m-p/3096650#M734665</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try using this code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: BEGIN OF ty_ekpo,
         ebeln TYPE ekpo-ebeln,
         ebelp TYPE ekpo-ebelp,
         matnr TYPE ekpo-matnr,
         meins TYPE ekpo-meins,
         elikz TYPE ekpo-elikz,
       END OF ty_ekpo,

       BEGIN OF ty_ekko,
         ebeln TYPE ekko-ebeln,
         lifnr TYPE ekko-lifnr,
       END OF ty_ekko,

       BEGIN OF ty_ekes,
         ebeln TYPE ekes-ebeln,
         ebelp TYPE ekes-ebelp,
         etens TYPE ekes-etens,
         menge TYPE ekes-menge,
         dabmg TYPE ekes-dabmg,
       END OF ty_ekes,

       BEGIN OF ty_ekpo_final,
         ebeln TYPE ekpo-ebeln,
         ebelp TYPE ekpo-ebelp,
         etens TYPE ekes-etens,
         matnr TYPE ekpo-matnr,
         meins TYPE ekpo-meins,
         lifnr TYPE ekko-lifnr,
         elikz TYPE ekpo-elikz,
         menge TYPE ekes-menge,
         dabmg TYPE ekes-dabmg,
       END OF ty_ekpo_final.


DATA: w_ekpo           TYPE          ty_ekpo             ,
      w_ekes           TYPE          ty_ekes             ,
      w_ekko           TYPE          ty_ekko             ,
      w_edit_cle       LIKE          itb_edit_cle        ,
      w_ekpo_final     TYPE          ty_ekpo_final       ,

      itb_edit_cle_tmp LIKE TABLE OF itb_edit_cle        ,
      t_ekpo           TYPE SORTED TABLE OF ty_ekpo
        WITH NON-UNIQUE KEY ebeln matnr                  ,
      t_ekpo_tmp       TYPE        TABLE OF ty_ekpo      ,
      t_ekes           TYPE SORTED TABLE OF ty_ekes
        WITH NON-UNIQUE KEY ebeln ebelp                  ,
      t_ekko           TYPE SORTED TABLE OF ty_ekko
        WITH NON-UNIQUE KEY lifnr                        ,
      itb_ekpo         TYPE        TABLE OF ty_ekpo_final.


REFRESH itb_ekpo.

IF NOT itb_edit_cle[] IS INITIAL.

  itb_edit_cle_tmp[] = itb_edit_cle[].
  SORT itb_edit_cle_tmp BY matnr.
  DELETE ADJACENT DUPLICATES FROM itb_edit_cle_tmp COMPARING matnr.

  SELECT ebeln
         ebelp
         matnr
         meins
         elikz
    FROM ekpo
    INTO TABLE t_ekpo
    FOR ALL ENTRIES IN itb_edit_cle_tmp
    WHERE matnr EQ itb_edit_cle_tmp-matnr
    AND   werks EQ p_werks
    AND   bstyp EQ 'F'
    AND   loekz EQ space.

  IF sy-subrc EQ 0.

    t_ekpo_tmp[] = t_ekpo[].

    SORT t_ekpo_tmp BY ebeln ebelp.

    SELECT ebeln
           ebelp
           etens
           menge
           dabmg
      FROM ekes
      INTO TABLE t_ekes
      FOR ALL ENTRIES IN t_ekpo_tmp
      WHERE ebeln EQ t_ekpo_tmp-ebeln
      AND   ebelp EQ t_ekpo_tmp-ebelp
      AND   ebtyp EQ 'AL'.


    DELETE ADJACENT DUPLICATES FROM t_ekpo_tmp COMPARING ebeln.

    SELECT ebeln
           lifnr
      FROM ekko
      INTO TABLE t_ekko
      FOR ALL ENTRIES IN t_ekpo_tmp
      WHERE ebeln EQ t_ekpo_tmp-ebeln.

  ENDIF.


  LOOP AT itb_edit_cle INTO w_edit_cle.

    READ TABLE t_ekko INTO w_ekko WITH KEY lifnr = w_edit_cle-lifnr
                                           TRANSPORTING
                                             ebeln.

    CHECK sy-subrc EQ 0.

    LOOP AT t_ekpo INTO w_ekpo WHERE ebeln EQ w_ekko-ebeln
                               AND   matnr EQ w_edit_cle-matnr.

      LOOP AT t_ekes INTO w_ekes WHERE ebeln EQ w_ekpo-ebeln
                                 AND   ebelp EQ w_ekpo-ebelp.


        IF ( ( w_ekpo-elikz EQ space
        OR     w_ekes-dabmg LE 0
        OR     w_ekes-menge LE 0 )
        AND    w_ekes-menge GT 0
        AND    w_ekes-dabmg LT w_ekes-menge ).

          w_ekpo_final-ebeln = w_ekpo-ebeln          .
          w_ekpo_final-ebelp = w_ekpo-ebelp          .
          w_ekpo_final-etens = w_ekes-etens          .
          w_ekpo_final-matnr = w_ekpo-matnr          .
          w_ekpo_final-meins = w_ekpo-meins          .
          w_ekpo_final-lifnr = w_edit_cle-lifnr      .
          w_ekpo_final-elikz = w_ekpo-elikz          .
          w_ekpo_final-menge = w_ekes-menge          .
          w_ekpo_final-dabmg = w_ekes-dabmg          .
          APPEND w_ekpo_final TO itb_ekpo.
          CLEAR  w_ekpo_final.

        ENDIF.

      ENDLOOP.

    ENDLOOP.

  ENDLOOP.

ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Nov 2007 18:04:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning/m-p/3096650#M734665</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-11-21T18:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: performance tuning.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning/m-p/3096651#M734666</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Siegfried Boes,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We write SQL queries using ABAP statements. The database interpreter converts this ABAP SQL to your database specific SQL. The database optimizer makes sure that the translated query is optimum. When you use JOINS, you rely on your database optimizer to do a good job. If it does, your query should run faster than the FOR ALL ENTRIES option. However this is not always the case. When the database optimizer does not do a good job the query will take a long time. The performance of the database optimizer is difficult to predict because it would perform differently for different queries.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you use FOR ALL ENTRIES you are making sure that the individual SELECT statements are written correctly. The probability that the database optimizer would mess up individual SELECT statements is far less. Even though the FOR ALL ENTRIES option involves looping, you retain more control over your queries as opposed to surrendering it to the database optimizer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I agree with you that if the database optimizer does a good job a JOIN would perform better but if you want to establish some sort of coding standards for your team, you are better off suggesting FOR ALL ENTRIES as compared to JOINS as in the case of FOR ALL ENTRIES the performance is reasonably good and the only reason there would be a performance issue is if the person writing the code has done a bad job.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Nov 2007 18:23:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning/m-p/3096651#M734666</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-11-21T18:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: performance tuning.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning/m-p/3096652#M734667</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Maddu Soni,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you share with us your code where you have problems with FOR ALL ENTRIES we could help you with it.  Just make it a separate post so that you will have points to offer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Nov 2007 18:30:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning/m-p/3096652#M734667</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-11-21T18:30:43Z</dc:date>
    </item>
  </channel>
</rss>

