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: 

internal table

Former Member
0 Kudos

how to delete a perticular record from internal table based on the record exits in an another internal table .

1 ACCEPTED SOLUTION

Former Member
0 Kudos

use delete statement for deleting the records...

e.g. loop at itab1 into wa-itab1.

read table itab2 with key fld1 = wa_itab1-fld1.

if sy-subrc eq 0.

delete table itab1 from wa_itab1.

endif.

endloop.

Message was edited by:

sharayu kumatkar

8 REPLIES 8

Former Member
0 Kudos

use delete statement for deleting the records...

e.g. loop at itab1 into wa-itab1.

read table itab2 with key fld1 = wa_itab1-fld1.

if sy-subrc eq 0.

delete table itab1 from wa_itab1.

endif.

endloop.

Message was edited by:

sharayu kumatkar

Former Member
0 Kudos

do you want to read an internal table 1 depending on a variable of an internal table 2, say

loop at itab1 into wa_tab1,

read itab2 into wa_tab2 with key = wa_tab1-field.

if sy-subrc <> 0.

delete wa_tab1 from itab1.

endif.

endloop.

basically a delete statement would do.

Former Member
0 Kudos

Hi,

TYPES: BEGIN OF NAMETAB_TYPE,

NAME(30) TYPE C,

END OF NAMETAB_TYPE.

DATA: NAMETAB TYPE STANDARD TABLE OF NAMETAB_TYPE WITH

NON-UNIQUE DEFAULT KEY INITIAL SIZE 100.

...

DELETE NAMETAB FROM 5 TO 36 WHERE NAME eq 'ABC'.

Here abc is value of another internal table.

Assign points if useful.

Former Member
0 Kudos

Hi,

ABAP Coding:


DATA:
  lt_table_1 TYPE TABLE OF xxx WITH HEADER LINE,
  lt_table_2 TYPE TABLE OF xxx,
  l_idx         TYPE i.

LOOP AT lt_table_1.
  l_idx = sy-tabix.

  READ TABLE lt_table_2 WITH KEY ... TRANSPORTING NO FIELDS.
  IF sy-subrc EQ 0.
*   Entry exists in lt_table_2
    DELETE lt_table_1 INDEX l_idx.
  ENDIF.
ENDLOOP.

Regards, Joerg

varma_narayana
Active Contributor
0 Kudos

Hi..

This is the Sample code.

Loop at Itab1 .

Delete ITAB2 where Field1 = Itab1-field1.

Endloop.

REWARD IF HELPFUL.

Former Member
0 Kudos

1. Create a range.


DATA: r_field TYPE RANGE OF table-field.

2. Loop on the reference table and save the value to the range you created.


loop at table.
  r_field-sign   = 'I'. 
  r_field-option = 'EQ'. 
  r_field-low    = table-field. 
  APPEND r_field.
  CLEAR r_field.
endloop.

3. Delete the value in your table existing in the range you created.


   Delete itab where field in r_field.

You can also do a loop in the reference table and deleting every record in every iteration but the first one that i gave you is much more faster because you don't need to read the table inside the loop which is a factor when you're dealing with large amount of records.

Former Member
0 Kudos

don loop and delet from same table.. instead do like this.

loop at itab2.

read table itab1 with key itab1-value = itab2-value.

if sy-subrc EQ 0.

delete itab1.

endif.

endloop

Former Member
0 Kudos

Hi,

you can write logic for deleting records from the ITAB comparing ITAB1.

Put a Loop on ITAB.

then read table ITAB1....and compare.

then Delete ITAB on success of the read statement.

then Modify ITAB.

Endloop.

Best Regards,

Bhawani