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 records in internal table

Former Member
0 Likes
1,058

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
Read only

venkat_o
Active Contributor
0 Likes
1,013

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

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

8 REPLIES 8
Read only

Former Member
0 Likes
1,013
loop at itab1 into is1.
 read table itab2 into is2 with key runid = is1-runid.
 if sy-subrc NE 0.
  delete itab1.
 endif.
endloop.
Read only

Former Member
0 Likes
1,013

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

Read only

0 Likes
1,013

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

Read only

0 Likes
1,013

deleted

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

Read only

0 Likes
1,013

Yes. I got it.

Thanks

VG

Read only

venkat_o
Active Contributor
0 Likes
1,014

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

Read only

Former Member
0 Likes
1,013

>

> 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.

Read only

venkat_o
Active Contributor
0 Likes
1,013

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