cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with web dynpro handling exception thrown by BAPI

Former Member
0 Kudos

Hi guys,

I occured a weird problem when web dynpro handling exception thrown by BAPI. Here is my code:

try {

wdThis.wdGetCreateCustController().execute_ZBAPI_TRIP_CHANGE_FROM_DATA();//throws an exception from BAPI

} catch (Exception e) {

if(e != null) manager.reportException("exception:" + e.toString(),false);//NullPointerException????

if(null != wdContext.nodeReturn()) {

wdContext.nodeOutput().invalidate();

int returnsize = wdContext.nodeReturn().size();

for(int i = 0;i<returnsize;i++) {

IPrivateCreateView.IReturnElement ob = wdContext.nodeReturn().getReturnElementAt(i);

String msgtype = ob.getType();

String msg = ob.getMessage();

if("S".equalsIgnoreCase(msgtype)) {

manager.reportSuccess(msg);

} else if("E".equalsIgnoreCase(msgtype)) {

manager.reportException(msg,false);

} else manager.reportWarning(msg);

}

}

}

Weird problems:

1. When an exception is thrown by the BAPI, the exception seems to be print in my message area automatically.

2. The line if(e != null) manager.reportException("exception:" + e.toString,false) will throw an NullPointerException

3. We can't get the rows in return table, which should be one row when executed in SE37.

Can anyone give me an explanation?

Best Regards,

Xiaoming Yang

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Ideally your BAPI shouldn't raise exceptions - it is much better to use the RETURN table from your BAPI with any relevant messages - have a look at the majority of standard SAP BAPI's in transaction BAPI.

This way, the only exceptions your try... catch block needs to handle are those related to the actual calling of your BAPI, not it's functionality.

Also, if you can successfully run the BAPI in SE37 but it fails when called from your WD application, try using the FBGENDAT functionality to capture what data is being passed to SAP from your Web Dynpro application. All it takes is a simple mistake in setting up your contexts or logic and you won't be calling your BAPI correctly.

Hope this helps,

Gareth.

Former Member
0 Kudos

Gareth,

<i>Ideally your BAPI shouldn't raise exceptions</i>

This is true, but world of distributed computing is not ideal per se, there are could be communications error at transport layer, authentication errors, etc

VS

Former Member
0 Kudos

Hi Valery,

That's what I meant - I just wasn't very clear!

The exceptions should be coming only from the communication between WD and SAP Backend and not the actual business logic inside the BAPI. This way it is easier to trace problems and decide whether they are with the logic of your BAPI or in fact with your JCo connections or related.

Gareth.

Former Member
0 Kudos

xiaoming,

Inside catch block Exception "e" can never be null, however variable "manager" seems to be null, check this instead.

Next, do not mix exception handling and handling of BAPI return messages, this processing (BAPI returns) should be placed inside "try" block (btw, this may cause NPE as well).

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com