Skip to Content
0
Former Member
Jan 19, 2016 at 02:32 PM

SAP JCo: How to handle an Exception thrown by JCoContext.end()

591 Views

All,

We have currently developed a Java client application that communicates with SAP via the JCO v3.0 API. During a stateful call, where multiple BAPI functions are invoked, we use the JCoContext class to establish a stateful session. We call JCoContext.begin() before the JCoFunctions are executed and JCoContext.end() in a finally block after all functions are complete.

The problem arises on JCoContext.end(). It could potentially raise a JCoException. The document is not very clear on why an Exception may occur or how to handle it. In testing, I have been able to observe an exception when a NULL destination is passed to the JCoContext.end() method. While this can occur, it most definitely will not occur in our production code. So the question remains, are there any other reasons why and exception would be raised?

Also, I have observed strange behavior if the JCoContext.end() method is not invoked. It those cases, I have seen subsequent BAPI calls not complete successfully. This indicates to me that if the end() method does not complete successfully, it could leave the JCo in a bad state. So, how should we handle an exception that occurs here. What recourse do I have as a developer?

Thanks,

Paul Manning