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

ABAP Open SQL:Cascade on Delete

Former Member
0 Kudos
717

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
Read only

Former Member
0 Kudos
367

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á

Read only

0 Kudos
367

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

Read only

0 Kudos
367

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á