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

Delete from Internal Table

Former Member
0 Likes
1,148

Hi,

I have 2 internal tables.

ITAB1 has 100 records.

ITAB 2 has 10 records.

I want to delete the records from ITAB1 which are present in the ITAB2.

Is htere any way without using the LOOP?

Thanks in advance.

11 REPLIES 11
Read only

Former Member
0 Likes
1,079

do.

read itab2 into wa index sy-index.

if sy-sbrc ne 0.

exit.

endif.

read itab1 where itab1 eq wa.

if sy-subrc eq 0.

delete itab1.

modify itab1.

endif.

enddo.

Read only

Former Member
0 Likes
1,079

hi there....

do as follows

loop at itab1.

loop at itab2.

if itab1-field1 eq itab2-field1 and itab1-field2 eq itab2-field2.....

clear itab2.

update itab2.

endif.

endloop.

endloop.

i hope it helps...

do reward if helpful.

Read only

Former Member
0 Likes
1,079

Hi ,

combined two internal table into final_itab and use

DELETE ADJACENT DUPLICATES final_itab COMPARING VALUES.

Regards,

Vishvesh.

Read only

Former Member
0 Likes
1,079

Hi,

LOOP AT ITAB1 into wa_itab1
READ TABLE ITAB2 WITH VAR = wa_itab1-VAR1.
DELETE TAble ITAB1 from wa_itab1
ENDLOOP.

Read only

ThomasZloch
Active Contributor
0 Likes
1,079

Not possible without some sort of loop. My general approach would be:

- LOOP AT the smaller table using ASSIGNING (not INTO)

- READ the corresponding entry in the larger table (table should be of type SORTED, use full table key for access) using TRANSPORTING NO FIELDS

- if found, DELETE that entry from the larger table using INDEX

Thomas

Read only

Former Member
0 Likes
1,079

hi,

If same fields are there in both internal tables then you can combine data in one internal table and just use DELETE ADJACENT DUPLICATES ..

& if different fields are there then use

LOOP AT it_prd.

READ TABLE it_chs WITH KEY

spras = 'E'

msehi = it_prd-msehi.

IF sy-subrc NE 0.

WRITE:/ w_tmp.

APPEND it_prd TO it_s.

incs = incs + 1.

ENDIF.

if sy-subrc EQ 0.

clear it_chs.

endif.

ENDLOOP.

reward points if useful.

thx,

twinkal

Read only

Former Member
0 Likes
1,079

may be you dont want looping because of performance

in delete statement you provide values in where condition which are in itab2

Read only

Former Member
0 Likes
1,079

Hi,

To reduce time taken,

Loop at itab2.

delete itab1 where key1 = itab1-key1.

endloop.

In all, you will loop only 10 times.

Shruthi

Read only

Former Member
0 Likes
1,079

Hello Pranu,

if you are looking for a sinle code line whic can delete one internal table rows from another similar internal table... then I am sorry there is no such way as of now. You have to use some form logic with loop process as described by SDN members.

However "DELETE ADJACENT DUPLICATES FROM... " may not meet the requirement as one set of value still remains in the table and only the duplicate entry is removed.

Regards,

Mahidhar

Read only

Former Member
0 Likes
1,079

Hi,

Please refer the code below:



loop at itab1.
 
   read table itab2 with key f1 = itab1-f1. "Use all necessary key fields.

if sy-subrc eq 0.
 delete itab1.
 clear itab1.
endif.

endloop.

Thanks,

Sriram Ponna.

Read only

Former Member
0 Likes
1,079

hi ,

pls try this .

loop at itab1 .

read table itab2 with key matnr = itab1-matnr .

if sy-subrc = 0.

delete itab1 index sy-tabix .

endif .

clear itab1 .

endloop .