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 records from one table comparing other table

Former Member
0 Likes
1,595

hi,

I need to delete records from internal table comparing other internal table records.

if both the record matches then need to delete the record.

SELECT *

FROM kotg004

INTO TABLE lt_exclusio

WHERE kappl = 'V'

AND kschl = 'ZB01'

AND vkorg = p_vkorg

AND vtweg = p_vtweg

AND kunnr = p_kunnr

AND datbi >= p_fkdat

AND datab <= p_fkdat.

SELECT *

FROM kotg001

INTO TABLE lt_ kotg001

WHERE kappl = 'V'

AND kschl = 'ZB01'

AND kunnr = p_kunnr.

whatver records are fechthed in lt_ kotg001 if that records exist in lt_exclusio table then those records shd be deleted.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,122

HI,

U cud use the below :

SELECT *

FROM kotg001

INTO TABLE lt_ kotg001

WHERE kappl = 'V'

AND kschl = 'ZB01'

AND kunnr = p_kunnr.

if it_kotg001[] is not initial.

SELECT *

FROM kotg004

INTO TABLE lt_exclusio for all entries in it_kotg001

WHERE kappl ne it_kotg001-kappl

AND kschl ne it_kotg001-kschl

AND vkorg = p_vkorg

AND vtweg = p_vtweg

and matnr ne ne it_kotg001-matnr

AND kunnr ne it_kotg001-kunnr

AND datbi >= p_fkdat

AND datab <= p_fkdat.

endif.

let us know if the above works for you!

hi,

I need to delete records from internal table comparing other internal table records.

if both the record matches then need to delete the record.

SELECT *

FROM kotg004

INTO TABLE lt_exclusio

WHERE kappl = 'V'

AND kschl = 'ZB01'

AND vkorg = p_vkorg

AND vtweg = p_vtweg

AND kunnr = p_kunnr

AND datbi >= p_fkdat

AND datab <= p_fkdat.

SELECT *

FROM kotg001

INTO TABLE lt_ kotg001

WHERE kappl = 'V'

AND kschl = 'ZB01'

AND kunnr = p_kunnr.

whatver records are fechthed in lt_ kotg001 if that records exist in lt_exclusio table then those records shd be deleted.

5 REPLIES 5
Read only

Former Member
0 Likes
1,122

hi,

{SELECT *

FROM kotg004

INTO TABLE lt_exclusio

WHERE kappl = 'V'

AND kschl = 'ZB01'

AND vkorg = p_vkorg

AND vtweg = p_vtweg

AND kunnr = p_kunnr

AND datbi >= p_fkdat

AND datab <= p_fkdat.

SELECT *

FROM kotg001

INTO TABLE lt_ kotg001

WHERE kappl = 'V'

AND kschl = 'ZB01'

AND kunnr = p_kunnr.

whatver records are fechthed in lt_ kotg001 if that records exist in lt_exclusio table then those records shd be deleted.}

from which table you want to delete the records.

if you want to delete the records form table it_exclusio, then

loop at it_kotg001 into wa.

read table it_exclusio with key KAPPL = wa-KAPPL

KSCHL = wa-KSCHL

KUNNR = wa-KUNNr

MATNR =wa-MATNR

DATBI = wa-DATB

DATAB = wa-DATAB.

if sy-subrc = 0.

delete it_exclusio where kappl = wa-kappl.

endif.

endloop.I

Read only

Former Member
0 Likes
1,122

HI

If your kappl and kschl is primary key then there should be only one record for those fields.

then you can write:

delete adjacent duplicates from it_kotg001 where kappl = it_exclusio-kappl and kschl = it_exclusio-lschl.

try it.

hope this will work for you

Thanks

Lalit Gupta

Read only

Former Member
0 Likes
1,122

HI,

You can use FOR ALL ENTRIES in select query instead of selecting and deleting it.

Chk this out.

SELECT *

FROM kotg001

INTO TABLE lt_ kotg001

WHERE kappl = 'V'

AND kschl = 'ZB01'

AND kunnr = p_kunnr.

if it_kotg001[] is not initial.

SELECT *

FROM kotg004

INTO TABLE lt_exclusio for all entries in it_kotg001

WHERE kappl = it_lotg001-kappl

AND kschl = 'ZB01'

AND vkorg = p_vkorg

AND vtweg = p_vtweg

AND kunnr = p_kunnr

AND datbi >= p_fkdat

AND datab <= p_fkdat.

endif.

Hope it helps you.

Regards,

K.Tharani.

Read only

Former Member
0 Likes
1,123

HI,

U cud use the below :

SELECT *

FROM kotg001

INTO TABLE lt_ kotg001

WHERE kappl = 'V'

AND kschl = 'ZB01'

AND kunnr = p_kunnr.

if it_kotg001[] is not initial.

SELECT *

FROM kotg004

INTO TABLE lt_exclusio for all entries in it_kotg001

WHERE kappl ne it_kotg001-kappl

AND kschl ne it_kotg001-kschl

AND vkorg = p_vkorg

AND vtweg = p_vtweg

and matnr ne ne it_kotg001-matnr

AND kunnr ne it_kotg001-kunnr

AND datbi >= p_fkdat

AND datab <= p_fkdat.

endif.

let us know if the above works for you!

Read only

MilindMungaji
Participant
0 Likes
1,122

loop at lt_exclusio into wa_exclusio.

loop at it_kotg001 into wa_kotg001 where KUNNR = wa_exclusio-kunnr

and MATNR = wa_exclusio-matnr

and DATBI = wa_exclusio-datbi

and DATAB = wa_exclusio-datab.

delete it_kotg001 index sy-tabix.

endloop.

endloop.