博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
一些通过SAP ABAP代码审查得出的ABAP编程最佳实践
阅读量:2441 次
发布时间:2019-05-10

本文共 2119 字,大约阅读时间需要 7 分钟。

1. 这两个IF ELSE分支里检测的条件其实逻辑上来说都是同一类,应该合并到一个IF分支里进行检查:

webp

It is an expensive operation to open a file in application server with 50MB file size.

webp

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

webp

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 <current line>.

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

这是一个性能问题。使用ABAP原生支持的NOT IN关键字可以获得更好的性能。性能评测如下:

webp

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进行分块读取。

webp

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函数:

webp
webp

这个函数里执行一大堆计算,然后把传入的product ID写到一张自定义表ZJERRY1里。

webp

调用这个函数的代码:

webp
webp

注意第二种方案使用STARTING NEW TASK达到的并发执行效果:

webp

通过比较,第二种解决方案的效率是第一种的四倍。

webp

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.

webp

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

webp

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24475491/viewspace-2565436/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/24475491/viewspace-2565436/

你可能感兴趣的文章
JAVA编码问题的一些理解(转)
查看>>
JAVA基础:JSP与Servlet的区别(转)
查看>>
Oracle数据库备份与恢复的三种方法(转)
查看>>
解决MYSQL数据从高版本导入低版本的问题(转)
查看>>
mysql数据目录结构(转)
查看>>
解决不能通过mysql.sock连接MySQL问题的办法(转)
查看>>
mysql rpm 安装问题(转)
查看>>
在ASP中也能使用MYSQL数据库(转)
查看>>
最新版本Linux Flash 9 Beta开放发布(转)
查看>>
Linux世界这一周,有喜有忧(转)
查看>>
TerraSoft发表PS3 Linux操作领域(转)
查看>>
Linux通用系统优化(转)
查看>>
mysql事务处理(转)
查看>>
埃利森暗示发行甲骨文版红帽Linux 众说纷纭(转)
查看>>
Vista阻黑客入侵 合法程序也遭殃(转)
查看>>
防黑客不愁 DIY自己的防火墙设备(转)
查看>>
在Ubuntu上安装openssh(转)
查看>>
监控oracle的触发器语句(转)
查看>>
Bash 实例:探讨 ebuild 系统(转)
查看>>
你的INTERNAL帐号密码忘记了怎么办(转)
查看>>