Search code examples
javacommitabapjco

Does BAPI_TRANSACTION_COMMIT commit changes since the last commit


I know When you call BAPIs in your program that change data in the SAP system, you must then call BAPI_TRANSACTION_COMMIT to write the changes to the database.

   JCoFunctionTemplate functionTemplate = dest.getRepository().getFunctionTemplate("BAPI_FIXEDASSET_CHANGE");      
   JCoFunction ChangeFunction = functionTemplate.getFunction();
   ...//some code
   ChangeFunction.execute(destination);

    JCoFunctionTemplate functionTemplate = dest.getRepository().getFunctionTemplate("BAPI_TRANSACTION_COMMIT");   
    JCoFunction commFunct = functionTemplate.getFunction();
    commFunct.execute(destination);

My question is, does BAPI_TRANSACTION_COMMIT commit all the changes since the last commit? or does it commit only the previous transaction?


Solution

  • A usual way of dependent database operations is also known as transaction. A transaction is per definition a atomic operation on a db to keep consistent data consistent after any change. If n database operations after each other belong to a transaction, then the commit must be issued after the last successful operation. If any of n operations fail, the transaction is considered incompletely issued. A rollback work is the usual approach for this. If You have a transaction which should be split to commit only several changes, consider redesigning Your entire approach. Or , not so nice, create a posting function module and call this in update task. Be careful with that. Oh, and I see, You call standard sap function module. Look for its parameters. It might have a flag for commit implicitly. And never forget the SAP GUI transaction "BAPI" and read the documemtation. It is very likely that Your wish is not transactional consistent therefore the bapi must do more. If something later fails, the transaction is inconsistent and therefore not committed. Mostly sap knows what their apis should do. But I doubt it when dealing with quality notifications and quality inspection lots. :-D