SELECT FOR UPDATE
2022-05-23
When you’re going to modify existing records of a database table it is common to first SELECT
them to see how they are and only then UPDATE
them with what they will be.
But ABAP is like a Fabergé egg. The more you look at it the more details you’ll find. And now I found this one.
When you SELECT
when you already know you’re going to UPDATE
, then at the end of the SELECT
command you can add FOR UPDATE
and ABAP will go ahead and lock those records for writing immediately.
Here’s an example:
SELECT calories FROM cakes WHERE id = 'cupcake' FOR UPDATE.
It does have some rules and constraints. But still quick nice, hum?
Thank you Nuno Morais for the tip.
Thank you Jason Pier for the photo.
Greetings from Abapinho.