Show TOC

Example documentationStateful Connections Locate this document in the navigation structure

 

With SAP JCo release 2.x, a function call was seen as a stateful connection. For this reason it was not necessary to declare a stateful connection explicitly as such.

As of JCo 3.0 a stateful connection requires the statements JCoContext.begin(destination) and JCoContext.end(destination).

The following example shows the programming differences between 2.x and 3.0.

Syntax Syntax

JCo 2.x

  1. JCO.Function bapiFunction1 = ...
  2. JCO.Function bapiFunction2 = ...
  3. JCO.Function bapiTransactionCommit = ...
  4. JCO.Function bapiTransactionRollback = ...
  5. JCO.Client client = ...
  6. try
  7. {
  8. 	try
  9. 	{
  10. 		client.execute(bapiFunction1);
  11. 		client.execute(bapiFunction2);
  12. 		client.execute(bapiTransactionCommit);
  13. 	}
  14. 	catch(JCO.AbapException ex)
  15. 	{
  16. 		client.execute(bapiTransactionRollback);
  17. 	}
  18. }
  19. catch(JCO.Exception ex)
  20. {
  21. 	[...]
  22. }
End of the code.

Syntax Syntax

JCo 3.0

  1. JCoDestination destination = ...
  2. JCoFunction bapiFunction1 = ...
  3. JCoFunction bapiFunction2 = ...
  4. JCoFunction bapiTransactionCommit = ...
  5. JCoFunction bapiTransactionRollback = ...
  6. try
  7. {
  8. 	JCoContext.begin(destination);
  9. 	try
  10. 	{
  11. 		bapiFunction1.execute(destination);
  12. 		bapiFunction2.execute(destination);
  13. 		bapiTransactionCommit.execute(destination);
  14. 	}
  15. 	catch(AbapException ex)
  16. 	{
  17. 		bapiTransactionRollback.execute(destination);
  18. 	}
  19. }
  20. catch(JCoException ex)
  21. {
  22. 	[...]
  23. }
  24. finally
  25. {
  26. 	JCoContext.end(destination);
  27. }
End of the code.