Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Slow Performance i.e. pimping up an internal table loop

mario_maisto
Participant
0 Likes
3,186

Hi there,

I am struggling with a quite simple loop, that is weirdly slow. I was wondering if maybe you can give me a helping hand on this subject.

So, I have 2 selects into internal tables, that are fast ( approx. 1 sec for both select), e.g. lt_a and lt_b, where lt_a has a sub-table where the corresponding lt_b rows should go (connected by an identifier id ). So - here's my loop:


*Note: some number and performance information:
lt_a (6 columns) - approx 55 000 rows
lt_b (4 columns) - approx 40 000 rows
time: ~45 seconds (!)

Is there something I could enhance? Should I use corresponding or go with the value (col1 = <fs_b>-col1 .. ) ?

Thank you,

Mario


 data: lt_b type standard table of ty_b with key id "lt_a defined as an attribute somewhere else
....
sort lt_b by id. loop at lt_b assigning field-symbol(<fs_b>).
assign lt_a[ id = <fs_b>-id ]-subtable to field-symbol(<fs_a_subtable>). " which one is faster - corresponding or insert value.. ? insert corresponding #( <fs_b> ) into table <fs_a_subtlable>. " Commented out.. as corresponding is shorter (but is it slower ?) * insert value lt_a( * col1 = <fs_b>-col1 * col2 = <fs_b>-col2 * col3 = <fs_b>-col3
* col4 = <fs_b>-col4 * ) into table <fs_a_subtable>. endloop.
1 ACCEPTED SOLUTION
Read only

ruben_rollano
Participant
2,663

You need to work with sorted tables both with the same ID. You are going to see an incredible improvement in performance. Do not work never with this king of declaration like TYPE STANDARD TABLE for this king of development.

I imagine that you are working without HANA database. If you have HANA you can model a CDS view preparing the data.

Best regards.

Hi there,

I am struggling with a quite simple loop, that is weirdly slow. I was wondering if maybe you can give me a helping hand on this subject.

So, I have 2 selects into internal tables, that are fast ( approx. 1 sec for both select), e.g. lt_a and lt_b, where lt_a has a sub-table where the corresponding lt_b rows should go (connected by an identifier id ). So - here's my loop:


*Note: some number and performance information:
lt_a (6 columns) - approx 55 000 rows
lt_b (4 columns) - approx 40 000 rows
time: ~45 seconds (!)

Is there something I could enhance? Should I use corresponding or go with the value (col1 = <fs_b>-col1 .. ) ?

Thank you,

Mario


 data: lt_b type standard table of ty_b with key id "lt_a defined as an attribute somewhere else
....
sort lt_b by id. loop at lt_b assigning field-symbol(<fs_b>).
assign lt_a[ id = <fs_b>-id ]-subtable to field-symbol(<fs_a_subtable>). " which one is faster - corresponding or insert value.. ? insert corresponding #( <fs_b> ) into table <fs_a_subtlable>. " Commented out.. as corresponding is shorter (but is it slower ?) * insert value lt_a( * col1 = <fs_b>-col1 * col2 = <fs_b>-col2 * col3 = <fs_b>-col3
* col4 = <fs_b>-col4 * ) into table <fs_a_subtable>. endloop.
4 REPLIES 4
Read only

Former Member
2,663

If the ids are unique Try to add hashed key to the tables with components id and in your select get the results with order by id

Else add sorted key with non unique key id

Read only

ruben_rollano
Participant
2,664

You need to work with sorted tables both with the same ID. You are going to see an incredible improvement in performance. Do not work never with this king of declaration like TYPE STANDARD TABLE for this king of development.

I imagine that you are working without HANA database. If you have HANA you can model a CDS view preparing the data.

Best regards.

Read only

DoanManhQuynh
Active Contributor
2,663

best way is try joint or use for all entries first.

if your requirement is just move data like that, you may try FILTER or CORRESPONDING command too.

Read only

mario_maisto
Participant
2,663

Obviously, Ruben Rollano Carcajona, Xavier Joubert, Quynh Doan Manh - you were all correct, and by putting together those pieces, I improved the performance from 45 seconds to 1.6 🙂 !.

So, i used sorted table with the key 'id' together with:

loop at lt_a assigning field-symbol(<fs_a>).
 <fs_a>-subtable = corresponding #( filter #( lt_b where id eq <fs_a>-id ) ).
endloop.

Thank you for the help!
Best regards,

Mario