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

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

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

1240

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

1240

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

1240

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关键字可以获得更好的性能。性能评测如下:

1240

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

1240

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

1240

1240

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

1240

调用这个函数的代码:

1240

1240

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

1240

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

1240

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.

1240

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

1240

转载于:https://www.cnblogs.com/sap-jerry/p/10350638.html

你可能感兴趣的文章
Uncaught SyntaxError: Unexpected token ILLEGAL
查看>>
一个预处理定义的问题
查看>>
ANDROID L——Material Design综合应用(Demo)
查看>>
自我介绍以及关于软件工程的问题
查看>>
struts (一)
查看>>
【新番推荐】工作细胞
查看>>
NYOJ 16 矩形嵌套
查看>>
Leetcode中的SQL题目练习(二)
查看>>
dubbo 集群容错源码
查看>>
Collection接口的子接口——Queue接口
查看>>
LINUX安装NGINX
查看>>
服务器启动项目抛错 没有到主机的路由
查看>>
python_85_sys模块
查看>>
第九周动手动脑
查看>>
HDU 1811 Rank of Tetris
查看>>
winform 获取当前名称
查看>>
MyBatis笔记一:GettingStart
查看>>
查找不同的木棍
查看>>
面试题:顺时针打印矩阵
查看>>
DataSet、DataTable、DataRow、DataColumn区别及使用实例
查看>>