cancel
Showing results for 
Search instead for 
Did you mean: 

how to get short text of a exception thrown by abap rfc

Former Member
0 Kudos

Hi buddy,

I use jco to communicate with backend, an abap function module will raise a exception. I can catch that exception,

The example exception is:

<b>Exception</b> <b>Short text</b>

Test This is exception test.

e.getKey() 

will return TEST.

Does any know how to get that short text "This is exception test." from the exception I caught?

Thanks

Austin

Accepted Solutions (0)

Answers (3)

Answers (3)

lajitha_menon
Contributor
0 Kudos

Hi Austin,

There are 2 methods to raise errors in function modules.

1) Using the raise Exception statement

2) Using a return structure like BAPIRET to populate the message details like type, error number, error text etc.

Generally method 1 is not recommended for any RFC/BAPI function modules because it causes the calling program to crash if the function raises an exception. Method 2 is the recommended way and is used in all standard BAPI's. ABAP programmers are advised to code RFC's as per method 2, but some times it would not be possible as the function would already be used and could be barred from changes.

But whatever method the RFC uses to raise an exception, web dynpro can handle it in the following ways,

Method 1) If the RFC raises an exception using RAISE EXCEPTION,

Dont catch Exception class in your code, instead do the following,

catch (WDDynamicRFCExecuteException e) {

wdComponentAPI.getMessageManager().reportException(

e.getLocalizedMessage(),

true);

Method 2) If the function returns the errors in the standard bapi return structure, you can do the following

IWDMessageManager MsgMgr = wdComponentAPI.getMessageManager();

for (int i = 0; i < ReturnNode.size(); i++) {

if (Types.indexOf("S") != -1

&& ReturnNode.getElementAt(i).getAttributeAsText("Type").equals(

"S"))

MsgMgr.reportSuccess(

ReturnNode.getElementAt(i).getAttributeAsText("Message"));

if (Types.indexOf("W") != -1

&& ReturnNode.getElementAt(i).getAttributeAsText("Type").equals(

"W"))

MsgMgr.reportWarning(

ReturnNode.getElementAt(i).getAttributeAsText("Message"));

if (Types.indexOf("E") != -1

&& ReturnNode.getElementAt(i).getAttributeAsText("Type").equals(

"E"))

MsgMgr.reportWarning(

ReturnNode.getElementAt(i).getAttributeAsText("Message"));

}

Former Member
0 Kudos

Hi,

It is returning from the BAPI.

Then it has one field status u can utilize in After executing

U can capture the field.

And check your filed based on some condition.

Get the status field is

Do u want to capture that field I will give the code and u can utilize.

Or otherwise u can go as Anil's advice.

Thanks,

Lohi.

Former Member
0 Kudos

Try

e.getMessage() or e.toString()

Regards, Anilkumar

Former Member
0 Kudos

Hi Anilkumar

unfortunately

e.getKey()=TEST

e.getMessage()=TEST

e.getMessageText() =

e.getLocalizedMessage()=TEST

the abap guy just write the following code to raise exception:

raise test

should the abap guy do something else?

Best regards,

Austin

Former Member
0 Kudos

e.toString()com.sap.mw.jco.JCO$AbapException: (126) TEST: TEST

Former Member
0 Kudos

Hi Austin,

I think you need to do more on ABAP side while raising the exception .

Check the link below

http://help.sap.com/saphelp_nw04s/helpdata/en/cf/f2bbc8142c11d3b93a0000e8353423/frameset.htm

Regards, Anilkumar

Former Member
0 Kudos

Hi Anilkumar

my abap guy tell me that if he uses classed based exception then the function module can't be remote call:(

I have little knowledge about abap.

Best regards,

Austin

Former Member
0 Kudos

Hi

Even i don't have any knowledge on ABAP !!!

But i've found a link explains about two diferent ways of raising exceptions in functionmodules

1. RAISE except.

2.MESSAGE.....RAISING except.

Just try with the second option.

http://help.sap.com/saphelp_nw04s/helpdata/en/9f/db98fc35c111d1829f0000e829fbfe/content.htm

Regards, ANilkumar