Stateful-Verbindungen
In SAP JCo Release 2.x wurde ein Funktionsaufruf grundsätzlich als Stateful-Verbindung betrachtet. Aus diesem Grund war es nicht notwendig, eine Stateful-Verbindung explizit als solche zu deklarieren.
Ab JCo 3.0 benötigt eine Stateful-Verbindung die Anweisungen JCoContext.begin(destination)und JCoContext.end(destination).
Das folgende Beispiel zeigt die Unterschiede in der Programmierung zwischen 2.x und 3.0:
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) { [...] }
|
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); }
|