Application Development 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: 

Comparing Internal Tables

former_member188326
Active Participant
0 Kudos

Hi All,

I had 2 internal tables with HR data.

One containing old data and one containing both old as well as new data.

I want to delete old data form new table by comparing the data with the internal table containing old data.

How can i do it?

Regards,

Bharat Mistry

10 REPLIES 10

rahulkavuri
Active Contributor
0 Kudos

According to ur problem loop around the new table and read the second table ( new one )... when ever sy-subrc = 0... u can delete the particular record

loop at newtable.

read table old where pmkey = pmkey2.
      
IF SY-SUBRC = 0.

delete newtable.

ENDIF.

endloop.

<b>award points if found helpful</b>

Former Member
0 Kudos

Bharat,

How are you selecting data into internal table?

Cheers,

Nilesh

former_member181962
Active Contributor
0 Kudos

loop at itab_old.

DELETE TABLE itab WITH TABLE KEY k1 = itab_old-k1 ... kn = itab_old-kn.

endloop.

Regards,

Ravi

Former Member
0 Kudos

hi

loop at itab1.

delete table itba2 from itab1.

endloop.

this helps

plz reward helpful answers

Former Member
0 Kudos

Hi Bharat,

refer to the link..

<a href="http://help.sap.com/saphelp_erp2005/helpdata/en/fc/eb3653358411d1829f0000e829fbfe/frameset.htm">Comparing Internal Tables</a>

if the structure of itab_new and itab_old is same.

Code sample:

loop at itab_new.

read itab_old from itab_new.

if sy-subrc ne 0.

delete itab_new from itab_old.

endif.

endloop.

Hope it helps..

Lokesh

pls. reward appropriate points

Former Member
0 Kudos

itab1-new

itab2-old

itab3-final.

loop at itab1.

read table itab2 with key = itab1-key.

if itab1 <> itab2 .

itab3 = itab1.

append itab3.

endloop.

Former Member
0 Kudos
one way is like this

 loop at it_old into wa_old.

       read table it_new into wa_new with key fld1 = wa_old-fld2 ....
        if sy-subrc = 0.

            delete it_new from wa_new.
        endif.
 endloop.

hymavathi_oruganti
Active Contributor
0 Kudos

loop at old_tab.

read table new_tab with key (key field) = (key field of old_tab).

if sy-subrc = 0.

delete new_tab.

endif.

endloop.

Former Member
0 Kudos

HI,

U CAN DO LIKE THIS

LOOP AT ITAB_NEW.

READ TABLE ITAB_OLD WITH KEY FIELD1 = ITAB_NEW-FIELD1.....

IF SY-SUBRC = 0.

DELETE FROM ITAB_NEW.

ENDIF.

HOPE THIS HELPS,

PRIYA.

Former Member
0 Kudos

Hai Bharst

Do the following way

data : begin of it_mara occurs 0,

matnr like mara-matnr,

mbrsh like mara-mbrsh,

mtart like mara-mtart,

meins like mara-meins,

end of it_mara.

data : begin of it_makt occurs 0,

matnr like makt-matnr,

maktx like makt-maktx,

end of it_makt.

select matnr

mbrsh

mtart

meins

from mara into table it_mara.

if sy-subrc = 0.

sort it_mara by matnr.

endif.

if not it_mara[] is initial.

select matnr

maktx

from makt into it_makt

for all entries in it_mara

where matnr = it_mara-matnr.

endif.

loop at it_mara.

read table it_makt with key matnr = it_mara-matnr binary search.

if sy-subrc = 0.

delete from it_mara with sy-index.

endif.

endloop.

Thanks & Regards

Sreenivasulu P

Message was edited by: Sreenivasulu Ponnadi