DI-API: startTransaction

sap-sdk

 

Starts a transaction, allowing you to perform data operations on several business objects.

Use the EndTransaction method to end the transaction and free locked records, allowing other users to access them.

 

Remarks

Use this method when you want to perform data operations on several business objects:

If the operations succeed, either commit the transaction to save the data in the database, or roll back to discard the changes.

If one of the operations fail, the DI API rolls back the transaction, which discards the changes. After a failed DI API call in the transaction, you must immediately exit the transaction (see the example below).

 

declare=di_item=ue_api_sbo
// Start transaction process
// Add first item
di_item=starttransaction
di_item=getbusinessobject=oitems
di_item=itemcode=NewItemCode
di_item=itemname=NewItemName
di_item=add
// Add second item
di_item=getbusinessobject=oitems
di_item=itemcode=NewItemCode2
di_item=itemname=NewItemName2
di_item=add
// If anything is wrong - create rollback
if <anyerror> = true then
  di_item=endtransaction=-1
 
// all ok, commit complete process
else
  di_item=endtransaction=0
end if

 

Note:

The transaction process is only for the SAP SDK connection.

Beas open own connection to database and can't see the changes made inside sap transaction process, if not commited.

 

 

declare=di_item=ue_api_sbo
// Start transaction process
// Add first item
di_item=starttransaction
di_item=getbusinessobject=oitems
di_item=itemcode=NewItemCode
di_item=itemname=NewItemName
di_item=add
 
// follow return 100 (not found) because the transaction process not closed
select "ItemCode" from "OITM" where ItemCode='NewItemCode'
 
di_item=endtransaction=0
// now it's possible to read
select "ItemCode" from "OITM" where ItemCode='NewItemCode'