cancel
Showing results for 
Search instead for 
Did you mean: 

How to handle JCO.AbapException on JCO call in ABAP

Former Member
0 Kudos

Hello Forum,

I am implementing an JCO Server scenario.

I use dynamic repositories like Example7.java from the JCO documentation.

Example7 throws an JCO.AbapException if anything went wrong, e.g. the function is not implemented. My coding is like:

	protected void handleRequest(JCO.Function function) throws AbapException {
		try {
		  // Process incoming requests
		} catch (Exception e) {
		  log.error(this.getProgID() + ": error handling request " + function.getName(), e);
		  throw new AbapException(function.getName(), e.getMessage());
		}
	}

How to react on this AbapException?

The examples in SAP Help documentation only catch

SYSTEM_FAILURE and COMMUNICATION_FAILURE.

I implemented the JCO call as well like following.

CALL FUNCTION 'MY_JCO_FUNCTION_MODULE'
    DESTINATION JCO_DEST
    <...>
    EXCEPTIONS
      SYSTEM_FAILURE        = 1  MESSAGE RFC_MESS
      COMMUNICATION_FAILURE = 2  MESSAGE RFC_MESS.

But these two are only thrown and caught when something with communication went completely wrong, e.g. RFC not found.

When the exception in the JCO server occured and JCO.AbapException was thrown I always get an ABAP short dump, i.e. the exception was not handled.

Additionaly, the exception is named like the JCO function called and the message text which was submitted to JCO.AbapException is not displayed. I think that means that the AbapException was not recognized at all?

The JCO API doc says:

Creates an exception with the specified key. This constructor is normally used in the server's handleRequest() methods to throw an exception which is part of the function interface definition. In such a case the SAP system will not raise a system exception. If however the specified key is not a defined exception for the currently processed function module the SAP will raise a system exception.

But whether I define an exception in the function interface definition named like the module (thererfor new AbapException(function.getName(), <...>)) or not, it always dumps. I understand the exception that a system exception is raised when the exception is not defined? But this is not been handled with above ABAP code as well.

What is wrong here? Could anyone post an example please how the exception has to be handled?

Please note that I do not define static repositories but have the remote function defined on in the ABAP server to be used by dynamic repository (like the STFC_CONNECTION test rfc). Am I right that the exception should be defined in that RFC remote definition?

Thanks,

Carsten

Accepted Solutions (0)

Answers (3)

Answers (3)

0 Kudos

Dear everybody,

Finally I solved this old problem

I am a novice in JCO and played a little with the problem and found an old reference to the difference between J2EEAbapException and AbapException classes. I modified my program and it works! ABAP caller gets the correct exception, not system_failure! The details:

1. modify beanname.java source

     .....

     import com.sap.mw.jco.JCO;

     import com.sap.mw.jco.JCO.J2EEAbapException;

     public interface ... extends EJBObject {

    public void processFunction(JCO.Function function) throws RemoteException, J2EEAbapException;

2. modify beannamebean.java source

     ...

    import com.sap.mw.jco.JCO.J2EEAbapException;

     ...

     public void processFunction(JCO.Function function) throws J2EEAbapException {

     ...

     throw new JCO.J2EEAbapException("NODATA");

     ...

3. modify beannamelocal.java source

     ...

      import com.sap.mw.jco.JCO;

     import com.sap.mw.jco.JCO.J2EEAbapException;

     ...

          public void processFunction(JCO.Function function) throws J2EEAbapException;

     ...

I hope it helps for somebody else too!

Imre

0 Kudos

Dear Carsten,

Did you find any solution to this problem? I have the same problem.

Many thanks,

Imre

Former Member
0 Kudos

Hi Carsten,

did you find an answer to your question from last year?

I have the same issue.

Thanks

Markus