Package com.sap.conn.jco
Class JCoContext
java.lang.Object
com.sap.conn.jco.JCoContext
The JCoContext class allows the execution of stateful function call sequences with JCo.
It provides methods for notifying the JCo runtime about beginning and ending stateful call sequences for a specific
destination. The same connection will be used for all remote function calls between invoking the
In case an error occurs during the communication and the connection is broken or closed, an exception will be thrown and the application should take care of this. Depending on the application it might be necessary to repeat all function calls of the failed sequence as the back-end will do an automatic rollback of all previous operations that have not been committed yet.
Example usage:
begin()
and
end()
methods. This is typically used for multi-step logical units of work (LUWs), in which several function
modules are executed in a row and are committed afterwards.In case an error occurs during the communication and the connection is broken or closed, an exception will be thrown and the application should take care of this. Depending on the application it might be necessary to repeat all function calls of the failed sequence as the back-end will do an automatic rollback of all previous operations that have not been committed yet.
Example usage:
JCoDestination destination = JCoDestinationManager.getDestination("<DestinationName>"); try { JCoContext.begin(destination); function1.execute(destination); function2.execute(destination); functionBapiTransactionCommit.execute(destination); } catch (AbapException ex) { ... } catch (JCoException ex) { ... } catch (Exception ex) { ... } finally { JCoContext.end(destination); }Internally, the JCo runtime considers all calls executed in the current session and scope between
begin()
and
end()
as coherent and sends the calls over the same connection. Stateful contexts can be nested. The respective
connection will be released only after the root context is ended, i.e. end()
needs to be called as many times
as begin()
was called before for a specific destination.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
begin
(JCoDestination destination) Begins a stateful call sequence for calls to the specified destination.static void
end
(JCoDestination destination) Ends a stateful call sequence for calls to the specified destination.static boolean
isStateful
(JCoDestination destination) Returnstrue
if in the current session a stateful call sequence has been started and is not finished yet.
-
Constructor Details
-
JCoContext
protected JCoContext()Only used internally.
-
-
Method Details
-
begin
Begins a stateful call sequence for calls to the specified destination. The connections used betweenbegin(JCoDestination)
andend(JCoDestination)
will not be reset or closed. As a consequence the user context in the ABAP back-end will be kept.Note: As
JCoContext.begin()
reserves a connection for exclusive usage, you should only switch to the stateful context if this is really required. Stateless processing should be preferred whenever possible, i.e. avoid usingJCoContext.begin()
/JCoContext.end()
sequences if the used function modules do not store any state in the ABAP system.- Parameters:
destination
- The destination for which to start a back-end context for processing stateful call sequences.
-
end
Ends a stateful call sequence for calls to the specified destination. A reserved connection is then either returned to a pool for reuse or it is at least no longer guaranteed to be kept open.Note: Stateful contexts can be nested. If currently running in a nested context, then calling this method only ends the deepest context, but not the stateful call sequence. The stateful call sequence will only end after the root context has been ended, i.e. after
end()
has been called as many times as methodbegin()
was called before for a specific destination.- Parameters:
destination
- The destination whose back-end context shall be ended.- Throws:
JCoException
- in case releasing/closing any connection runs into an issue.
-
isStateful
Returnstrue
if in the current session a stateful call sequence has been started and is not finished yet. That means methodbegin()
has been invoked butend()
not yet, or more precisely:begin()
has been invoked more often thanend()
for the specified destination.
Otherwise, if there is no stateful call sequence active in the current session, this method returnsfalse
.- Parameters:
destination
- The destination for which the stateful context shall be checked.- Returns:
- Flag describing the current state of the specified destination.
-