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: 

Using delete and FOR ALL ENTRIES

Former Member
0 Kudos

Hi,

We have a error message regarding the following code :

Delete FROM TABLE FOR ALL ENTRIES IN lt_TABLE WHERE
TABLE_KEY1  = LT_TABLE_KEY1

Could we use the For All entries with "Select" ?

For information, the error message is "Unable to interpret "FOR". Possible causes: Incorrect spelling or comma error.

Thank you.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

You can not delete from database table like this.

Use a loop on internal table and delete inside comparing values in where clause.

Regds,

Anil

15 REPLIES 15

Former Member
0 Kudos

Hi monsdn,

we can use for all entries with select statement.

if i_tab is not initial.

select f1 f2

from mara

into table i_tab1

for all entries in i_tab

where f1 = i_tab-f1.

for delete statement,use like....

delete i_tab where f1 not in i_tab1.

or,

delete i_tab where f1 not in so_matnr(select-options).

Hope this can solve your problems.

Regards,

Tutun

Former Member
0 Kudos

Hi,

You can not delete from database table like this.

Use a loop on internal table and delete inside comparing values in where clause.

Regds,

Anil

0 Kudos

Thank you Anil,

Could you give me the syntaxe please basing on my example, because I m beginner on ABAP program.

Delete FROM TABLE FOR ALL ENTRIES IN lt_TABLE WHERE
TABLE_KEY1  = LT_TABLE_KEY1

Thx.

Edited by: monsdn on Jul 31, 2009 11:04 AM

0 Kudos

HI,

In order to delete data base table entries the structure of db table and ur table should be same.

Get all the records in the internal table and then use this command.

delete <database table> from table itab.

if sy-subrc eq 0.

commit work.

endif.

Regards,

Nagaraj

0 Kudos

Hi,

You can try this


loop at lt_table.
Delete TABLE where TABLE-KEY1  = LT_TABLE-KEY1.
endloop.

Regards,

Vik

0 Kudos

Delete TABLE lt_TABLE WHERE

TABLE_KEY1 = LT_TABLE_KEY1

write delete and press f1 and see the syntax

Thanks

Bala Duvvuri

0 Kudos

Hi,

Check the below syntax, if you want to delete from database

DELETE FROM sflight 
WHERE  carrid = p_carrid AND 
       fldate = sy-datum AND 
       seatsocc = 0.

Just a suggestion. May be from next time you can use F1 help for syntax:

1. Place the cursor on the delete keword in your program and press F1 - You willl get all the possible syntax for delete statement

2. Else open the transaction ABAPDOCU, Click Keyword Help, Enter the required keyword(delete in this case) and press cont.. You will get the syntax.

Hope thsi will help you.

Regards,

Swarna Munukoti.

0 Kudos

Hi,

tables : ztarget.

data : begin of itab occurs 0.

include structure ztarget.

data : end of itab.

select * into table itab from ztarget.

loop at itab.

delete from ztarget where kunnr = itab-kunnr.

endloop.

Regds,

Anil

Edited by: Anil Katoch on Jul 31, 2009 11:29 AM

0 Kudos

Hi,

It works,

Thank you.

0 Kudos

please flag "solved" to the people who gave the correct solution, so that people who will have the same question later, will get directly the answer.

0 Kudos

hey, don't mark my post HAS SOLVED your question, or I should indicate to moderators that you ABUSE !

former_member218674
Contributor
0 Kudos

Hello,

For such issues you should check syntax help provided by SAP.

Thanks,

Augustin,

Former Member
0 Kudos

Hi,

here is the piece of code.... try to do in the following way..

put the records u want to delete in an internal table and then delete the datbase table from that internal table..

SELECT carrid connid fldate

FROM sflight

INTO CORRESPONDING FIELDS OF TABLE sflight_key_tab

WHERE carrid = p_carrid AND

fldate = sy-datum AND

seatsocc = 0.

DELETE sflight FROM TABLE sflight_key_tab.

Thanks

Ashu

Former Member
0 Kudos

The correct syntax is

delete from it_TABLE WHERE TABLE_KEY1 = LT_TABLE_KEY1.

and

select matnr from mseg into table i_table1

for all entries in it_TABLE

where mblnr = it_TABLE-mblnr.

former_member97292
Participant
0 Kudos

I see where this has been answered but here is another way to do this.

To delete all entries in an internal table:

REFRESH it_table.