Application Development 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: 

delete records in internal table

Former Member
0 Kudos

Hi,

I have two internal tables itab1 and itab2.

I need to delete records from itab1 comparing the data from itab2. I tried to use the read statement within the main table.

My problem is itab2 and itab1 has multiple records and all the records need to be checked from itab2 with itab1 before deleting the records from itab1.

itab1 and itab2 have a common field 'runid' between them.

How can this be accomplished?

Thanks,

VG

1 ACCEPTED SOLUTION

venkat_o
Active Contributor
0 Kudos

Hi VG, Try this way.


data: tabix type sy-tabix.
loop at itab1.
  tabix = sy-tabix.
 LOOP at itab2 where runid = itab1-runid.
 if sy-subrc NE 0.
  delete itab1 index tabix.
 endif.
endloop.
Thanks Venkat.O

8 REPLIES 8

Former Member
0 Kudos
loop at itab1 into is1.
 read table itab2 into is2 with key runid = is1-runid.
 if sy-subrc NE 0.
  delete itab1.
 endif.
endloop.

Former Member
0 Kudos

Can you provide a example of the internal table values and how you are expecting to delete the records?

0 Kudos

Hi,

The records appear like this,

itab1

3464, 0100, PP, 1855

3475, 0100,PP,1864

3455,0100,PP,1877

3488,0100,PP,1866

itab2 records

3464,0100,PP,1855

3488,0100,PP,1866

I need to delete the records 1864 and 1877.

Thanks again,

VG

0 Kudos

deleted

Edited by: Vikranth.Reddy on Oct 5, 2009 10:10 PM

0 Kudos

Yes. I got it.

Thanks

VG

venkat_o
Active Contributor
0 Kudos

Hi VG, Try this way.


data: tabix type sy-tabix.
loop at itab1.
  tabix = sy-tabix.
 LOOP at itab2 where runid = itab1-runid.
 if sy-subrc NE 0.
  delete itab1 index tabix.
 endif.
endloop.
Thanks Venkat.O

Former Member
0 Kudos

>

> Hi VG, > Try this way. >


> data: tabix type sy-tabix.
> loop at itab1.
>   tabix = sy-tabix.
>  _LOOP at itab2 where runid = itab1-runid._
_>  if sy-subrc NE 0._
>   delete itab1 index tabix.
>  endif.
> endloop.
> > Thanks > Venkat.O

Venkat, inside a loop a IF SY-SUBRC NE 0 doesn't make sense because you are in the loop only after the condition in WHERE clause is satisfied (which means SY-SUBRC is always 0). Also you are missing another ENDLOOP.

venkat_o
Active Contributor
0 Kudos

Hey thanks for highlighting my mistake. I just wrote without system.


data: tabix type sy-tabix.
loop at itab1.
  tabix = sy-tabix.
 Read table itab2 with key runid = itab1-runid.
 if sy-subrc NE 0.
  delete itab1 index tabix.
 endif.
endloop.
Thanks Venkat.O