Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Re: Exception in Function Module

Former Member
0 Likes
4,498

There is an scenario i.e., am creating a Z-function module and in that am making a call to a standard SAP function module ...when I execute my Z function module the standard SAP FM contained in it , produces an error or dump which is not being handled in the standard SAP FM ...so how can I handle this error or dump in my Z function module ?

1 ACCEPTED SOLUTION
Read only

Clemenss
Active Contributor
0 Likes
1,663

Hi ,

you can handle almost everyrhing using the try .. catch statement:

TRY.

  CALL FUNCTION 'Any function'...

CATCH CX_ROOT. "Root exception catches everything

*  Handle exception here

ENDTRY.

Using this, you will never get a dump.

If you CATCH CX_ROOT INTO lo_object you can use predefined methods to find out details about the error, i.e. line number and include where it occurred.

Regards

Clemens

5 REPLIES 5
Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,663

(FAQ, Basis) Read the documentation of CALL FUNCTION (F1 or online) then use the EXCEPTION clause to catch the raised exceptions, you can then raise your own exception to the caller or manage it in your code.

Regards;

Raymond

PS: You could also wrap the call in a try/endtry or similar tool to intercept most errors.

Read only

che_eky
Active Contributor
0 Likes
1,663

When calling the standard function module use EXCEPTIONS error_message = 4.

Che

Read only

rajesh_paruchuru
Active Participant
0 Likes
1,663

I believe you are referring to a situation where SAP standard FM is throwing an error message without "RAISING" any exception, if yes, I doubt if such an error situation can be handled in the calling program, if I were you I would ensure that i'm using an SAP released FM and would also look for alternate FM's which serve the same purpose.

As a side note it is also possible that SAP might be doing that on purpose, like in the case of update function modules, an "A" message will be triggered if any of the DML operations within the FM fail, it is however not a good practice to use such SAP standard update FM's in custom implementations.

-Rajesh.

Read only

Former Member
0 Likes
1,663

Hi Raghavendran,

while calling the standard function module use the others = 4 in exceptions.

Then it will not raise any short dump and the sy-subrc value as 4.

1) If you are not maintained any exceptions are default case others = 4 then the FM fails then it will not recognize the error then it will

   gives short dump. The best practice is when ever you are calling any function module maintain as exceptions others = 4.

   then it eradicates the dump even it is standard one also

2) Don't use the standard messages in the FM. Use the custom messages.

While you are calling the standard function module from pattern.

If sy-subrc <> 0 .

----> Using some standard messages. Here, write the custom message Bcoz, when the system not recognize the standard message then it will gives the

short dump

Endif.

I hope,  it will helps to you try it.

Thanks

Sekhar

Read only

Clemenss
Active Contributor
0 Likes
1,664

Hi ,

you can handle almost everyrhing using the try .. catch statement:

TRY.

  CALL FUNCTION 'Any function'...

CATCH CX_ROOT. "Root exception catches everything

*  Handle exception here

ENDTRY.

Using this, you will never get a dump.

If you CATCH CX_ROOT INTO lo_object you can use predefined methods to find out details about the error, i.e. line number and include where it occurred.

Regards

Clemens