Skip to Content
0
Aug 26, 2023 at 09:18 AM

Invoke multiple functions in a transaction in sapjco3

238 Views

I want to Invoke multiple functions in a transaction to ensure transaction consistency or rollback..

My code:

JCoContext.begin(jcoDestination);

String tid = jcoDestination.createTid();

JCoFunction function1 = jcoDestination.getRepository().getFunction("function1");

function1.execute(jcoDestination,tid );

JCoFunction function2 = jcoDestination.getRepository().getFunction("function1");

function2.execute(jcoDestination,tid );

JCoFunction commitFunction = jcoDestination.getRepository().getFunction("BAPI_TRANSACTION_COMMIT");

commitFunction.execute(jcoDestination,tid );

JCoContext.end(jcoDestination);

I found a problem when I ran it.

First,The function BAPI_TRANSACTION_COMMIT commit all transactions, and the transaction does not use the transaction id(tid) parameter. I want to know how to commit a transaction for a particular transaction id.

Second,The data entered in "function1" is correct. The data entered in "function2" is incorrect. When the transaction is committed, the data of "function1" is still saved to the table. The transaction consistency is not achieved. That is, one error is reported and the other cannot be saved. It does not achieve the consistency of transactions that I understand, one error is reported and the other cannot be saved. Who can tell me why.

Please , what's wrong, or I have a problem understanding of sap's transaction.