Application Development 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: 

Execption handling in RFCs

Former Member
0 Kudos

Hello All.

I've read about the "Two Pre-Defined Execptions" for a RFC.

a> SYSTEM_FAILURE

b> COMMUNICATION_FAILURE

AND that, while calling the RFC we can code:

EXCEPTIONS

SYSTEM_FAILURE = 1 MESSAGE msg

COMMUNICATION_FAILURE = 2 MESSAGE msg

Can anybody please help me on this? Both concept wise and the above code. I mean, what do you mean by Pre-Defined and how to successfully use it.

Thank You.

5 REPLIES 5

Former Member
0 Kudos

Hi, as my undetstand, these two exception is default been defined by system, for RFC function.

You don't need to add them into the Exceptions Defination in the SE37.

Hope it will be helpful.

Former Member
0 Kudos

hi,

these two exceptions are defined in the system for each RFC-enabled function module. u don't need to define these in the interface of the function module but u must handle them in your code. The code sample that you have written is the correct way to code them.

read the following extract from documentation...

As well as the exceptions defined in the interface of the called function module, an external function call can also have the following predefined exceptions:

The SYSTEM_FAILURE exception is the response to a runtime error that occurs when the remotely-called function module is executed.

The COMMUNICATION_FAILURE exception occurs when the connection to the partner system cannot be established or if the connection is lost during communication.

Note

We strongly recommend that you assign a return value to both these exceptions for every RFC, and that you handle this return value, as otherwise a runtime error will occur in the exception situations in question.

regards,

PJ

0 Kudos

hi,

just to add....you might find this extract useful too...

Identical to any call of a function module, the RFC initializes the system field sy-subrc in the calling program resp. sets it to the value specified in error handling. Additionally, RFC initializes the system fields sy-msgid, sy-msgno, sy-msgty and sy-msgv1 to sy-msgv4 in the calling program at every remote call of a function module. If an error or termination message is sent during the execution of a remotely called function module through the statement MESSAGE, then the exception SYSTEM_FAILURE is triggered in the calling program, to which you can assign a return value at calling time. If the exception occurs, then these system fields are supplied with the properties of the message.

regards,

PJ

former_member181959
Contributor
0 Kudos

hi...

built-in function modules generally contains some import , export parameters and probable exceptions.

here in RFC also there some expected exceptions which may occur for a particular reason.

if you are from a computers background i can explain you with an example in java. For example if i = 3 / 0 this may lead to arithmetic exception which occurs only when we divide a number with 0.

Here in abap also same, when communication fails or system fails respective exceptions will be raised.

That corresponding exception code value is placed in

sy-subrc system field. What we need to do is check for that value and proceed as we intended to.

for example we can handle those exception like this,

if sy-subrc eq 1.

code to handle that exception.

for SYSTEM_FAILURE.

endif.

if sy-subrc eq 2.

code to handle that exception.

for COMMUNICATION_FAILURE.

endif.

I hope you got something.

Regards,

Prasad.

Former Member
0 Kudos

If that is the case that we need not include these two exceptions explicitly, then I have another question.

The below code is IN the RFC.

__________________________________________________________

SELECT werks matnr

INTO CORRESPONDING FIELDS OF TABLE it_mat_plantwise

FROM marc

WHERE werks = plant_werks.

IF SY-SUBRC <> 0.

return = 'No materials selected for entered plant'.

MESSAGE I001(AT)

WITH 'Please Enter Correct Plant Number'

<b>RAISING RE_ENTER_PLANT_NO</b>.

ENDIF.

__________________________________________________________

I have included RE_ENTER_PLANT_NO inside the EXECPTIONS tab in function builder.

Now this is what I see when I call this function in SE38.

__________________________________________________________

CALL FUNCTION '.....'

..

..

EXCEPTIONS

RE_ENTER_PLANT_NO = 1

OTHERS = 2

.

__________________________________________________________

I will write a CASE statement to handle the SY-SUBRCs.

My question is if RE_ENTER_PLANT_NO and OTHERS have SY-SUBRC values as 1 and 2 respectively, then how do I handle SYSYTEM_FAILURE and COMMUNICATIONS_FAILURE (I mean using what value of SY-SUBRC?).