SAP ABAP Performance Tuning
Tips & Tricks
Performance Analysis Tools
Use of selection criteria:查詢數據加入限定條件,不要取不必要的東西-->能少則少
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博客 ” ,链接:https://blog.itpub.net/554557/viewspace-470534/ ,如需转载,请注明出处,否则将追究法律责任。