I Have a C# web application that call multiple BAPI and stored procedure at one of the function in ASP.net Website. i need to rollback all the bapi executed on the function that called on the web if one of the method inside the function is failed.
in SQL I call
SqlTransaction transaction = connectionsql.BeginTransaction();
...
transaction.Rollback();
on the c# code if one of the method failed. (this can be done for sql rollback)
but for the SAP BAPI , even if i call BAPI_TRANSACTION_ROLLBACK on C# catch statement , the changes is still there. (rollback not success)
FYI , in my BAPI Function i use CSAP_MAT_BOM_MAINTAIN to update the BOM information.
is there any way to do rollback like sql transaction on my C# code for SAP BAPI Function and rollback all the BAPI run on C# if the web catch an exception ?
Your thinking is correct. Ideally, you should be able to do the following from your ASP.net code:
BAPI_TRANSACTION_COMMIT
, if error, call BAPI_TRANSACTION_ROLLBACK
.Unfortunately, if the BAPIs contain a COMMIT
themselves (and many older ones and non-BAPI function modules do), your ROLLBACK
will be too late - the data will already have been committed.
In your case, function module CSAP_MAT_BOM_MAINTAIN
contains a FL_COMMIT_AND_WAIT
parameter but this only affects whether the COMMIT
waits (a commit still occurs either way). There may be a workaround, however: in subroutine CSAP_MAIN_INIT
(include LCSAPF01
) in my system, there is this line of code:
import flg_no_commit_work from memory id 'CS_CSAP'.
This flag (flg_no_commit_work
) is later passed into a call to function module CS_DI_BOM_VB
(called from CSAP_MAT_BOM_MAINTAIN
) and if it's set, no COMMIT
is done. Perhaps try setting that flag via an EXPORT TO MEMORY
and see if that helps. Of course, this is undocumented and unsupported by SAP but it may well work...