cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Try Catch Block in ABAP Like JAVA

Former Member
0 Kudos

Hi Experts,

I am using BAPI to post MIGO in one of my application. If the MIGO is successfully gets posted then BAPI returns no message, but if there is some error in posting then it returns an error message. Now I want to print that error message in catch block by calling method RAISE_ERROR_MESSAGE. How to use try catch block in ABAP. Please suggest with example.

Thanks and Regards.

Vaibhav Tiwari.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Vaibhav

You may not catch exceptions returned by function module using try endtry block.

It works well with the exception returned by methods.

In case of function modules or BAPI what u can do is to check sy-subrc returned and give message accordingly. If it returns a structure like bapireturn then display message returned.

in case of exception returned by a method, do it like this...

data: excep type cx_root.

data: v_str type string.

try.

*any method call or division by zero (for ex)

catch cx_root into excep.

endtry.

if excep is not initial.

CALL METHOD excep->if_message~get_text

receiving

RESULT = v_str.

.

endif.

*display the value returned in v_str on screen

Former Member
0 Kudos

hi vaibhav.....

check this link:

[link|help.sap.com/saphelp_nw70/helpdata/en/a9/b8eef8fe9411d4b2ee0050dadfb92b/content.htm -]

in order to raise a message fo a bapi return you can go for if condition...

like

if i_return is not initial.

message.

endif.

---regards,

alex b justin