Skip to Content
0

Question on RFC handling in sap

Nov 08, 2016 at 06:19 AM

187

avatar image

Hi Experts,

I know we can use RFC for communicating from external system to R3 or from R3 to external system, I have a question on the exception handling done.

If we are communicating from R3 to external system, we would use as

CALL FUNCTION FM NAME DESTINATION DEST NAME

Exceptions

exceptions and based on the sy-subrc value the exception is caught

and if we are calling from external system how are the exceptions handled I had gone through the links below

https://help.sap.com/abapdocu_731/en/abenrfc_exceptions_abexa.htm

https://help.sap.com/saphelp_nwpi71/helpdata/en/13/90a594a1ab0841bbb731bdec1a7fd7/content.htm

Thanks,

rg

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
avatar image
Former Member Nov 08, 2016 at 06:53 AM
0

Hi Ramya G,

Exception Handling will be effective one, You want to prevent your RFC should not goes to dump, Then you should keep exceptions in your RFC.

The following two exceptions are SAP Standard Exceptions,

system_failure = 1

communication_failure = 2

You can use these exceptions in your Program(Program which you are executing RFC),

After that RFC function module(if you kept these standard exceptions), Then system will come from RFC without dump incase any system failure or communication failure happen.

You can caught it using sy-subrc,

Everything ok then sy-subrc = 0.

System failure happens , then sy-subrc = 1

Communication failure happens, then sy-subrc = 2.

Answer for your Question: you need to developed report program/ class to handle exceptions, From where you are calling this RFM using CALL FUNCTION FM NAME DESTINATION DEST NAME.

Note: you can implement your custom exceptions also, while creating Function module itself.

Thanks,

Sivaraj Sadasivam.

Share
10 |10000 characters needed characters left characters exceeded
Raghu Govindarajan Nov 08, 2016 at 01:37 PM
0

Are you asking about an external non-SAP system to SAP? The RFC connector that is used for Visual Studio languages returns a code. For example the call may look like.

return_code = myRFCFunction.execute

This return_code will contain the equivalent of the sy-subrc in SAP. Since the code itself means nothing to the program on the other side, if it is possible return a detailed error message in a structure such as the BAPIRET2, with at the very least a message type and full error message. This will make life easier on both sides of the interface.

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Oh! In Visual Basic, it's the name of the exception which is returned, not the SY-SUBRC, so I thought it was the

the same in all RFC Client implementations (and so in the RFC SDKs).

1

That must be with the newer (than 20 years old) connectors :) I was using librfc32.dll with a C++ wrapper and then called that from VB or VBScript. Or, maybe it was lost in that C++ wrapper. I have never used the .NET connector so can't comment on that.

Well after writing that above, I decided to go check some old stuff...

The call itself only sends back a true or false (RfcCall). If it is false, then another API call has to be made to return more information on the error (RfcLastError). This second part was something I guess I never implemented back in the day! Here are some snippets from the 18 year old SAPRFC.H

/* -----------------------------------------
 * calling function modules
 * ---------------------------------------*/
/* @func
 * Calls an ABAP/4 function module via RFC.
 *
 * The structures <t RFC_PARAMETER> and  <t RFC_TABLE> contain
 * name and description of the 'exporting' parameters and tables
 * (internal ABAP/4 table) of the function's interface.
 * The function returns after the call request is send.
 * If the function returns RFC_OK, there is no guaranty, that
 * the call was already received by the target system.
 *
 * @rdesc
 * returns RFC_OK or RFC_FAILURE.
 *
 * @ex calling the function module  RFC_SYSTEM_INFO. |
 *
 *   RFC_RC             rfc_rc;
 *   RFC_PARAMETER      exporting[32];
 *   RFC_TABLE          tables[32];
 *
 *   exporting[0].name = NULL;
 *   tables[0].name    = NULL;
 *
 *   rfc_rc = RfcCall( handle, "RFC_SYSTEM_INFO",
 *                                  exporting,
 *                                  tables );
 *   if( rfc_rc != RFC_OK )
 *   {
 *      ....
 *
 */
RFC_RC SAP_API RfcCall(
 RFC_HANDLE       handle,    /* @parm connection handle.
                              */
 char *           function,  /* @parm function module to call.
                              */
 RFC_PARAMETER *  parameters,/* @parm 'exporting' parameters.
                              */
 RFC_TABLE     *  tables     /* @parm 'tables' parameters.
                              */
                      );
 /* @struct RFC_ERROR_INFO |
  * structure returned by <f RfcLastError> describing
  * the last RFC error that occurred.
  */
typedef struct
{
    char key[33];       /* @field error code to identify
                         * the error */
    char status[128];   /* @field state of the RFC
                             * connection
                                                 */
    char message[256];  /* @field text describing the error */
    char intstat[128];  /* @field internal description of the
                             * RFC connection
                                                 */
}
RFC_ERROR_INFO;
/*------------------------------------------------------
 * @func
 *
 * RfcLastError describes the last error reported by
 * some function of the RFC API.
 *
 * @rdesc
 * returns 1 if no error occurred and 0 elsewhere.
 *------------------------------------------------------
 */
int SAP_API RfcLastError(
  RFC_ERROR_INFO * error_info  /* @parm structure
                                * <t RFC_ERROR_INFO> describing the
                                * error.
                                */
                        );
1

Okay. I think it's the same thing between the 2 languages, but I had misinterpreted when you said "contain the equivalent of the sy-subrc": I thought you were saying that return_code was an integer to be used as a boolean (either 0 or 1)... In VB, there's such a return code, a boolean too. If it's "false", then we have to get the exception name with "theFunc.Exception" (string), and I guess it's the same for C with "RfcLastError.message". Here is a VB code :

dim returnFunc as Boolean

returnFunc = theFunc.Call

If returnFunc = False Then
MsgBox "Exception " + theFunc.Exception + " when accessing function in SAP ! "
Else
MsgBox "OK"
End if
1