优化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 代替.
********************************************************************************************
- 是关于符号的,这点可能注意的人比较少,尽可能用EQ、NE来代替=、<> 等符号,因为用符号的话也会导致读取时效率降低;
- 选用一些替代表/替代字段(VBFA, SHP_IDX_)
曾做过一些类似于“未拣配交货单”、“未发货过账交货单”的报表,刚开始用的是LIKP、VBUK等表,速度并不理想。后来调试了标准程序VL06O,发现其用的表是SHP_IDX_PICK、SHP_IDX_GDSI等。原来系统在创建交货单的时候,也会更新这些临时表。当拣配完成,该条目就从SHP_IDX_PICK中删除。所以表SHP_IDX_PICK的条目数始终不多,查询速度很快。
同样的,当我们在多个表中进行查询时,可能不同的限制条件都能达到同样的结果集,但效率差异就很大,所以选用有效的字段非常关键。比如需要查询某销售组织某天已发货的销售订单,我们可以将VBAP与LIPS联查。此时查询条件VBAK-LIFSK=SPACE或VBAP-ABGRU=SPACE并不影响查询结果,但它们可以在第一时间就排除大量无关的订单,对于性能的提升帮助很大。 - 关于表连接语句(INNER JOIN, LEFT JOIN…)
写报表的时候,表与表之间的关联是不可避免的。通常而言,表连接语句要掌握的原则有:
(1)
将最有效的查询条件所对应的表放在第一位。换言之,让查询第一个表后所得到的结果集就尽可能小。
比如有一张报表叫做订单状态统计表,可能查完VBAK、VBAP后还查询LIPS、VTTP等,界面上的查询条件很多。不过据了解得知,该报表主要是查看昨天创建或前几天创建的订单。那么最有效的限制条件自然是订单创建日期,以及销售组织了,而表连接的主表宜选用VBAK。
(2)
确定了表连接的次序后,应考虑将查询条件尽量限制在靠前的表里。比如选择屏幕上有个物料号的查询条件,而我们知道订单VBAP和交货单LIPS均有物料号,那就应该视情况而定,如果表连接中VBAP更早出现,那么WHERE子句中就使用vbap~matnr
IN s_matnr,反之就是lips~matnr IN s_matnr。
(3)
两个表之间进行连接的时候,应考虑关键字段或索引字段的作用。比如查询VTTP和LIPS时,关联关系是vttp~vbeln =
lips~vbeln。那么vttp在前,lips在后,就会比较快,因为根据vttp的vbeln查询lips时,vbeln是lips的关键字段,速度较快。而反过来如果lips在前,那根据lips~vbeln查询vttp会慢一些,除非vbeln是vttp的索引字段。
2,
先构建RANGE再执行SQL语句
有时我们所能用的查询条件不是很理想,比如查询LIKP却必须用公司代码,而非销售组织。
此时普通做法是用LIKP与TVKO根据VKORG进行表联接,从而限制TVKO~BUKRS的值。
还有一种有效的办法是,通过TVKO查询到当期公司代码所对应的全部销售组织,从而组建一个RANGE出来,再根据此RANGE查询LIKP。当然要注意RANGE的行项目有上限的,在ECC6中大概2万行将导致ABAP
DUMP。
提示:DATA r_vkorg TYPE RANGE OF likp-vkorg.
SIGN = ‘I’, OPTION = ‘EQ’,
LOW = ‘XXXX’ 即可往r_vkorg中放入多个单值。
优化ABAP性能(摘录)的更多相关文章
- ABAP性能和优化
哪些工具可以用于性能优化? ST05-性能追踪.包含SQL追踪加RFC,队列和缓存追踪.SQL追踪主要用于测量程序中select语句的性能. SE30-运行时分析.用于测量应用的性能. SAT是过时的 ...
- REORG TABLE命令优化数据库性能
[转]DB2日常维护——REORG TABLE命令优化数据库性能 一个完整的日常维护规范可以帮助 DBA 理顺每天需要的操作,以便更好的监控和维护数据库,保证数据库的正常.安全.高效运行,防止 ...
- 优化TableView性能
优化tableView性能(针对滑动时出现卡的现象) (2013-08-02 11:18:15) 转载▼ 标签: ios tableview it 分类: 技术文档 在iOS应用中,UITableVi ...
- DB2日常维护——REORG TABLE命令优化数据库性能
一个完整的日常维护规范可以帮助 DBA 理顺每天需要的操作,以便更好的监控和维护数据库,保证数据库的正常.安全.高效运行,防止一些错误重复发生. 由于DB2使用CBO作为数据库的优化器,数据库对象的状 ...
- Citrix 服务器虚拟化之十三 Xenserver虚拟机内存优化与性能监控
Citrix 服务器虚拟化之十三 Xenserver虚拟机内存优化与性能监控 XenServer的DMC通过自动调节运行的虚拟机的内存,每个VM分配给指定的最小和最大内存值之间,以保证性能并允许每 ...
- Redis 优化查询性能
一次使用 Redis 优化查询性能的实践 应用背景 有一个应用需要上传一组ID到服务器来查询这些ID所对应的数据,数据库中存储的数据量是7千万,每次上传的ID数量一般都是几百至上千数量级别. 以前 ...
- IIS优化服务器性能导致QuartZ任务未运行
问题: IIS 为优化服务器性能,会自动对它认为休眠的应用程序进行资源回收,资源回收将会导致网站应用程序关闭. 解决方案: 1. 设置闲置超时为0,固定回收时间间隔为0,即IIS不主动回收闲置进程 ...
- 优化EF性能
本文介绍一些改善EF代码.优化其性能的相关方法,如NoTracking,GetObjectByKey, Include等,还包括编译查询.存储模型视图以及冲突处理等内容.. l Mer ...
- DB2日常维护——REORG TABLE命令优化数据库性能(转)
[转]DB2日常维护——REORG TABLE命令优化数据库性能 一个完整的日常维护规范可以帮助 DBA 理顺每天需要的操作,以便更好的监控和维护数据库,保证数据库的正常.安全.高效运行,防止一些错误 ...
随机推荐
- 那些年我们赚过的外快(POS(移动支付)接口开发)
老规矩上前戏了.在我写博文"那些年我们赚过的外快"前后算起来大大小小也接了些私活,这次是因为好久没写博客了,趁热分享一下.最近回了离老家近的二线城市成都工作,收入那是下降很多啊,刚 ...
- Android Studio NDK 学习之接受Java传入的字符串
本博客是基于Android Studio 1.3 preview版本,且默认你已经安装了Android SDK, Android NDK. 用Android Studio新建一个工程叫Prompt,其 ...
- IIS7下配置SSAS通过HTTP远程连接
淘宝 问答 学院 博客 资源下载 高端培训 登录 注册 全部问题 文章 话题 人物 ...
- Safari下默认10位数字为电话号码,点击拨号
<meta content="telephone=no" name="format-detection"/>
- java简单统计.java文件中的有效代码行,空行,注释行
package regxdemo; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundExc ...
- Java后端书架
本书架主要针对Java后端开发与架构. 更新记录:4.0版把第五部份-具体技术的书整块拿掉了.<TCP/IP详解 卷1:协议>出到了第二版,增加<SRE:Google运维解密> ...
- [水煮 ASP.NET Web API 2 方法论] 目 录
一.ASP.NET 中的 Web API [水煮 ASP.NET Web API2 方法论](1-1)在MVC 应用程序中添加 ASP.NET Web API 与 ASP.NET MVC 在同一个进程 ...
- DataList分页访问FooterTemplate模板里的控件
今天做DataList分页的时候,突然想把分页控件写在FooterTemplate模板里面,弄了很久都访问不到控件,终于发现问题所在,以下是访问FooterTemplate里控件的方法: <Fo ...
- Free Slideshow, Gallery And Lightboxes Scripts
http://bootstraphelpers.codeplex.com/SourceControl/list/changesets https://github.com/gordon-matt/Bo ...
- [PE结构分析] 10.基址重定位
源代码如下: typedef struct _IMAGE_BASE_RELOCATION { DWORD VirtualAddress; DWORD SizeOfBlock; // WORD Type ...