As with LocalTransaction, the UserTransaction should be allocated first. All transactional activities running under this user will then be included in this UserTransaction as soon as it is started and as long as it is not completed by COMMIT or ROLLBACK.
Example:
………………………………………………..
// create UserTransaction
UserTransaction userTransaction
= (UserTransaction) initialcontext.lookup("java:comp/UserTransaction");
// or get UserTransaction from Servlets Context (valid only for Servlets)
UserTransaction userTransaction = m_sessionContext.getUserTransaction();
// start userTransaction
userTransaction.begin();
// create Interaction and Records, fill records with business data
………………………………………………
// execute first call
MappedRecord output1 = (MappedRecord)interaction.execute(null, input1);
// evaluate output1 and using it fill the new input2 with some data.
…………………………………………….
// execute next call
MappedRecord output2 = (MappedRecord)interaction.execute(null, input2);
// execute some more calls, if needed
…………………………………………….
// if all this calls were proceeded successfully, then commit LocalTracaction
userTransaction.commit();
// after commit, all statements written with update task in ABAP will be persisted
// in the data base
// otherwise rollback it, by
userTransaction.rollback();
// In this case all statements written with update tasks will be discarded.