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.
推荐
Select max( fligh ) from zflight into maxnu where airln = ‘LF’ and cntry = ‘IN’.
3、使用视图代替基本表查询
不推荐
Select * from zcntry where cntry like ‘IN%’.
Select single * from zflight where cntry = zcntry-cntry and airln = ‘LF’.
Endselect.
推荐
Select * from zcnfl where cntry like ‘IN%’ and airln = ‘LF’.
Endselect.
4、使用INTO table 代替select endselect
不推荐
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 statementsSelect distinct
Select … for update
Order by, group by, having clause
Joins
Use the Bypass buffer addition to the select clause in order to explicitly bypass the buffer while selecting the data.
9、 使用FOR ALL Entries
不推荐
Loop at int_cntry. Select single * from zfligh into int_fligh where 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 join
Let 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.
Select a~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 the selection criteria, a where clause can be added to the above inner join.
13、使用sort by 代替order by
14、避免使用SELECT DISTINCT语句
使用的 ABAP SORT + DELETE ADJACENT DUPLICATES 代替

二、

ABAP/4的程序会需要花费大量的时间执行,而且会使其它进程被迫暂停以等待当前程序运行结束。

1.尽量把更多选择项放在用户选择界面上,以避免程序一次选出大量的数据。
2.做好表的索引,这一点才是最关键的,在where 里,查询条件的顺序最好跟索引关键字一样,要不然你的索引就不起什么作用。
3.尽量使用这样的选择语句SELECT A B C INTO TABLE ITAB,最好是跟表的字段顺序相同。这个操作会将所有符合条件的数据一次性地读进内表,这比在SELECT A B C INTO ITAB... ENDSELECT的循环中添加数据到内表要快。请注意,这里声明的内表还应该符合第3条的条件。
4.用OCCURS NUM_RECS声明内表,NUM_RECS参数是你估计(或希望)使用到的数据条数。如果使用到的记录条数超出NUM_RECS参数的限制,数据将被存放在硬盘上的交换空间(不是内存)。
5.尽可能使用SELECT SINGLE语句。
6.LOOP/ENDLOOP里面使用READ TABLE...来读取另一内表,不要再使用LOOP/ENDLOOP来嵌套.LOOP/ENDLOOP处理内表数据,使用SUM/COLLECT来处理数值字段.
7.内表使用完之后,应使用FREE来释放内存.
8.尽可能多地使用表的键值作为WHERE分句的条件选项。尽可能让程序只读取一定范围内的记录(比如说,你只准备操作一个月之内的业务数据,那么对于这一个月的业务就应该有一定的范围取值,如1000~2000。)
9.如果读出的记录条数在持续增长,你应该把这些数据分割成几个固定大小的数据块。比如说,你想调出一年的数据,就可以按照月份把一年的数据分成12个月调出。这样做能减少I/O的操作。
10.Field-groups(字段组)对于多层次的排序和显示是非常有用的。它是将数据写入系统的页面文件,而不是内存(内表是使用内存的)。基于这个原因,field-groups比较适合于处理大量数据的列表(一般超过50000条记录)。如果涉及大量的数据处理,应该首先和系统管理员协商来决定这个程序最多能使用多少内存,以计算这个程序需要使用多少资源。然后你就可以决定是把数据写入内存还是交换空间。
field-groups:header.
insert ... into header.
do.
...
extract header.
enddo.
sort descending.
loop.
....
  write: ...
endloop.
 11.尽量用后勤数据仓库来查询  
    最主要的是尽量减少I/O操作,然后是内存占用,在再就是CPU的负载。类似对硬盘的读写的I/O 操作是最耗费时间的。如果对内存的操作不加以控制,可能有些时候不得不对硬盘的交换空间操作,这样就增加了对磁盘的I/O读写操作。CPU的负载可以通过优化程序来改善,在程序中尽量使用诸如SUM(SQL语句)或者COLLECT(ABAP语句)。
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值