2022 Jul 07 3:19 PM
Hello everyone,,
I have a question regarding the use of BAPI inside BADI, customer exits or any enhancement techniques. We need to use BAPI_COMMIT FM after calling the bapi but if we are using the BAPI inside anyone of the enhancement techniques, then in that case what should be our approach since we should not use commit inside any enhancement?
Also, my second question is that if the bapi returns a locking error here then what should we do? Use deque FM in the enhancement? Wouldn’t that release locks for other objects as well!
Any help would be very much appreciated here!
Thanks in advance.
2022 Jul 07 4:38 PM
Hello eihtu
First of all, it is not carved in stone that you must not call BAPIs or execute commit work in enhancements. It all depends on the nature of the enhancement and when it is called. I do agree however, it is safer to avoid commits in enhancements.
The solution is to wrap BAPI call and subsequent BAPI_TRANSACTION_COMMIT is an RFC function module. Then call the function from the enhancement in a separate LUW (logical unit of work) using:
CALL FUNCTION func IN BACKGROUND TASK
AS SEPARATE UNIT
See SAP Help on AS SEPARATE UNIT addition.
That trick also solves locking problems in BAPI processing.
Best regards
Dominik Tylczynski
2022 Aug 03 2:06 PM
Hello Dominik,
Sorry for the late response! Thank you so much for your answer.
So if the Badi changes fails in between, and a rollback happens. The changes by the BAPI in this FM will also be rolled back? Or it is commited? I am new to SAP LUW’s scenarios. So if you can help me understand whether the Background task will be part of the same SAP LUW or a separate one in this case?
thanks in advance
2022 Aug 03 2:16 PM
2022 Aug 08 7:47 AM
Hi Dominik,
I created RFC to update BP and added BAPI_TRANSACTION_COMMIT in it after BP update BAPI. Called RFC as below inside BAPI but it seems it does not consider BAPI_TRANSACTION_COMMIT added in the RFC. Commit happens only when it receives commit outside RFC..
CALL FUNCTION func IN BACKGROUND TASK AS SEPERATE UNIT
2022 Aug 08 12:04 PM
2022 Aug 08 12:50 PM
ls_centraldata-centralblock = space.
ls_centraldata_x-centralblock = 'X'.
CALL FUNCTION 'BAPI_BUPA_CENTRAL_CHANGE'
EXPORTING
businesspartner = iv_partner
centraldata = ls_centraldata
centraldata_x = ls_centraldata_x
TABLES
return = et_return.
IF sy-subrc = 0.
READ TABLE et_return TRANSPORTING NO FIELDS
WITH KEY type = 'E'.
IF sy-subrc <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
ENDIF.
…… Inside BADI
CALL FUNCTION 'ZRFC' IN BACKGROUND TASK
AS SEPARATE UNIT
EXPORTING
iv_partner = lv_bp_num
TABLES
et_return = lt_return.
2022 Aug 08 2:24 PM
2022 Jul 07 4:41 PM
As a rule of thumb,
Inside the BADi - We should not use any BAPI that finished with Commit . Because BADi is are in generally in betwen process where we put of deviations and/or validations.
Anything that commits or locks - will create incosistencies.
for your second question also, though DEQUE releases the lock, it may create incosistencies too.
2024 May 03 8:12 PM
Yes we can use bapi inside badi .
I have worked on one requirement where badi is used to populate a bapi as some fields were not available in bapi so that it can be executed successfully.