# 提高ABAP性能

1、使用where语句

Select* from zflight.
Check : zflight-airln = ‘LF’ and zflight-fligh = ‘BW222’.
Endselect.

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

2、使用聚合函数

Maxnu = 0.
Select* from zflight where airln = ‘LF’ and cntry = ‘IN’.
Check zflight-fligh >maxnu.
Maxnu = zflight-fligh.
Endselect.

Selectmax( fligh ) from zflight intomaxnu where airln = ‘LF’ and cntry = ‘IN’.

3、使用视图代替基本表查询

Select* from zcntry where cntry like ‘IN%’.
Selectsingle * from zflight where cntry = zcntry-cntry and airln = ‘LF’.
Endselect.

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

4、使用INTO table 代替selectendselect

Refresh: int_fligh.
Select* from zflight into int_fligh.
Append int_fligh. Clear int_fligh.
Endselect.

Refresh: int_fligh.
Select* from zflight into table int_fligh.

5、使用批量修改内表代替逐行修改

Loop at int_fligh.
If int_fligh-flag is initial.
Int_fligh-flag = ‘X’.
Endif.
Modify int_fligh.
Endloop.

Int_fligh-flag = ‘X’.
Modify int_fligh transporting flag where flag is initial.

6、使用二分法查询，提高查询内表数据速度

Read table int_fligh with key airln = ‘LF’.

Read table int_fligh with key airln = ‘LF’ binary search.

7、两个内表添加使用批量增加代替逐行

Loop at int_fligh1.
Append int_fligh1 to int_fligh2.
Endloop.

Append lines of int_fligh1 to int_fligh2.

8、使用table buffering
Use of buffered tables is recommended to improve the performance considerably. The buffer is bypassed while using the following statements
Selectdistinct
Select… for update
Order by, group by, having clause
Joins
Use the Bypass buffer addition to theselectclause in order to explicitly bypass the buffer whileselecting the data.

9、 使用FOR ALL Entries

Loop at int_cntry.
Selectsingle * from zfligh into int_flighwhere cntry = int_cntry-cntry.Append int_fligh.
Endloop.

Select* from zfligh appending table int_fligh
For all entries in int_cntry
Where cntry = int_cntry-cntry.

10、正确地使用where语句，使查询能使用索引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
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. One more tip is that if a table begins with MANDT, while an index does not, there is a high possibility that the optimizer might not use that index.

11、正确地使用MOVE语句
Instead of using the move-corresponding clause it is advisable to use the move statement instead. Attempt should be made to move entire internal table headers in a single shot, rather than moving the fields one by one.

12、正确地使用inner joinLet us take an example of 2 tables, zairln and zflight. The table zairln has the field airln, which is the airline code and the field lnnam, which is the name of the airline. The table zflight has the field airln, the airline code and other fields which hold the details of the flights that an airline operates.
Since these 2 tables a re logically joined by the airln field, it is advisable to use the inner join.
Selecta~airln a~lnnam b~fligh b~cntry into table int_airdet
From zairln as a inner join zflight as b on a~airln = b~airln.
In order to restrict the data as per theselection criteria, a where clause can be added to the above inner join.

13、使用sort by 代替order by

14、避免使用SELECTDISTINCT语句

15、内标1批量插入内标2.

INSERT LINES OF ITAB1 [FROM N1] [TO N2] INTO [TABLE] ITAB2 [INDEX IDX].

• 博文量
196
• 访问量
172129