Start of Content Area

RFC Server Program Working With RfcDispatch  Locate the document in its SAP Library structure

/* main program */

rfc_handle = RfcAccept (...); /* Accept RFC connection */

if (rfc_handle == RFC_HANDLE_NULL) /* Check return code */
{
rfc_error_handling("RfcAccept"); /* Handle error and get error */
return 1; /* specification via RfcLastError */
}

rfc_rc = RfcInstallFunction ( ‘ABC’ , abc_function ,...);
/* Install RFC function ‘ABC’ */
/* under the C-routine */
/* ‘abc_function’ */

if (rfc_rc != RFC_OK) /* Check return code */
{
rfc_error_handling("Install function ‘ABC’);
/* Handle error and get error */
return 1; /* specification via RfcLastError */
}

do /* Wait for call or execution of */
{
rfc_rc =
RfcDispatch (...); /* installed RFC functions until */

} while ( rfc_rc == RFC_OK); /* connection is closed or */ /* terminated */

RfcClose (...); /* Close RFC connection */

 

/* RFC function: ‘ABC’ */

static RFC_RC abc_function (RFC_HANDLE rfc_handle)
{
rfc_rc =
RfcGetData (...); /* Get associated RFC data */
if (rfc_rc != RFC_OK) /* Check return code */
{

rfc_error_handling("RfcGetData");
/* Handle error and get error */
return 1; /* specification via RfcLastError */
}

... /* Process RFC data */

rfc_rc = RfcSendData (...); /*Report result to ABAP program */
if (rfc_rc != RFC_OK) /* Check return code */
{
rfc_error_handling("RfcSendData");
/* Handle error and get error */
return 1; /* specification via RfcLastError */
}

return 0; /* Back to RFC Library */
}