Reading original (before change) DB values in the current LUW?
Asked Answered
P

1

9

Is it possible to retrieve the old or original values for a table when it has been changed, but not yet committed, in the current LUW?

I'm implementing a BAdI that's supposed to be used to raise messages based on changes performed to an object, but SAP doesn't actually provide the original object data in the BAdI. Trying to read the data with SELECT statements doesn't work as the pending changes have already been applied at that point, just not committed.

If I debug the code I can see the old values just fine in SE16 but it seems like the uncommitted changed values are being returned by any SELECTs I perform in this BAdI.

Is there any way to read this original data?

Protoactinium answered 22/3, 2018 at 12:57 Comment(2)
I think you'll possibly benefit of helpful answers by tagging your question with sqlHizar
@SandraRossi Thanks for the tip. I usually avoid that as while it does draw a lot more people, I usually end up having to explain at tedious length why a standard SQL solution won't work in ABAP. :)Protoactinium
H
13

The reading of a table which was updated previously, during the same Database LUW, will always return the updated values. So, it's at least required to read the table from another Database LUW.

The isolation level used by default depends on the type of database you are using. For HANA and Oracle, the "committed read" is the default, but other databases use the "uncommitted read" by default.

If you don't use HANA/Oracle, you may switch temporarily to the "committed read" isolation level by calling the function module DB_SET_ISOLATION_LEVEL.

Then, you can read the table from another Database LUW by using a service connection (prefixed R/3*), for instance: SELECT ... FROM yourtable ... CONNECTION ('R/3*temp') ...

Hizar answered 22/3, 2018 at 15:31 Comment(1)
Worked like a charm and I don't see how this answer could be improved upon so I'll accept early. Thanks!Protoactinium

© 2022 - 2024 — McMap. All rights reserved.