2014 Oct 15 4:19 PM
Dear experts,
I got 2 internal tables (1, 2), both of them have one key (MBLNR)
and I got one internal table (3) based on structure with some fields form table 1 and some fields from the table 2.
What is the best way to fulfill the table 3 based on the MBLNR with information from tables 1 and 2?
Dear experts,
I got 2 internal tables (1, 2), both of them have one key (MBLNR)
and I got one internal table (3) based on structure with some fields form table 1 and some fields from the table 2.
What is the best way to fulfill the table 3 based on the MBLNR with information from tables 1 and 2?
2014 Oct 15 4:28 PM
Hi Denis,
Hope this logic helps you. <request for rewards removed>
LOOP AT 3rd internal_table into 3rd_wa.
LOOP AT 1st_internal_table into 1st_wa.
if 3rd_wa-mblnr = 1st_wa-mblnr.
(COPY the values needed from the 1st table to 3rd table).
else.
continue.
endif.
ENDLOOP.
LOOP AT 2nd_internal_table into 2nd_wa.
if 3rd_wa-mblnr = 2nd_wa-mblnr.
(COPY the values needed from the 2nd table to 3rd table).
else.
continue.
endif.
ENDLOOP
MODIFY 3rd internal_table into 3rd_wa.
ENDLOOP.
Best Regards,
Charlie
Message was edited by: Gareth Ryan Please don't ask for rewards.
2014 Oct 15 4:58 PM
Hi Denis,
If you have 1 record per MBLNR, then this is a unique key. All 3 tables should thus be defined as TYPE SORTED TABLE WITH UNIQUE KEY mblnr.
I did not understand if table 3 is alrteady filled with mblnr an some attributes or if this shall be the result of the process.
For all table accesses use field-symbols. It is faster, i.e.
LOOP AT 3rd_internal_table ASSIGNING <3rd_internal>.
LOOP AT 1st_internal_table ASSIGNING <1st_internal>
* Loop will use the table key - very fast - one record found or none!
WHERE mblnr = <3rd_internal>-mblnr.
<1st_internal>-field1 = <3rd_internal>-field1.
<1st_internal>-field2 = <3rd_internal>-field2.
*...(COPY the values needed from the 1st table to 3rd table).
ENDLOOP.
*...
ENDLOOP.
If you are on ABAP 740 you can use in-line-declaration of field-symbols, i.e.
LOOP AT 3rd_internal_table ASSIGNING FIELD-SYMBOL(<3rd_internal>).
Regards
Clemens
2014 Oct 15 5:36 PM
Hi Clemen,
Thanks for your feedback. I agree with you in using field symbols rather than working with work area. I'll definitely work with field-symbols for most of my programs as I have read on most of the articles that field-symbols can provide better performance. Thanks once again.
Best Regards,
Charlie
2014 Oct 15 5:49 PM
Hi Charlie,
yes, FIELD-SYMBOLS are never slower than work areas but many developers are stuck with the things they learned 15 years or longer ago.
The real performance boost will come in this case from using internal tables with index.
LOOP ASSIGNING .... <field-symbol> and is available since release 4.0, defining keys for internal tables not much later.
Still most developers avoid to use all the nice features ):-
Regards
Clemens
2014 Oct 16 1:49 AM
Hi Clement,
Noted and thank you for your inputs, I'm actually quite a newbie in ABAP and most of the time I actually thought that what I do are the basics, I have tried using field symbols though I was not able to compare it with the performance of a work area. thank you thank you again!
Best Regards,
Charlie
2014 Oct 15 5:56 PM
How are you filling these internal tables? Many times, multiple internal tables are the result of a chain of select statements using FOR ALL ENTRIES. By using a JOIN select instead, you could read the data into one final internal table straight away and avoid the problem altogether.
Thomas
2014 Oct 16 2:27 AM
Hi Denis,
Hope it help full.
Loop at itab1 ASSIGNING <fs1.>.
read table itab2 ASSIGNING <fs2.> with key mblnr = <fs1>-mblnr.
if sy-subrc = 0.
move-corresponding <fs1> to wa3.
move-corresponding <fs2> to wa3.
append wa3 to itab3.
clear wa3.
endif.
endloop.
Regards,
Venkat.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |