I've read about the "Two Pre-Defined Execptions" for a RFC.
AND that, while calling the RFC we can code:
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.
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.
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.
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.
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.
if sy-subrc eq 2.
code to handle that exception.
I hope you got something.
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
WHERE werks = plant_werks.
IF SY-SUBRC <> 0.
return = 'No materials selected for entered plant'.
WITH 'Please Enter Correct Plant Number'
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 '.....'
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?).