ABAP 優化文件【來自網路】加個人體會 - 2

leniz發表於2008-10-14

Modifying a group of lines of an internal table:如果內表中需要對多行進行資料修改,請採用整體修改的方式

Use the variations of the modify command to speed up this kind of processing.

 Not recommended

            Loop at int_fligh.

             If int_fligh-flag is initial.

                        Int_fligh-flag = X.

             Endif.

             Modify int_fligh.

            Endloop.

 

Recommended

            Int_fligh-flag = X.

            Modify int_fligh transporting flag where flag is initial.

個人體會:注意這個transporting

Use of binary search option

When a programmer uses the read command, the table is sequentially searched. This slows down the processing. Instead of this, use the binary search addition. The binary search algorithm helps faster search of a value in an internal table. It is advisable to sort the internal table before doing a binary search. Binary search repeatedly divides the search interval in half. If the value to be searched is less than the item in the middle of the interval, the search is narrowed to the lower half, otherwise the search is narrowed to the upper half. 

Not Recommended

            Read table int_fligh with key  airln = LF.

 

Recommended

            Read table int_fligh with key  airln = LF binary search.

個人體會:記得先排序

Appending 2 internal tables:連結兩個內表

Instead of using the normal loop-endloop approach for this kind of programming, use the variation of the append command. Care should be taken that the definition of both the internal tables should be identical. 

Not Recommended

            Loop at int_fligh1.

             Append int_fligh1 to int_fligh2.

            Endloop.

 

Recommended

            Append lines of int_fligh1 to int_fligh2.

個人體會:比較少用,記住使用者即可

 

Using table buffering

Use of buffered tables is recommended to improve the performance considerably. The buffer is bypassed while using the following statements

  1. Select distinct
  2. Select … for update
  3. Order by, group by, having clause
  4. Joins

Use the Bypass buffer addition to the select clause in order to explicitly bypass the buffer while selecting the data.

Use of FOR ALL Entrieswhere條件採用內表的方式才說明

Outer join can be created using this addition to the where clause in a select statement. It speeds up the performance tremendously, but the cons of using this variation are listed below

  1. Duplicates are automatically removed from the resulting data set. Hence care should be taken that the unique key of the detail line items should be given in the select statement.
  2. If the table on which the For All Entries IN clause is based is empty, all rows are selected into the destination table. Hence it is advisable to check before-hand that the first table is not empty.
  3. If the table on which the For All Entries IN clause is based is very large, the performance will go down instead of improving. Hence attempt should be made to keep the table size to a moderate level.

Not Recommended

            Loop at int_cntry.

             Select single * from zfligh into int_fligh

 where cntry = int_cntry-cntry.

 Append int_fligh.

            Endloop.

 

Recommended

            Select * from zfligh appending table int_fligh

            For all entries in int_cntry

            Where cntry = int_cntry-cntry.

個人體會:要注意內表為空的情況

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/554557/viewspace-470536/,如需轉載,請註明出處,否則將追究法律責任。

相關文章