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 a internal table

Former Member
0 Kudos

I Have an ALV in which I have selected several lines to delete (icon "-").

The method get_selected_rows returns the index of the selected lines.

In a loop I try to delete the lines of the internal table by the index. But I have a problem because when I delete a line, the index number is updated, therefore the second record that I try to delete doesn´t work because the index has changed.

does there exist the possibility that the index is not updated?

Thanks

1 ACCEPTED SOLUTION

messier31
Active Contributor
0 Kudos

Hi,

1. Create a additional field in your table called say flag.

2. First loop at your internal table and set this flag for all entires which you have selected on ALV and modify your itab.

3. Then delete all entries for which this flag is set.

Hope this helps.

Enjoy SAP.

Pankaj Singh.

4 REPLIES 4

Former Member
0 Kudos

hi

try to delete like this

loop at itab

delete itab

endloop

it deletes all the records in the internal table

outside of the loop

delete itab index 2 -


> it deletes the record of index 2

put it into the while or do while

i =1.

while i < 5

i = i+ 1.

delete itab index i.

endwhile.

it deletes 5 records in the internal table

Former Member
0 Kudos

hi

try to delete like this

loop at itab

delete itab

endloop

it deletes all the records in the internal table

outside of the loop

delete itab index 2 -


> it deletes the record of index 2

put it into the while or do while

i =1.

while i < 5

i = i+ 1.

delete itab index i.

endwhile.

it deletes records in the internal table

messier31
Active Contributor
0 Kudos

Hi,

1. Create a additional field in your table called say flag.

2. First loop at your internal table and set this flag for all entires which you have selected on ALV and modify your itab.

3. Then delete all entries for which this flag is set.

Hope this helps.

Enjoy SAP.

Pankaj Singh.

Former Member
0 Kudos

hi Óscar

If your problem is the "updated of index"

try to use Select later the "delete";

Select * into table index 1.

Regards

Allan Cristian