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
JCo 2.x
JCO.Function bapiFunction1 = ...
JCO.Function bapiFunction2 = ...
JCO.Function bapiTransactionCommit = ...
JCO.Function bapiTransactionRollback = ...
JCO.Client client = ...
try
{
try
{
client.execute(bapiFunction1);
client.execute(bapiFunction2);
client.execute(bapiTransactionCommit);
}
catch(JCO.AbapException ex)
{
client.execute(bapiTransactionRollback);
}
}
catch(JCO.Exception ex)
{
[...]
}
Syntax
JCo 3.0
JCoDestination destination = ...
JCoFunction bapiFunction1 = ...
JCoFunction bapiFunction2 = ...
JCoFunction bapiTransactionCommit = ...
JCoFunction bapiTransactionRollback = ...
try
{
JCoContext.begin(destination);
try
{
bapiFunction1.execute(destination);
bapiFunction2.execute(destination);
bapiTransactionCommit.execute(destination);
}
catch(AbapException ex)
{
bapiTransactionRollback.execute(destination);
}
}
catch(JCoException ex)
{
[...]
}
finally
{
JCoContext.end(destination);
}