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: 

ABAP Open SQL:Cascade on Delete

Former Member
0 Kudos
462

Hello,

I have a primary table and seconday table with Foreign Key. when I delete the record from primary table, i want to delete all recrods from secondary table. Is there command in ABAP like cascade on delete?

Thanks,

Ahmed

3 REPLIES 3

Former Member
0 Kudos
112

Hi!

You have to clean up the records from the second table for yourself.

DELETE FROM second_table WHERE foreign_key = first_table-key.

Regards

Tamá

0 Kudos
112

Thanks for the reply.

But I have multiple records to be deleted from first table. So I have to loop to delete records from secondary table. Can I do without loop.

Regards,

Ahmed

0 Kudos
112

Of course you can.

1. You surely have an internal table, with the entries to be deleted. This table must have the primary keys of your DDIC second_table.

Then use the following code :

IF NOT itab[] IS INITIAL. "don't start the deletion using an empty table

DELETE second_table FROM TABLE itab.

ENDIF.

2. Or you can use the DELETE within a loop.

For more details on the DELETE command, simply press F1, on it, within the ABAP editor.

Regards

Tamá