2019 Sep 12 7:59 AM
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.
2019 Sep 12 9:20 AM
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.
2019 Sep 12 8:50 AM
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
2019 Sep 12 9:20 AM
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.
2019 Sep 12 9:23 AM
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.
2019 Sep 12 10:08 AM
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
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |