RECEIVE RESULTS FROM FUNCTION

RECEIVE Syntax Diagram

Additions:

1. ... KEEPING TASK
2. ... IMPORTING p1 = f1 ... pn = fn
3. ... TABLES p1 = itab1 ... pn = itabn
4. ... EXCEPTIONS except1 = rc1 ... exceptn = rcn

Effect

Used within a FORM routine to receive the results of an asynchronous function module call ( CALL FUNCTION func STARTING NEW TASK task name) as IMPORTING or TABLES parameters. In addition, the FORM routine must have a placeholder (such as USING task name) to receive the task name (see example below). The FORM routine is used only to receive and execute simple ABAP statements. It must not contain any statements that interrupt the program execution (for example, CALL SCREEN, CALL DIALOG, CALL TRANSACTION, SUBMIT, COMMIT WORK, WAIT , Remote Function Calls, CPIC calls, etc.), or output warning and information messages with the command MESSAGE.

Notes

This key word occurs only with the function module call CALL FUNCTION func STARTING NEW TASK task name. If the function module returns no results, this part need not be defined.

This key word is new in Release 3.0. Therefore, both partner systems (client and server) must have Release 3.0 (or higher) of the R/3 System.

You can use the WAIT statement with PERFORMING form ON END OF TASK to wait for the reply to a previously started asynchronous call. In this case, WAIT must be in the same program context.

Replies to asynchronous calls can only be received if there is a roll area switch or through WAIT (dialog and background processing).

If the calling program responsible for the asynchronous calls is terminated even though it is expecting replies, there is no way these replies to the asynchronous calls can be handled.

The FORM routine in which the evaluation of the task takes place should only be used to receive the results of the asynchronous task. Moreover, list output in the FORM routine is suppressed if there is a WRITE statement.

Effect

This addition prevents the asynchronous connection from being terminated once the results have been received. The remote context (roll area) is retained until the calling routine terminates. This allows you to address and use the same context by specifying the same task name, and means that you can always address the same roll area.

Notes

You should only use this addition if you want to use the remote context in a further asynchronous call. Otherwise, the context (and the roll area) remain in the system until the calling routine is terminated. As well as increased memory requirements, this also leads to a loss of performance, because the system needs increased time to manage the roll area.

If the remote function module contains dialogs (lists or dialog screens), the screen output remains active until the calling program ends. If you call the remote function module in debugging ode, the remote debugging dialog also remains active until the calling dialog ends.

Effect

IMPORTING returns the values of fields and field strings from the function module to the calling program. In the function module, the formal parameters are defined as export parameters. You can pass any number of export parameters.

Effect

The TABLES statement contains references to internal tables.

Addition 4

... EXCEPTIONS except1 = rc1 ... exceptn = rcn

Effect

As with function module calls that contain the addition DESTINATION, two special system exceptions can be handled here:

SYSTEM_FAILURE

This is triggered if there is a system crash on the receiving side.

COMMUNICATION_FAILURE

This is triggered if there is a problem establishing the connection or if a communication error occurs.

In both cases, you can use the optional addition

... MESSAGE mess

to get a description of the error.

Note

In principle, these two system exceptions should always be present with asynchronous function module calls and when results are received.

Example

DATA: INFO LIKE RFCSI, 
* Result of RFC_SYSTEM_INFO function 
	MSG(80) VALUE SPACE. 
* Exception handling 
	RET_SUBRC LIKE SY-SUBRC. 
* Handling of SY-SUBRC 
 
CALL FUNCTION 'RFC_SYSTEM_INFO' 
	 STARTING NEW TASK 'INFO' 
	 PERFORMING RETURN_INFO ON END OF TASK 
	 EXCEPTIONS 
	 COMMUNICATION_FAILURE = 1 MESSAGE MSG 
	 SYSTEM_FAILURE		= 2 MESSAGE MSG.
 
IF SY-SUBRC = 0. 
  WRITE: 'Wait for reply'. 
ELSE. 
  WRITE MSG. 
ENDIF. 
... 
AT USER-COMMAND. 
* Return from FORM routine RETURN_INFO via SET USER-COMMAND 
 IF SY-UCOMM = 'OKCD'. 
   IF RET_SUBRC = 0. 
	 WRITE: 'Destination =', INFO-RFCDEST. 
   ELSE. 
	 WRITE MSG. 
   ENDIF. 
 ENDIF. 
... 
FORM RETURN_INFO USING TASKNAME. 
 
  RECEIVE RESULTS FROM FUNCTION 'RFC_SYSTEM_INFO' 
	IMPORTING  RFCSI_EXPORT = INFO 
	EXCEPTIONS 
		 COMMUNICATION_FAILURE = 1 MESSAGE MSG 
		 SYSTEM_FAILURE		= 2 MESSAGE MSG. 
  RET_SUBRC = SY-SUBRC. "Set RET_SUBRC 
  SET USER-COMMAND 'OKCD'. "Set user command 
ENDFORM.

Note

As the above example shows, you can use the SET USER-COMMAND statement in the FORM routine that evaluates the tasks to trigger a list event. You can then process this in the AT USER-COMMAND event of the main program (e.g. to manage asynchronous calls). However, it is not guaranteed that after each SET USER-COMMAND the <DS.ABAP.AT_LIST_EVENT>AT USER- COMMAND will be executed.

During screen processing, the effect of the SET USER-COMMAND statement is such that the last active PAI module of the previous screen is processed using the specified user command as command field input. However, it is not guaranteed that after each <DS.ABAP.SET_USER-COMMAND>SET USER-COMMAND the User-Command processing will be run. This statement loses its effectiveness in the debugging mode (this means that event SET USER-COMMAND is not processed).

To manage asynchronous function module calls (particularly with background processing), you can use the WAIT command. Then, the above example would have the following appearance if you inserted WAIT instead of SET USER-COMMAND:

Example

DATA: INFO LIKE RFCSI, 
* Result of RFC_SYSTEM_INFO function 
	MSG(80) VALUE SPACE, 
* Exception handling 
	RET_SUBRC LIKE SY-SUBRC, 
* Handling of SY-SUBRC 
	SEMAPHORE(1) TYPE C VALUE SPACE. 
* Flag for receiving asynchronous results 
 
CALL FUNCTION 'RFC_SYSTEM_INFO' 
	 STARTING NEW TASK 'INFO' 
	 PERFORMING RETURN_INFO ON END OF TASK 
	 EXCEPTIONS 
	 COMMUNICATION_FAILURE = 1 MESSAGE MSG 
	 SYSTEM_FAILURE		= 2 MESSAGE MSG.
 
IF SY-SUBRC = 0. 
  WRITE: 'Wait for reply'. 
ELSE. 
  WRITE MSG. 
ENDIF. 
... 
CLEAR SEMAPHORE. 
WAIT UNTIL SEMAPHORE = 'X'. 
* Return from FORM routine RETURN_INFO 
IF RET_SUBRC = 0. 
   WRITE: 'Destination =', INFO-RFCDEST. 
ELSE. 
   WRITE MSG. 
ENDIF. 
... 
FORM RETURN_INFO USING TASKNAME. 
 
  RECEIVE RESULTS FROM FUNCTION 'RFC_SYSTEM_INFO' 
	IMPORTING  RFCSI_EXPORT = INFO 
	EXCEPTIONS 
		 COMMUNICATION_FAILURE = 1 MESSAGE MSG 
		 SYSTEM_FAILURE		= 2 MESSAGE MSG. 
  RET_SUBRC = SY-SUBRC. "Set RET_SUBRC 
  SEMAPHORE = 'X'. "Set semaphore 
ENDFORM.