2010 Jul 23 11:51 AM
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.
2010 Jul 23 1:36 PM
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.
2010 Jul 23 12:01 PM
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
2010 Jul 23 12:04 PM
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
2010 Jul 23 12:37 PM
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.
2010 Jul 23 1:36 PM
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!
2010 Jul 23 2:11 PM
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.