RfcListen

RFC_RC SAP_API RfcListen(RFC_HANDLE handle);

can be used to check if there is an RFC request available.

You may not always want to wait for the answer to an RFC call. You can use the following function (instead of RfcReceive) to poll for incoming RFC events.

The function always returns immediately. If RfcListen returns RFC_OK, RfcReceive has to be called to handle the event. It is only possible to listen for one incoming RFC message at a time.

It is also possible to use RfcListen while waiting for a new RFC request by RfcDispatch with or without register mode (see RfcAccept). Because RfcListen will return immediately, it is recommended to use RfcWaitForRequest to wait for new RFC requests.

This function is defined in SAPRFC.H.

Return Values:

Function Parameter:

Using RfcListen while waiting for the answer of a remote function call:

RFC_RC rc;

rc = RfcCall(handle,...);

do
{
rc = RfcListen(handle);
if(rc == RFC_RETRY)
{
// while waiting for the RFC answer, do something...
...
}
} while (rc == RFC_RETRY);

if(rc == RFC_OK)
rc = RfcReceive(handle,...);

...

Using RfcListen and RfcDispatch:

RFC_RC rc;
RFC_HANDLE handle = RfcAccept(argv);

...

do
{
// Waiting for the next RFC request
for(rc = RFC_RETRY; rc == RFC_RETRY;)
{
rc = RfcListen(handle);
if(rc == RFC_RETRY)
{
// while waiting for the next RFC request, do something...
...
}
}
if (rc != RFC_OK)
break;

rc = RfcDispatch(handle);

} while(rc == RFC_OK);

RfcClose(handle);
exit(0);

A lot of calls to the RFC library "block", that is, they do not return until communications are complete. You can overcome this obstacle by using the RfcListen function: RfcListen checks whether any requests are present. If there are none, then programs can be started and run. If, however, a call is being processed, then RfcListen puts the results in a buffer and dispatches them, so that no blocking occurs. Thus, the results will not be lost.