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
586

Hello friends,

I have 2 internal tables. IT1_knvp and IT2_knvp.

IT1_knvp contains some data which already exists in it2_KNVP. so i want to delete it1_knvp based on it2_knvp kunn2.

Below is the code i am using but it does not work.

LOOP AT it2_knvp.

LOOP AT it1_knvp.

DELETE it1_knvp

where kunn2 = it2_knvp.

ENDLOOP.

ENDLOOP.

Shejal.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
564

It appears that you forgot the KUNN2 field in your DELETE statement and you don't need the LOOP at IT1_KNVP

LOOP AT it2_knvp.

    DELETE it1_knvp
         where kunn2 = <b>it2_knvp-kunn2.</b>

ENDLOOP.

REgards,

Rich Heilman

5 REPLIES 5
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
565

It appears that you forgot the KUNN2 field in your DELETE statement and you don't need the LOOP at IT1_KNVP

LOOP AT it2_knvp.

    DELETE it1_knvp
         where kunn2 = <b>it2_knvp-kunn2.</b>

ENDLOOP.

REgards,

Rich Heilman

Read only

ferry_lianto
Active Contributor
0 Likes
564

Hi,

Please try this.

LOOP AT it2_knvp.

DELETE it1_knvp

where kunn2 = it2_knvp-kunn2.

ENDLOOP.

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
564

Hi Shejal,

DELETE statement will delete all records which satifies that condition. So need of LOOP..ENDLOOP on IT1_KNVP.

Try with this code.

LOOP AT it2_knvp.

DELETE it1_knvp

where kunn2 = <b>it2_knvp-kunn2</b>.

ENDLOOP.

For better Performance,

SORT IT2_KNVP BY KUNN2.

LOOP AT it2_knvp.

<b>AT NEW KUNN2.</b>

DELETE it1_knvp

where kunn2 = <b>it2_knvp-kunn2</b>.

<b>ENDAT.</b>

ENDLOOP.

Thanks,

Vinay

Read only

Former Member
0 Likes
564

Hi,

Try this..

LOOP AT IT2_KNVP.

DELETE IT1_KNVP WHERE KUNN2 = IT2_KNVP-KUNN2.

ENDLOOP.

Thanks,

Naren

Read only

Former Member
0 Likes
564

Assuming there are no more than 1 entry to be deleted from it1_knvp for an entry in it2_knvp, try:


SORT it1_knvp BY kunn2,
     it2_knvp by kunn2.

LOOP AT it2_knvp.
  READ TABLE it1-knvp1 WITH KEY
    kunn2 = it2_knvp-kunn2
    BINARY SEARCH.
  IF sy-subrc = 0.
    DELETE it1_knvp INDEX sy-tabix.
  ENDIF.
ENDLOOP

Rob