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

how to delete data from internal table based on condition

Former Member
0 Likes
73,749

Hi experts,

I hve data in one internal table but i want to delete some data from that based on condition like when the condition satisfies i hve to make flag field as 1 and after checking for all records i hve to delete records mark as 1.

Plz tell me the procedure how to do that.

Thanks in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
26,354

hi,

check this code.

if <cond>
wa-flag = 1.
modify table itab from wa transaporting flag.
endif.

delete itab where flag = 1. "deletes multiple records in the table satisfying the condition

Thanks

Sharath

Hi experts,

I hve data in one internal table but i want to delete some data from that based on condition like when the condition satisfies i hve to make flag field as 1 and after checking for all records i hve to delete records mark as 1.

Plz tell me the procedure how to do that.

Thanks in advance.

11 REPLIES 11
Read only

former_member195383
Active Contributor
0 Likes
26,354

suppose you have the table itab[] .

use the below.

delete itab where field1 = '1' .

this will delete all the rows in which field1 has the value1 .

This is one of the basic concepts. U can click on DELETE and press F1.

That you have to try before posting a question

Read only

Former Member
0 Likes
26,354

Hi,

U can use like this,

DELETE ITAB where (Ur conditions).

It'll delete the records based on the conditions. No nedd to set flag and then delete.Just use only one statement.

Press F1 on DELETE, U'll get Lot of inputs.

Read only

Former Member
0 Likes
26,354

Hi,

If <condition>

fs-flag = 1.

endif.

delete itab where flag = 1.

Read only

0 Likes
26,354

Thanks a lot for your answer,but while setting flag i am loop on internal table like

loop at wt_itab into wa_itab.

if(condition)

ws_itab-flag = 'x'.

endif.

endloop.

now i hve to make flag = x in table like here i am making field of workarea as x.

can u plz tell me how to do that.

Thanks

Read only

0 Likes
26,354

Hi,

Then u can use modify

modify table itab from fs transporting flag.

Read only

0 Likes
26,354

hi,

Once the flag value is set, use modify statement for that to be reflected in your table.

This code will solve your purpose.

loop at wt_itab into wa_itab.
if(condition)

wa_itab-flag = 'x'.
MODIFY TABLE wt_itab FROM wa_itab TRANSPORTING FLAG.
endif.

endloop.

This statement changes the value of flag for that particular record in the loop.

Thanks

Sharath

Read only

Former Member
0 Likes
26,354

PARAMETERS p_carrid TYPE scarr-carrid.

DATA scarr_tab TYPE SORTED TABLE OF scarr

WITH UNIQUE KEY carrid.

SELECT *

FROM scarr

INTO TABLE scarr_tab.

DELETE TABLE scarr_tab WITH TABLE KEY carrid = p_carrid.

Read only

Former Member
0 Likes
26,354

Hello,

refer the given below code



DELETE FROM it_t352r WHERE revnr = v_t352r-revnr.

Thanks

Arun

Read only

Former Member
0 Likes
26,355

hi,

check this code.

if <cond>
wa-flag = 1.
modify table itab from wa transaporting flag.
endif.

delete itab where flag = 1. "deletes multiple records in the table satisfying the condition

Thanks

Sharath

Read only

Former Member
0 Likes
26,354

Thanks a lot for your response.

Read only

Former Member
0 Likes
26,354

Let say your internal table is defined as follows:

data : begin of it_tab occurs 0,

field1 type c,

field1 type c,

flag type c, " field for flag

end of it_tab.

loop at it_tab.

****when condition meets

it_tab-flag = 'X' .

modify it_tab transporting flag.

endloop.

delete it_tab where flag eq 'X'.