‎2013 Nov 07 10:27 AM
Hi experts,
I have 2 tabes ; Table 1 and Table 2.
Table 1 has more records then table 2 and both of them have a common field, let's say fieldY.
I would like to add in table 1 all the entries present in table 2 and not in table 1 and ignore the common records between both tables.
I tought about the following:
Copy the content of table 2 in copytabe2.
Loop at copytabe2 into wa.
Read table 1 with key fieldY = wa-fieldY.
if sy-subrc eq 0.
delete copytabe2 .
endif.
endloop.
Append lines of copytable2 into table1.
Thanks for your support.
Amine
PS:All the tables are internal tables in a program.
‎2013 Nov 07 10:32 AM
Hi-
This is what I would suggest.
APPEND LINES OF ITAB2 TO ITAB1.
SORT ITAB1 BY <Common Field>.
DELETE ADJACANT DUPLICATES FROM ITAB1 COMPARING <Common Field>.
-Venkat
‎2013 Nov 07 10:32 AM
Hi-
This is what I would suggest.
APPEND LINES OF ITAB2 TO ITAB1.
SORT ITAB1 BY <Common Field>.
DELETE ADJACANT DUPLICATES FROM ITAB1 COMPARING <Common Field>.
-Venkat
‎2013 Nov 07 10:54 AM
Hi Venkat,
Thanks for your answer. I actually tought about this possiblity. In case where table 1 and Table 2 are different in term of structure. I guess that i can't append lines of itab1 into itab2 directly.
I have to create a structure (str+tabstr) simlar to itab1, then:
loop at itab2 into wa.
str = wa.
append str into tabstr.
endloop.
Can you confirm me?
Thanks.
Amine
‎2013 Nov 07 11:04 AM
Agreed!
Approach 1:
ITAB1, WA1, ITAB2 and WA2.
LOOP AT itab2 INTO wa2.
MOVE-CORRESPONDING wa2 TO wa1.
APPEND wa1 TO itab1.
ENDLOOP.
SORT itab1 BY fieldy.
DELETE ADJACENT DUPLICATES FROM itab COMPARING fieldy.
Approach 2:
DATA: lv_tabix TYPE sy-tabix.
LOOP AT itab2 INTO wa2.
CLEAR: wa1,
lv_tabix.
lv_tabix = sy-tabix.
READ TABLE itab1 INTO wa1 WITH KEY fieldy = wa2-fieldy.
IF sy-subrc = 0.
DELETE itab2 INDEX lv_tabix.
ENDIF.
ENDLOOP.
-Venkat
‎2013 Nov 07 11:07 AM