‎2010 Jul 20 11:03 AM
Dear Experts,
My requirement is that i am calling an SAP Function Module inside a Method of a class. I need to handle exceptions for the FM call inside the method. Kindly help me in the above regard.
I searched the Forum completely and not able to search the thread.
Regards,
Ramesh Manoharan
Edited by: ramesh.manoharan on Jul 20, 2010 12:04 PM
‎2010 Jul 20 11:47 AM
Do you have any special requirement regarding this one? I don't see where the problem lies. The template for handling this would be:
method my_method.
call function 'SOME_FUNCTION'
exporting
....
importing
....
exceptions
exc1 = 1
exc2 = 2
...
others = 9.
case sy-subrc. "holds value of raised exception
when 1.
"exc1 was raised, handle it here i.e. by giving some message
when 2.
"exc2 was raised....
when 0.
"ok, no exception
....
when others.
"some undefined exception was raised, handle it here
endcase.
endmethod.
Regards
Marcin
‎2010 Jul 20 12:26 PM
Hi Marcin,
Thanks for ur immediate reply. I am unable to use the below statements inside the Method of a class to handle exceptions:
Method Meth1.
call function 'FUNCTION'
exporting.....
importing....
exception
excep1 = 1
excep2 = 2
other = 3.
if sy-subrc ne 0.
case sy-subrc.
when 1.
raise excep1.
when 2.
raise excep2.
when 3.
raise unknown_error.
endcase.
endif.
endmethod.
Are the above statements correct? Plz. correct me if i am wrong.
Regards,
Ramesh Manoharan
Edited by: ramesh.manoharan on Jul 20, 2010 1:29 PM
‎2010 Jul 20 12:41 PM
Ramesh,
What you are trying to do here is catch FM's exception and raise Method's one. So in fact you want to propagate the catched excpetion up in the call hierarchy (pass it to the method's caller). So you do the same as you would be calling exception for FM.
"in class
Method Meth1.
call function 'FUNCTION'
exporting.....
importing....
exception
excep1 = 1
excep2 = 2
other = 3.
if sy-subrc ne 0.
case sy-subrc.
when 1.
raise excep1.
when 2.
raise excep2.
when 3.
raise unknown_error.
endcase.
endif.
endmethod.
"in calling program
call method my_class->meth1
exceptions
excep1 = 1
excep2 = 2
unknown_error = 3.
if sy-subrc = 1.
message "EXCEPT1 was raised' ...
...
All these exceptions must be however listed in methods interface. If it is a global class go to se24 -> click on method -> choose exceptions -> list them here. If it is a local one you list them in the parameter list
class lcl DEFINITION.
public SECTION.
methods meth1 EXCEPTIONS exc1 exc2 ...
endclass.
Anyhow I suggest to get familarized with exception classes which are modern way of handling exceptions. You handle them in TRY...CATCH...ENTRY block.
Regards
Marcin
‎2010 Jul 20 2:43 PM
Check method GUI_UPLOAD of the class CL_GUI_FRONTEND_SERVICES on how to cascade the "Classical" Exceptions from the FM to method callee.
You may also want to translate those classical exceptions to new class based exceptions. Check this help: http://help.sap.com/abapdocu_70/en/ABENEXCEPTIONS.htm
Regards,
Naimesh Patel
‎2010 Jul 27 10:24 AM