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 Itab within Loop at ITAB ?

Former Member
0 Likes
5,013

Hi,

Help needed to remove this delete from within the loop.

{code

Loop at itab where <condition>.

<statements>

delete itab index sy-tabix.

Exit.

Endloop.

{code}

The functionality of the code should not be affected.

Useful help would be awarded

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,128

hi,

do this way ... take a new field(Flag) in the itab ...


Loop at itab where <condition>.
 lv_tabix = sy-tabix. 
<statements>
 if <conditions> 
  itab-flag = 'X'.
  modify itab index lv_tabix transporting flag.
  Exit.
 endif. 
Endloop.

delete itab where flag = 'X'. 

6 REPLIES 6
Read only

Former Member
0 Likes
2,129

hi,

do this way ... take a new field(Flag) in the itab ...


Loop at itab where <condition>.
 lv_tabix = sy-tabix. 
<statements>
 if <conditions> 
  itab-flag = 'X'.
  modify itab index lv_tabix transporting flag.
  Exit.
 endif. 
Endloop.

delete itab where flag = 'X'. 

Read only

Sm1tje
Active Contributor
0 Likes
2,128

I don't know what <statements> you are using, but the easiest way to do this, is this:

delete itab where <conditions>.

Read only

peter_ruiz2
Active Contributor
0 Likes
2,128

hi akshay,

use this

 DELETE itab WHERE <condition>

regards,

Peter

Read only

Former Member
0 Likes
2,128

Hi,

Never delete an internal table inside the same loop.

Rather add a flag field in the table.

In the loop at itab..mark the field = 'X 'where u want to delete.

and at the end of loop,

DELETE ITAB WHERE FLAG = 'X'

Please assign points if helpful

Read only

Former Member
0 Likes
2,128

Delete inside loop is not required.

You can use directly the statement

DELETE itab WHERE logexp.

or

DELETE TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn.

Read only

Former Member
0 Likes
2,128

Hi,

Instead of deleting data from itab use another internal table of same type (itab1) and append it. Use itab1 data for further processing.

check below logic...

{code

Loop at itab1 into wa_itab1 where <condition>.

<statements>

if <condition>

append wa_itab1 to itab2.

exit.

endif.

Endloop.

refresh itab1.

itab1[] = itab2[].

{code}

regards,

N M Poojari.