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

Manipulating Internal tables

Former Member
0 Likes
993

Hi,

I Have two internal tables with Objnr as the common field in that. Not i need to delete the records from the first internal table where the OBJNR of the second internal table is not in the first internal table. Pls let me know how to do this.

Regards,

Ramesh.

9 REPLIES 9
Read only

Former Member
0 Likes
936

loop at itab2.

read table itab1 where objnr = itab2-objnr.

if sy-subrc <> 0.

delete itab1 index sy-tabix.

endif.

endloop.

Read only

Former Member
0 Likes
936

Hi,

Please try this.


loop at itab1.
 read table itab2 with key objnr = itab1-objnr.
 if sy-subrc <> 0.
   delete itab1.
 else.
   continue. 
 endif.
endloop.

Regards,

Ferry Lianto

Read only

0 Likes
936

Hi,

Unable to delete the records from the first table with the logic given.

For example i have around 200 records in the first internal table. And in my second internal table i have 30 records. These 30 records are available in my first internal table also. Now i need to delete the remaining 170 records from the first internal table. The common field in these table is OBJNR. Based on this i need to delete the records.

Regards,

Ramesh

Read only

0 Likes
936

Hi..try this..

data:

w_index type i.

loop at itab1 into fs_itab1.

w_index = sy-tabix.

read table itab2 with key objnr = fs_itab1-objnr into fs_itab2.

if sy-subrc eq 0.

delete itab1 index w_index.

endif.

endloop.

reward...if it helpss u...

-Rammohan

Read only

0 Likes
936

Hi ram,

check this code.this will solve ur problem with out adding extra field.

data:itab1 like mara occurs 0 with header line.

data:itab2 like mara occurs 0 with header line.

select * from mara into table itab1.

select * from mara into table itab2 up to 2 rows.

loop at itab1.

write:/ itab1-matnr.

endloop.

skip 2.

loop at itab2.

write:/ itab2-matnr.

endloop.

skip 2.

loop at itab1.

read table itab2 with key matnr = itab1-matnr.

if sy-subrc <> 0.

delete itab1 where matnr = itab1-matnr.

endif.

endloop.

loop at itab1.

write:/ itab1-matnr.

endloop.

reward if helpful.

Read only

0 Likes
936

Hi,

Try this code.

*&---------------------------------------------------------------------*
  DATA: l_index LIKE sy-tabix.

  SORT: itab1 BY objnr,
        itab2 BY objnr.

  LOOP AT itab1.
    l_index = sy-tabix.
    READ TABLE itab2 WITH KEY objnr = itab1-objnr.
    IF sy-subrc <> 0.
      DELETE itabl INDEX i_index.
    ENDIF.
  ENDLOOP.
*&---------------------------------------------------------------------*

Let me know if you need any other information.

Regards,

RS

Read only

0 Likes
936

Hi RamMohan,

SORT ITAB1 BY OBJNR.

SORT ITAB2 BY OBJNR.

LOOP AT ITAB2 INTO WA_ITAB1.

READ TABLE ITAB1 WITH KEY OBJNR = WA_ITAB1-OBJNR.

IF SY-SUBRC = 0.

LV_INDEX = SY-TABIX.

DELETE ITAB1 INDEX LV_INDEX.

ENDIF.

ENDLOOP.

Thanks,

Vinay

Read only

Former Member
0 Likes
936

Hi,

loop at itab1.

delete itab2 where table key objjr = itab1-objjr.

endloop.

regards,

bharat.

Read only

Former Member
0 Likes
936

Hi..

Try this code.

Loop at itab2.

read table itab1 with key objnr = itab2-objnr.

if sy-subrc EQ 0.

Append itab1 to itab3.

endif.

endloop.

U may process the itab3 now..

Regards

Bala.