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

Comparing Internal Tables

Former Member
0 Likes
1,020

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
Read only

rahulkavuri
Active Contributor
0 Likes
836

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>

Read only

Former Member
0 Likes
836

Bharat,

How are you selecting data into internal table?

Cheers,

Nilesh

Read only

Former Member
0 Likes
836

loop at itab_old.

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

endloop.

Regards,

Ravi

Read only

Former Member
0 Likes
836

hi

loop at itab1.

delete table itba2 from itab1.

endloop.

this helps

plz reward helpful answers

Read only

Former Member
0 Likes
836

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

Read only

Former Member
0 Likes
836

itab1-new

itab2-old

itab3-final.

loop at itab1.

read table itab2 with key = itab1-key.

if itab1 <> itab2 .

itab3 = itab1.

append itab3.

endloop.

Read only

Former Member
0 Likes
836
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.
Read only

hymavathi_oruganti
Active Contributor
0 Likes
836

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.

Read only

Former Member
0 Likes
836

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.

Read only

Former Member
0 Likes
836

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