天天看點

一些通過SAP ABAP代碼審查得出的ABAP程式設計最佳實踐The validation logic for input records should be improvedAvoid using SELECT to access table with a large number of entries使用并發程式設計提高應用程式場景

1. 這兩個IF ELSE分支裡檢測的條件其實邏輯上來說都是同一類,應該合并到一個IF分支裡進行檢查:

一些通過SAP ABAP代碼審查得出的ABAP程式設計最佳實踐The validation logic for input records should be improvedAvoid using SELECT to access table with a large number of entries使用并發程式設計提高應用程式場景
It is an expensive operation to open a file in application server with 50MB file size.
一些通過SAP ABAP代碼審查得出的ABAP程式設計最佳實踐The validation logic for input records should be improvedAvoid using SELECT to access table with a large number of entries使用并發程式設計提高應用程式場景

Current logic is:

1. Open the file in application server

2. Read the file content line by line

3. If the file is regarding IPG or MIDH or TPG, handle with each line separately

The correct logic should be:

1. Check the file path whether it is IPG or MIDH or TPG related. If not, quit the report.

2. Handle with each line directly without evaluate file path in the BIG loop.

The validation logic for input records should be improved

一些通過SAP ABAP代碼審查得出的ABAP程式設計最佳實踐The validation logic for input records should be improvedAvoid using SELECT to access table with a large number of entries使用并發程式設計提高應用程式場景

Loop at all service BOM, check whether the ID in current loop does exist in validation table lt_valid_prod or lt_valid_sp. If so, delete them via DELETE TABLE XXX FROM .

Improvement: use DELETE XXX WHERE product_id NOT IN . It is more efficient when lt_srv_bom_file has a huge number of records. See comparison below ( unit: second )

這是一個性能問題。使用ABAP原生支援的NOT IN關鍵字可以獲得更好的性能。性能評測如下:

一些通過SAP ABAP代碼審查得出的ABAP程式設計最佳實踐The validation logic for input records should be improvedAvoid using SELECT to access table with a large number of entries使用并發程式設計提高應用程式場景

Avoid using SELECT to access table with a large number of entries

In product / IObject area, the best practice is to use OPEN CURSOR / FETCH NEXT CURSOR to access big DB table.

如果需要用ABAP OPEN SQL讀取一張包含海量記錄的資料庫表,那麼推薦使用OPEN CURSOR進行分塊讀取。

一些通過SAP ABAP代碼審查得出的ABAP程式設計最佳實踐The validation logic for input records should be improvedAvoid using SELECT to access table with a large number of entries使用并發程式設計提高應用程式場景

Although this solution will spend almost the same time to fetch the data from DB, it has far less memory consumption compared with using SELECT to fetch ALL data from DB at one time.

The original dump due to out of memory issue could be eliminated by replace SELECT with OPEN CURSOR statement.

這種方式和直接用SELECT相比,能顯著減少記憶體消耗量。

使用并發程式設計提高應用程式場景

通過下面這段代碼模拟一個費時的ABAP程式:

定義一個ABAP函數:

一些通過SAP ABAP代碼審查得出的ABAP程式設計最佳實踐The validation logic for input records should be improvedAvoid using SELECT to access table with a large number of entries使用并發程式設計提高應用程式場景
一些通過SAP ABAP代碼審查得出的ABAP程式設計最佳實踐The validation logic for input records should be improvedAvoid using SELECT to access table with a large number of entries使用并發程式設計提高應用程式場景

這個函數裡執行一大堆計算,然後把傳入的product ID寫到一張自定義表ZJERRY1裡。

一些通過SAP ABAP代碼審查得出的ABAP程式設計最佳實踐The validation logic for input records should be improvedAvoid using SELECT to access table with a large number of entries使用并發程式設計提高應用程式場景

調用這個函數的代碼:

一些通過SAP ABAP代碼審查得出的ABAP程式設計最佳實踐The validation logic for input records should be improvedAvoid using SELECT to access table with a large number of entries使用并發程式設計提高應用程式場景
一些通過SAP ABAP代碼審查得出的ABAP程式設計最佳實踐The validation logic for input records should be improvedAvoid using SELECT to access table with a large number of entries使用并發程式設計提高應用程式場景

注意第二種方案使用STARTING NEW TASK達到的并發執行效果:

一些通過SAP ABAP代碼審查得出的ABAP程式設計最佳實踐The validation logic for input records should be improvedAvoid using SELECT to access table with a large number of entries使用并發程式設計提高應用程式場景

通過比較,第二種解決方案的效率是第一種的四倍。

一些通過SAP ABAP代碼審查得出的ABAP程式設計最佳實踐The validation logic for input records should be improvedAvoid using SELECT to access table with a large number of entries使用并發程式設計提高應用程式場景

1. The more CPU & DB time spent in ZINSERT, the better performance will be gained by using

parallel processing (Asynchronous RFC call).

2. The more number of ZINSERT call, the better performance will be gained by using parallel

processing.

一些通過SAP ABAP代碼審查得出的ABAP程式設計最佳實踐The validation logic for input records should be improvedAvoid using SELECT to access table with a large number of entries使用并發程式設計提高應用程式場景