Skip to main content

SAP: Refresh BAPI Buffers with BAPI_TRANSACTION_COMMIT

Submitted by Stefan Barsuhn on

When you're communicating with an external SAP system, you should use the released BAPIs if you can.

I don't use RFCs and BAPIs that often, so one thing that struck me today was that BAPIs don't refresh their buffer when you call them.

My expectation was: BAPIs are for external calls, so they should make sure you always get the most-up-to-date data and handle the buffer themselves.

I was wrong.

BAPIs will default to accessing the buffer, which makes sense performance-wise.

Problems arise when - between two BAPI calls - somebody modifies the data in the external data and does not refresh the buffer. (And I'm not talking sloppy custom developments, SAP Standard often makes changes and does not clear the buffers either.)

Therefore, if you want to make sure that you're accessing the up-to-date data in the external system (as opposed to you're fine if the data is a few minutes old) - you need to refresh the buffer before your actual BAPI call.

This is done by calling function module BAPI_TRANSACTION_COMMIT right before the BAPI that requires up-to-date data.

This may be counter-intuitive as you're just reading data, not changing data. But we're not interested in the COMMIT but in the  SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } BUFFER_REFRESH_ALL function module that is called at the end of it.

BTW: It is good practice to never call COMMIT WORK explicitly. Instead, always use FM BAPI_TRANSACTION_COMMIT. This will take care of the BAPI buffers and it also allows for a "where used" of commit work.

Tags