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 Statement

Former Member
0 Likes
906

Hello friends,

I want to delete some rows from an internal table based on a where condition depending on another internal table.

DELETE it_knvp

FOR ALL ENTRIES IN it_vbpa

WHERE kunnr = it_vbpa-kunnr.

In the above code both the internal tables have kunnr.

But the above code is not correct.

Any advice.

Shejal Shetty.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
870

then use RANGES.

RANGES : R_KUNNR FOR KNA1-KUNNR.

R_KUNNR-SIGN = 'I'.

R_KUNNR-OPTION = 'EQ'.

LOOP AT it_vbpa.

R_KUNNR-LOW = it_vbpa-KUNNR.

APPEND R_KUNNR.

ENDLOOP.

IF you want to delete IT_KNVP records based on IT_VBPA,

1. if record exists in IT_VBPA then if you want to delete IT_KNVP also,then do

<b>DELETE IT_KNVP WHERE KUNNR IN R_KUNNR.</b>

2. IF you want to delete entries from IT_KNVP where KUNNR not in IT_VBPA,then

<b> DELETE IT_VBPA WHERE KUNNR <u>NOT</u> IN R_KUNNR.</b>

regards

srikanth

Message was edited by: Srikanth Kidambi

8 REPLIES 8
Read only

anversha_s
Active Contributor
0 Likes
870

hi

chk this code.

*it_knvp should be occurs 0 with header line

loop at it_knvp.

read table it_vbpa with key kunnr = it_knvp-kunnr.

if sy-subrc = 0 .

DELETE TABLE it_knvp FROM it_knvp.

endif.

endloop.

rgds

anver

if helped pls mark points

Read only

0 Likes
870

Thanks Anversha,

I am looking for a way to do it without using the loop statement.

Thanks again,

Shejal.

Read only

0 Likes
870

hi shejal,

for all entries is not possible in DELETE syntax.

thats y i went for loop.

since it is an internal table, there will not be nay performance issue.

rgds

anver

Read only

Former Member
0 Likes
870

Hi Shejal,

Try this:

loop at it_vbpa.

delete it_knvp where kunnr = it_vbpa-kunnr.

endloop.

Regards,

Vivek

Read only

Former Member
0 Likes
870

hi,

do this way ..

loop at it_vbpa.

read table it_vbpa  where< Conditions>

if sy-subrc = 0.

delete it_vbpa

endif
endloop.

Read only

Former Member
0 Likes
871

then use RANGES.

RANGES : R_KUNNR FOR KNA1-KUNNR.

R_KUNNR-SIGN = 'I'.

R_KUNNR-OPTION = 'EQ'.

LOOP AT it_vbpa.

R_KUNNR-LOW = it_vbpa-KUNNR.

APPEND R_KUNNR.

ENDLOOP.

IF you want to delete IT_KNVP records based on IT_VBPA,

1. if record exists in IT_VBPA then if you want to delete IT_KNVP also,then do

<b>DELETE IT_KNVP WHERE KUNNR IN R_KUNNR.</b>

2. IF you want to delete entries from IT_KNVP where KUNNR not in IT_VBPA,then

<b> DELETE IT_VBPA WHERE KUNNR <u>NOT</u> IN R_KUNNR.</b>

regards

srikanth

Message was edited by: Srikanth Kidambi

Read only

Former Member
0 Likes
870

i dont know the way to work in delete

with "FOR ALL ENTRIES "

i work like this

loop at [first internal table]

read [second table] with key if kunner = kunner

if sy-subrc = 0 .

delete second table index sy-tabix

endif.

endloop

Read only

0 Likes
870

Thanks Everyone for all the advice and suggestions.

Shejal Shetty.