I'm looking for a faster way to add to an existing string in ABAP.
ABAP version NW 7.x
Currently the string concatenation takes a very long time, especially once the string gets large. We need to build strings that are > 10 mb.
The string is constructed logically with many x = x + y
operations.
concatenate l_main_string l_extra into l_main_string. " very slow
Is there a faster way to construct large strings in ABAP? Perhaps Kernel tool we can call?
EDIT: Based on Feedback and answer posted.
Most useful is the blog Linked by VWegert. Is really the answer to the question.
It also seems the key issue is older kernels out customers are using.
The && and Concatenate where very similar on our system. (NW 7.50) 1.46s vs 1.50s repsectively. Clearly the same optimisation was running and it works in a acceptable way.
METHOD PERF_TEST_STRING. " 1.50 sec
DATA: n TYPE i value 5000000,
lv_string TYPE string.
do n times.
CONCATENATE lv_string 'ABCDEFGHIJ0123456789' into lv_string.
ENDDO.
r_len = strlen( lv_string ).
ENDMETHOD.
METHOD PERF_TEST_STRING2. "1.46
DATA: n TYPE i value 5000000,
lv_string TYPE string.
do n times.
lv_string = lv_string && 'ABCDEFGHIJ0123456789'.
ENDDO.
r_len = strlen( lv_string ).
ENDMETHOD.
So i'm off to check kernel level of customer and look for another reason why things are slow.
BTW: I CANT use
x = x && Y. " doesnt work prior to < 7.20
since many of customers dont have >=7.20 :(