天天看點

ABAP傳值和傳引用的性能比較 - pass by value VS pass by reference

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:

ABAP傳值和傳引用的性能比較 - pass by value VS pass by reference

test result

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

ABAP傳值和傳引用的性能比較 - pass by value VS pass by reference

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.

ABAP傳值和傳引用的性能比較 - pass by value VS pass by reference

繼續閱讀