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

DELETE syntax

Former Member
0 Likes
2,952

Hi Experts,

I have two internal tables.

The first internal table contains sales doc and invoice no.

the second internal table contains invoice no.

Do we have a delete statement that will delete the entries in first table where the invoice number is not present in second internal table?

Thanks in advance!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,275

Hi,

Loop at first internal table. Inside loop .. endloop read second table with invoice number of current loop pass. If read statement fails delete the record from first table.

EX:-

Loop at itab1.

read table itab2 with key invoice nO = itab1-invoice no.

if sy-subrc ne 0.

delete itab1.

endif.

endloop.

Regards,

Sankar

5 REPLIES 5
Read only

Former Member
0 Likes
1,276

Hi,

Loop at first internal table. Inside loop .. endloop read second table with invoice number of current loop pass. If read statement fails delete the record from first table.

EX:-

Loop at itab1.

read table itab2 with key invoice nO = itab1-invoice no.

if sy-subrc ne 0.

delete itab1.

endif.

endloop.

Regards,

Sankar

Read only

Former Member
0 Likes
1,275

Code like this.

The first internal table(itab1) contains sales doc and invoice no.

the second internal table(itab2) contains invoice no.

Loop at itab1.

read table itab2 with key invoice = itab1-invoice.

if sy-subrc = 0.

delete itab1.

endif.

endloop.

Read only

Former Member
0 Likes
1,275

hi,

chk this.

<u>Logic</u>

itab1

itab2

itab3.

2.

loop at itab2 into wa2.

read table itab1 with key itab2-key.

if sy-subrc NE 0.

append wa2 to itab3.

clear wa2.

endif.

endloop.

3.

Delete itab1 from itab3.

Regards

Reshma

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
1,275

HI,

LOOP AT itab1.

READ TABLE itab2 WITH KEY invoice_no = itab1-invoice_no TRANSPORTING NO FIELDS.

if sy-subrc <> 0.

DELETE itab1.

endif.

ENDLOOP.

Regards,

Sesh

Read only

Former Member
0 Likes
1,275

Hi

DELETE ADJACENT DUPLICATES FROM itab.

Sample code

SELECT ESLL~PACKNO ESLL~SUB_PACKNO ESLL~SRVPOS ESLL~KTEXT1
          FROM ESLL        
  INTO CORRESPONDING FIELDS OF TABLE ITAB6
         WHERE ESLL~PACKNO = ITAB1-PACKNO.

delete adjacent duplicates from itab1 comparing EBELN .

Extras:

1. ... COMPARING f1 f2 ...

2. ... COMPARING ALL FIELDS

<b>

Effect</b>

Deletes adjacent duplicate entries from the internal table itab. If there are n duplicate entries in succession, the first entry is retained, and the following n-1 entries are deleted.

Two lines are regarded as duplicates if their keys are identical.

<b>The Return Code is set as follows:</b>

SY-SUBRC = 0:

At least one duplicate was found, and at least one entry was deleted.

SY-SUBRC = 4:

No duplicates found, no entries deleted.

Addition 1

... COMPARING f1 f2 ...

Effect

Two lines of the internal table itab are regarded as duplicates if they have identical contents in the fields f1, f2, ...

Addition 2

... COMPARING ALL FIELDS

Effect

Two lines of the internal table are regarded as duplicates if all of their field contents are identical.

<b><u>Notes</u></b>

The DELETE ADJACENT DUPLICATES statement works particularly well if you have sorted the internal table itab according to the fields that you want to compare when looking for duplicates. In this case, deleting adjacent duplicates is the same as deleting all duplicates. The direction of the sort is irrelevant.

If you do not know a comparison expression until runtime, you can specify it dynamically as the contents of the field name in the expression COMPARING ... (name) .... If name is empty at runtime, the comparison expression is ignored. If name contains an invalid component name, a runtime error occurs.

You can further restrict comparison expressions - both static and dynamic - by specifying offset and length.

<b><u>

Note

Performance:</u></b>

When you delete a line of an internal table, index maintenance costs are incurred. These depend on the index of the table. The runtime is independent of the width of the table line.

Deleting a line from the middle of an internal table with 200 entries usually requires around 10 msn (standardized microseconds).

When you delete a set of entries using "DELETE itab FROM idx1 TO idx2." or "DELETE itab WHERE ...", index maintenance costs are only incurred once. This means that it is considerably more efficient than deleting entries in a LOOP.

If you want to delete adjacent duplicate entries from an internal table, use the variant " DELETE ADJACENT DUPLICATES FROM itab." instead of a LOOP construction.

Reward all helpfull answers

Regards

Pavan