SAP Stringbuilder for ABAP?

I am looking for a faster way to add to an existing line in ABAP.

ABAP version NW 7.x

Nowadays, string concatenation takes a very long time, especially after the string gets big. We need to build lines> 10 mb in size.

The line is built logically with many operations x = x + y

.

concatenate l_main_string l_extra into l_main_string. " very slow

      

Is there a faster way to build large strings in ABAP? Perhaps a kernel tool can be called?

EDIT: Based on feedback and response.
Most helpful is the VWegert related blog. In fact, this is the answer to the question. It also seems that the old kernels that clients use are the key issue.

& & and Concatenate, which are very similar to our system. (NW 7.50) 1.46s versus 1.50s re. Obviously the same optimization has been run and it works in an 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 want to check the client kernel layer and look for another reason why things are going slowly.
BTW: i cant use

x = x && Y.    " doesnt work prior to < 7.20

      

as many clients don't have> = 7.20 :(

+3


source to share


1 answer


Use the following format:

l_main_string = |{ l_main_string }{ l_extra }|.

      

I ran two tests, one that linked a ten-digit string for myself 50,000 times to test small paddings, and another that added a string for myself 26 times to test large paddings (this is very fast, very fast).


Small string concatenation test

DO 15 TIMES.
  lv_string = '1234567890'.
  DO 50000 TIMES.
    CONCATENATE '1234567890' lv_string INTO lv_string.
  ENDDO.
ENDDO.

      

Execution time: 775778ms (51718ms on average per run).

DO 15 TIMES.
  lv_string = '1234567890'.
  DO 50000 TIMES.
    lv_string = |1234567890{ lv_string }|.
  ENDDO.
ENDDO.

      



Execution time: 100543 ms (6702 ms on average per run).

Performance increase over CONCATENATE

: 672%

Large string concatenation test

DO 15 TIMES.
  lv_string = '1234567890'.
  DO 26 TIMES.
    CONCATENATE lv_string lv_string INTO lv_string.
  ENDDO.
ENDDO.

      

Execution time: 143116ms (average value is 9541ms per run).

DO 15 TIMES.
  lv_string = '1234567890'.
  DO 26 TIMES.
    lv_string = |{ lv_string }{ lv_string }|.
  ENDDO.
ENDDO.

      

Execution time: 51995 (3466 ms average).

Performance increase over CONCATENATE

: 175%

+4


source







All Articles