This is a test message to test the length of the message box.
Login

Write a comment

Writing comments is only allowed to registered users, registration is free and does not require an email address and can be done quickly here.

Performance for LOOP with secondary key explained

RalfS - 04/02/2025 - 11:38

Hello Björn and thx for this article. I've been working on a similar documentation for my department and also stumbled across the weirdly slow access using the secondary key (in Loops/Filter or VALUE expressions).

After some considerable digging, I found the solution in the ABAP-Keyword Documentation: https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abenitab_key_secondary_update.htm

The secondary key of a table does not automatically initialized until it is used for the first time. So your time for the Loop with key includes this initilization for the secondary key.

If you force an initialization manually beforehand with the method cl_abap_itab_utilities=>flush_itab_keys( CHANGING itab = mt_data ). The loop itself will be much faster:

Without initialization: Loop with key - 2765 : 0.1345390 Filter and Lines - 2765 : 0.0005960

With: Loop with key - 2685 : 0.0003340 Filter and Lines - 2685 : 0.0004980

This behaviour is only really relevant in test programs like this, in real life code it's more about the hundreds or thousands of loops after the first one, so the initialization does not matter that much.

Best regards, Ralf


Xexer - 04/03/2025 - 23:30

Hello Ralf, thank you for the valueable feedback and that you have checked this issue. This helps better to understand this case and behavior.