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

leniz發表於2008-10-14

SAP ABAP Performance Tuning
Tips & Tricks
Performance Analysis Tools

Use of selection criteria:查詢資料加入限定條件,不要取不必要的東西--&gt能少則少

Instead of selecting all the data and doing the processing during the selection, it is advisable to restrict the data to the selection criteria itself, rather than filtering it out using the ABAP code. 

Not recommended

            Select * from zflight.

             Check : zflight-airln = ‘LF’ and zflight-fligh = ‘BW222’.

            Endselect.

Recommended

            Select * from zflight where airln = ‘LF’ and fligh = ‘222’.

            Endselect.

One more point to be noted here is of the select *. Often this is a lazy coding practice. When a programmer gives select * even if one or two fields are to be selected, this can significantly slow the program and put unnecessary load on the entire system. When the application server sends this request to the database server, and the database server has to pass on the entire structure for each row back to the application server. This consumes both CPU and networking resources, especially for large structures.

Thus it is advisable to select only those fields that are needed, so that the database server passes only a small amount of data back.

Also it is advisable to avoid selecting the data fields into local variables as this also puts unnecessary load on the server. Instead attempt must be made to select the fields into an internal table.

 

個人體會:如果你在抓取資料後,還有範圍的選擇,那麼大可將此範圍的限定,加入到SQL語句中,這樣可以降低資料量在網路中的流通,更快地傳輸吧

Use of aggregate functions:取一批資料過來,如果本身有一些集合動作可以放到資料庫中做:要用集運算,則用集運算

Use the already provided aggregate functions, instead of finding out the minimum/maximum values using ABAP code.

Not recommended

            Maxnu = 0.

            Select * from zflight where airln = ‘LF’ and cntry = ‘IN’.

             Check zflight-fligh > maxnu.

             Maxnu = zflight-fligh.

            Endselect.

 

Recommended

            Select max( fligh ) from zflight into maxnu where airln = ‘LF’ and cntry = ‘IN’.

The other aggregate functions that can be used are min (to find the minimum value), avg (to find the average of a Data interval), sum (to add up a data interval) and count (counting the lines in a data selection).

 

個人體會:比如要做匯總,其實在資料庫做更快,而資料量也大大的降低,所以這個方法是最好用也是最容易用的

 

Use of Views instead of base tables:如果有幾個表關聯,那麼就乾脆建各View吧

Many times ABAP programmers deal with base tables and nested selects. Instead it is always advisable to see whether there is any view provided by SAP on those base tables, so that the data can be filtered out directly, rather than specially coding for it.

Not recommended

            Select * from zcntry where cntry like ‘IN%’.

             Select single * from zflight where cntry = zcntry-cntry and airln = ‘LF’.

            Endselect.

 

Recommended

            Select * from zcnfl where cntry like ‘IN%’ and airln = ‘LF’.

            Endselect.

個人體會:這樣用起來方便

Use of the into table clause of select statement:將資料一次取到表中,減少資料庫訪問次數

Instead of appending one record at a time into an internal table, it is advisable to select all the records in a single shot.

 Not recommended

            Refresh: int_fligh.

            Select * from zflight into int_fligh.

             Append int_fligh. Clear int_fligh.

            Endselect.

 

Recommended

            Refresh: int_fligh.

            Select * from zflight into table int_fligh.

個人體會:應該說資料庫的訪問效率還是比較低的,所以減少對話,把資料抓到程式中做運算準備

 

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

相關文章