zl程序教程

您现在的位置是:首页 >  工具

当前栏目

ABAP传值和传引用的性能比较 - pass by value VS pass by reference

vs性能 比较 by 引用 value ABAP 传值
2023-09-14 09:02:51 时间

When I was doing MyTask offline performance optimization, I hesitated about whether to use pass by value or pass by reference.

Pass by value pattern using RETURNING keyword:

lt_result = get_XXX().

Pass by reference pattern using IMPORTING keyword:

get_XXX( importing et_result = lt_result ).

I know that in theory, passing by reference has better performance than passing by value, since in former case, method of passing data from actual parameters to formal parameters when the proecdure is called. It is defined in the parameter interface of a procedure. In pass by reference, no local data object is specified for the actual parameter. Instead, the procedure receives a reference to the actual parameter during the call, and works with the actual parameter itself.
However, since the advantage of passing by value is I can type fewer characters which is appealing for a lazy programmer, I tend to choose passing by value if the performance difference between the two is trivial.

As a result I built a test case for performance comparison:

test result

for data volume with 1000 records, performance difference is 0.4 millisecond.

for data volume with 1 million records, performance difference is 0.2 seconds.
Base on this measurement, you can make decision accordingly. For my task optimization, since the magnitude of thousands makes more sense, so I choose passing by value finally.

Source code

See this method in AG3 for reference.

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