RfcDispatch

The routine RfcDispatch receives a single RFC request and causes it to be executed. The calling syntax is:

RFC_RC SAP_API RfcDispatch(RFC_HANDLE handle);

Use RfcDispatch after calling RfcAccept, or after receiving an RFC_CALL return code from RfcReceive or RfcCallReceive. In order to dispatch RFC requests, you must also have registered the remote function with RfcInstallFunction (or RfcWinInstallFunction).

This function internally calls the registered function corresponding the the RFC call. The return code of the registered function is again returned by RfcDispatch.

The sample programs provide examples of how to use RfcDispatch. (In particular, the program rfcexec.c which is included in the RFC SDK) implements an RFC server.)

This function is defined in SAPRFC.H.

Return Values:

  • returns RFC_OK or other RFC_RC return code

Function Parameter:

  • handle

handle to the RFC connection

Comments:

There are some function modules which are always offered automatically when using RfcDispatch. These are:

  • RFC_DOCU

Get a list of the installed function modules.

  • RFC_PING

Do nothing (used for connection test).

  • RFC_SYSTEM_INFO

Deliver some information to the RFC library used.

A typical RFC server:

int main(int argv, char** argv)
{
RFC_HANDLE handle;
RFC_RC rc;

handle = RfcAccept(argv);
if(handle == RFC_HANDLE_NULL)
{
... error processing
return 1;

}

rc = RfcInstallFunction(...);
if(rc != RFC_OK)
{
error processing
return 1;
}

do
{
rc = RfcDispatch(handle);
}
while(rc == RFC_OK);

RfcClose(handle);

return 0;

}

When RfcDispatch(handle) calls a C-function, it passes the function a different handle than the handle passed RfcDispatch(). Trying to do an RfcGetData() on the original handle passed to RfcDispatch() malfunctions. This is due to the internal structure of the transactional RFC: Since the function call is done indirectly, and not directly, from librfc, it internally passes RFC handles of its own in order to carry out the RFC calls.