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

Internal table

Former Member
0 Likes
685

Hi,

For example i have around 200 records in the first internal table. And in my second internal table i have 30 records. These 30 records are available in my first internal table also. Now i need to delete the remaining 170 records from the first internal table. The common field in these table is OBJNR. Based on this i need to delete the records.

Regards,

Ramesh

8 REPLIES 8
Read only

Former Member
0 Likes
661

Hiiiiiiii

just try the following code

<b>loop at itab2.

read table itab1 with key objnr = itab2-objnr.

if sy-subrc <> 0.

delete itab1 index sy-tabix.

else.

continue.

endif.

endloop.</b>

Reward if it helps u.

Read only

0 Likes
661

Hi,

I tried with the logic provided, but still i am unable to delete the records from the first internal table.

Regards,

Ramesh

Read only

0 Likes
661

Harita,

This won't help since itab 2 has only 30 records code will delete only 30 records from itab1 which are not in itab2.

Thanks,

Pankaj Singh

Read only

Former Member
0 Likes
661

Assume itab1 with 200 records and itab2 with 30 records.

Add one field " flag type c" to structure of itab1.

Now try below code:

sort itab1 by objnr.

loop at itab2 into wa_itab2.

read table itab1 into wa_itab1 with key objnr =wa_itab2-objnr binary search.

if sy-subrc = 0.

wa_itab1-flag = 'X'.

modify itab1 from wa_itab1.

endif.

endloop.

delete itab1 where flag = 'X'.

I hope it helps.

Best Regards,

Vibha

*Please mark all the helpful answers

Read only

former_member673464
Active Contributor
0 Likes
661

hi Ram,

You can use read statement to retrieve data from first internal table comparing with the second internal table field using loop at and append that line to third internal table(new one). Then you will have all the data containing data for your requirement.

regards,

veeresh

Read only

Former Member
0 Likes
661

Hi Ram,

Here is the simple solution,

loop at itab1.

loop at itab2 where objnr <> itab1-objnr.

delete itab1.

endloop.

endloop.

Regards,

Kiran B.

Read only

messier31
Active Contributor
0 Likes
661

Hi Ram,

Check code below for this,

say IT1 - itab with 200 records ( Add one more field in this itab say indicator. )

IT2 - itab with 30 records

<b>loop at it2.

read table it1 with key objnr = it2-objnr.

if sy-subrc = 0.

it1-indicator = 'X'.

modify it1 index sy-tabix.

endif.

endloop.

delete it1 where indicator <> 'X'.</b>

This will loop only for 30 rec in IT2 .

Hope this helps you.

Enjoy SAP.

Pankaj Singh.

Read only

Former Member
0 Likes
661

Hi ram,

check this code.this will solve ur problem with out adding extra field.

data:itab1 like mara occurs 0 with header line.

data:itab2 like mara occurs 0 with header line.

select * from mara into table itab1.

select * from mara into table itab2 up to 2 rows.

loop at itab1.

write:/ itab1-matnr.

endloop.

skip 2.

loop at itab2.

write:/ itab2-matnr.

endloop.

skip 2.

loop at itab1.

read table itab2 with key matnr = itab1-matnr.

if sy-subrc <> 0.

delete itab1 where matnr = itab1-matnr.

endif.

endloop.

loop at itab1.

write:/ itab1-matnr.

endloop.

reward if helpful.