Академический Документы
Профессиональный Документы
Культура Документы
The documentation may have changed since you downloaded the PDF. You can always find the latest information on SAP Help Portal.
Note
This PDF document contains the selected topic and its subtopics (max. 150) in the selected structure. Subtopics from other structures are not included.
© 2015 SAP SE or an SAP affiliate company. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose
without the express permission of SAP SE. The information contained herein may be changed without prior notice. Some software products marketed by SAP SE
and its distributors contain proprietary software components of other software vendors. National product specifications may vary. These materials are provided by
SAP SE and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be
liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express
warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty. SAP and other
SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE in Germany and other
countries. Please see www.sap.com/corporate-en/legal/copyright/index.epx#trademark for additional trademark information and notices.
Table of content
PUBLIC Page 1 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
Table of content
1 Writing RFC Programs in ABAP
1.1 Calling RFC Function Modules in ABAP
1.1.1 Introduction
1.1.2 RFC Calls
1.1.2.1 Parameters in Remote Calls
1.1.2.2 Calling Remote Functions Locally
1.1.2.3 Calling Remote Functions Back
1.1.2.4 RFC Call Restrictions
1.1.3 Things to Look Out for in Unicode
1.1.4 RFC Exceptions
1.1.4.1 Using Pre-Defined Exceptions for RFC
1.1.4.2 Exceptions That Cannot Be Handled
1.1.5 RFC Variants
1.1.5.1 Synchronous RFC (sRFC)
1.1.5.2 Asynchronous RFC (aRFC)
1.1.5.2.1 Call Properties of Asynchronous RFCs
1.1.5.2.2 Receiving Results from an Asynchronous RFC
1.1.5.2.3 Keeping Remote Contexts
1.1.5.2.4 Parallel Processing with Asynchronous RFC
1.1.5.2.5 CALL FUNCTION - STARTING NEW TASK
1.1.5.2.6 RECEIVE
1.1.5.2.7 WAIT UNTIL
1.1.5.2.8 aRFC Programming Example
1.1.5.3 Transactional RFC (tRFC)
1.1.5.3.1 CALL FUNCTION - IN BACKGROUND TASK
1.1.5.4 Queued RFC (qRFC)
1.2 Writing Remote Function Modules in ABAP
1.2.1 Steps for Implementing Remote Function Modules
1.2.2 Programming Tips
1.2.3 Debugging Remote Function Modules
PUBLIC Page 2 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
Writing RFC Programs in ABAP
Use
The following sections provide information about RFC programming in the ABAP environment:
● Calling RFC Function Modules in ABAP
● Writing Remote Function Modules in ABAP
1.1.1 Introduction
You can use the CALL FUNCTION statement to call remote functions, just as you would call local function modules. However, you must include an additional
DESTINATION clause to define where the function should run:
CALL FUNCTION Remotefunction
DESTINATION Dest
EXPORTING F1 = a1
F2 = a2
IMPORTING F3 = a3
CHANGING F4 = a4
TABLES t1 = ITAB
EXCEPTIONS …
The Remote Function field can be either a literal or a variable. The Dest field can be either a literal or a variable. Its value is a logical destination
("hw1071_53" for example) that is known to the local SAP System. You can define logical destinations in table RFCDES using transaction SM59 or by
choosing Tools → Administration ® Administration → Network → RFC Destinations .
Programming guidelines are available in the following topics:
Parameters in Remote Calls
Things to Look Out for in Unicode
Calling Remote Functions Locally
Calling Remote Functions Back
CALL FUNCTION RFC (RFC Variants)
RFC Calls
Use
In all SAP systems, CALL FUNCTION represents an integral part of the ABAP language. This statement executes a function (a function module) in the same
system.
Remote Function Call (RFC) is an extension of CALL FUNCTION in a distributed environment. Existing function modules can be executed using an RFC from a
remote system. This is done by adding a DESTINATION to the CALL FUNCTION statement:
PUBLIC Page 3 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
The destination parameter displays an entry in the RFCDES table. This entry contains all necessary parameters to connect to and log in the destination system.
Interface Functions
RFC frees the ABAP programmer from having to program his/her own communications routines. When you make an RFC call, the RFC interface takes care of:
● Converting all parameter data to the representation needed in the remote system. This includes character string conversions, and any hardware-dependent
conversions needed (for example, integer, floating point). All ABAP data types are supported.
● Calling the communication routines needed to talk to the remote system.
● Handling communications errors, and notifying the caller, if desired. (The caller requests notification using the EXCEPTIONS parameter of the CALL
FUNCTION statement.)
The RFC interface is effectively invisible to the ABAP programmer. Processing for calling remote programs is built into the CALL FUNCTION statement.
Processing for being called is generated automatically (in the form of an RFC stub) for every function module registered as remote. This stub serves as an
interface between the calling program and the function module.
A distinction is made between an RFC client and an RFC server. The RFC client is the instance that calls up the Remote Function Call to execute the function
that is provided by an RFC server. From here on, the functions that can be executed remotely are referred to as RFC functions, and the functions provided via
RFC API are referred to as RFC calls.
Context Management
Every remote function module call made using the RFC interface defines its own context in the target system. The function group of the function module is loaded
into an internal session of the context, and is retained. What this means is that, if repeated calls of function modules belonging to the same destination and the
same function group are made, the global data of this function group can be accessed collectively.
A connection and its context are retained until the connection is explicitly closed, or until the calling program is terminated. Function module
RFC_CONNECTION_CLOSE can be used to explicitly close a connection.
More Information
You can find detailed information about RFC calls here:
● Parameters in Remote Calls
● Calling Remote Functions Locally
● Calling Remote Functions Back
● RFC Call Restrictions
● RFC Variants
TABLES Parameters
The actual table is transferred, but not the table header. If you do not specify a table parameter, the called function module uses an empty table.
The RFC uses a delta managing mechanism to minimize network load during parameter and result transfer. Internal ABAP tables can be used as parameters for
function module calls. When a function module is called locally, a parameter table is transferred “by reference". This means that you do not have to create a new
local copy. RFC does not support transfer “by reference”. Therefore, the entire table must be transferred back and forth between the RFC client and the RFC
server. When the RFC server receives the table entries, it creates a local copy of the internal table. Only delta information is then returned to the RFC client.
However, this information is not returned to the RFC client every time a table operation occurs. Instead, all collected delta information is transferred at once when
the function returns to the RFC client.
The first time a table is transferred, it is given an object-ID and registered as a "virtual global table" in the calling system. This registration is kept alive as long as
call-backs are possible between calling and called systems. Thus, if multiple call-backs occur, the change-log can be passed back and forth to update the local
copy, but the table itself need only be copied once (the first time).
Remote Call:
● CALL FUNCTION...DESTINATION = 'NONE'
This is a remote call, even though DESTINATION = 'NONE'means that the remote function will run in the same system as the caller. As a remote call, the
function module runs in its own roll area, and parameter values are handled as for other remote calls (described in Parameter Handling in Remote Function
Calls.)
CALL FUNCTION Remotefunction
DESTINATION ‘NONE’
PUBLIC Page 4 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
EXPORTING F1 = a1
F2 = a2
TABLES t1 = ITAB
EXCEPTIONS ...
●
●
Local Call:
● CALL FUNCTION... [no DESTINATION used]
This is a local call, even though the function module is registered as remote. The module does not run in a separate roll area, and is essentially like a normal
function call. Parameter transfer is handled as for normal function modules. In particular, if the call leaves some EXPORTING parameters unspecified, it
terminates abnormally.
CALL FUNCTION Remotefunction
EXPORTING F1 = a1
F2 = a2
TABLES t1 = ITAB
EXCEPTIONS ...
You can also call a function for parallel processing in the same system. For more details, see Parallel Processing with Asynchronous RFCs.
In the diagram, remote function B of System B invokes remote function A in the calling System A.
PUBLIC Page 5 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
Things to Look Out for in Unicode
An MDMP system sends data in an unknown language. The Unicode system is therefore unable to determine the code page of this data for the conversion.
Unicode return characters cannot be converted into the required non-Unicode code page
The way in which the called Unicode system reacts to conversion errors depends on the profile parameters
rfc/cp_convert/ignore_error
rfc/cp_convert/conversion_char
Default: Ignore errors and replace non-convertible characters with character ‘#’.
The system making the call receives the exception COMMUNICATION_FAILURE with the message connection closed.
The Unicode system sends characters that cannot be converted into the required non-Unicode code page.
In the calling system, the reaction to conversion errors can be configured separately for each destination.
See transaction SM59 Defining Remote Destinations.
For the called system, conversion errors are not visible. The calling Unicode system identifies errors in the input data before it triggers an action on the called
page. The calling Unicode system only identifies errors in the output data if the called context has already been disconnected.
We strongly recommend that you assign a return value to these two exceptions for each RFC, and that you process these, otherwise a runtime
error may occur in the exception situations described.
PUBLIC Page 6 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
More Information
You can find further information about RFC exceptions under:
● Usnig Pre-Defined Exceptions for RFC
● Untreatable Exceptions
You can use MESSAGE only with the two system exceptions described here.
CALL_FUNCTION_DESTINATION_NO_T Missing communication type (I for internal connection, 3 for ABAP) when performing an
asynchronous RFC.
CALL_FUNCTION_NO_LB_DEST The specified destination (in load distribution mode) does not exist.
CALL_FUNCTION_NOT_REMOTE The function module being called is not flagged as "remotely" callable.
CALL_FUNCTION_REMOTE_ERROR While performing an RFC, an error occurred that has been logged in the calling system.
PUBLIC Page 7 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
6) No external user check
7) Invalid user type
8) Validity period of the user exceeded
CALL_FUNCTION_SYSCALL_ONLY RFC without valid user ID only allowed when calling a system function module. The
meaning of the error codes is the same as for
CALL_FUNCTION_SINGLE_LOGIN_REJ.
CALL_FUNCTION_TABINFO Data error (info internal table) during a Remote Function Call.
CALL_FUNCTION_TASK_IN_USE For asynchronous RFC only: The task name is already being used.
CALL_FUNCTION_TASK_YET_OPEN For asynchronous RFC only: The specified task is already open.
RFC Variants
This section provides a description of the various RFC variants. Depending on the required service properties, you can use the following RFC variants.
Synchronous RFC
Synchronous RFC (sRFC) performs a function call directly and waits for the reply from the called function module. The data is not written to the database before the
call. When using synchronous RFC, the called system must therefore be available. The call is only made once. If the called system is not available or problems
occur, the call fails (service property: At Most Once ).
Asynchronous RFC
PUBLIC Page 8 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
[{PERFORMING subr}|{CALLING meth} ON END OF TASK].
Despite its name, asynchronous RFC (aRFC) does not actually entail asynchronous function calls in the strict sense of the word. Although the function check
returns to the calling program directly after the call, the data is not actually written to the database. The call can therefore only take place on a directly available
system.
If the called system is not available, the call fails. Like the sRFC, the aRFC also only has service property At Most Once .
Background RFC
Unlike the aRFC, the background RFC (bgRFC) can be termed a "genuine" asynchronous communication method, which performs the function module called
in the RFC server exactly one time (service property: Exactly Once). The remote system need not be available at the time when the RFC client program is
executing a bgRFC. The bgRFC component stores the called RFC function, together with the corresponding data, in the SAP database under a unique transaction
ID (TID).
If a call is sent, and the receiving system is down, the call remains in the local queue until a later time. The calling dialog program can proceed without waiting to
see whether or not the remote call was successful. If the receiving system does not become active within a certain amount of time, the call is scheduled to run in
batch.
bgRFC is always used if a function is executed as a Unit . Within a given unit, all calls:
1. are executed in the order in which they are called
2. are executed in the same program context in the target system
3. run as a single transaction: they are either committed or rolled back as a unit.
Using bgRFC is always recommended if you want to maintain the transactional sequence of the calls in a unit. bgRFC can be either transactional (type T) or
queued (type Q). When using type Q, units belonging to multiple calls are also sent and processed in exactly the sequence in which they were written to the
database.
Transactional RFC
Transactional RFC is the predecessor of bgRFC for transactional RFC calls. It has the same service properties as bgRFC. tRFC can still be used in exactly the
same way as bgRFC. However, it is not possible to use the two methods in parallel.
Queued RFC
queued RFC (qRFC) is the predecessor of bgRFC type Q. qRFC also allows you to fix the processing sequence. The technology behind qRFC is based on tRFC.
The only difference is that function module TRFC_SET_QUEUE_NAME is executed before the actual tRFC call. This function module makes it possible to
serialize using queues.
We recommend using bgRFC, as it offers considerably better performance than tRFC and qRFC.
This statement causes a synchronous call of a remote-capable function module specified in func using the RFC interface. With the addition DESTINATION, the
destination is specified in dest. Character-type data objects are expected for func and dest. If the remotely called function is terminated, the calling program is
continued using the CALL FUNCTION statement.
PUBLIC Page 9 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
The parameter list has the following syntax:
These additions are used to assign actual parameters to the formal parameters of the function module, and return values to exceptions that are not class-based.
The additions have the same meanings as for the general function module call, the only differences being that, with the addition TABLES, only tables with flat
character types can be transferred, and that if a header line exists, it is not transferred.
The additions EXPORTING, IMPORTING and CHANGING allow you to transfer tables that have deep character types, deep structures, and strings.
For EXCEPTIONS, you can also specify an optional addition MESSAGE for the special exceptions SYSTEM_FAILURE and COMMUNICATION_FAILURE. If one
of these exceptions occurs, the first line of the corresponding short dump is entered in the field mess, which must be flat and of character-type.
Transferring tables using addition TABLES is considerably faster than using the other additions, as a binary format is used internally instead of an
XML format.
RECEIVE RESULTS FROM FUNCTION Remotefunction is used in a FORM routine to receive the results of an asynchronous RFC. The
following receiving parameters are available:
■ IMPORTING
■ TABLES
■ EXCEPTIONS
Addition KEEPING TASK keeps an asynchronous connection open after the results have been sent. The relevant remote context (role area) is kept for re-use
until the caller terminates the connection.
More Information
You can find more information about aRFC in:
● Call Properties of Asynchronous RFC
● Receiving Results from an Asynchronous RFC
● Keeping Remote Contexts
● Parallel Processing with Asynchronous RFC
● You can find a description of the various statements for aRFC in:
● CALL FUNCTION - STARTING NEW TASK
● RECEIVE
● WAIT UNTIL
● RFC Example
PUBLIC Page 10 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
Call Properties of Asynchronous RFCs
When you call a remote function with the optional suffix STARTING NEW TASK, the system starts the function in a new session. Rather than waiting for the
remote call to be completed, the user can resume processing as soon as the function module has been started in the target system.
The remotely called function module can, for example, display a new screen using CALL SCREEN, allowing the user to enter a dialog that connects him or her
directly to the remote system:
Client System
CALL FUNCTION Remotefunction
STARTING NEW TASK Taskname
DESTINATION Dest
Server System
FUNCTION Remotefunction.
CALL SCREEN 100.
ENDFUNCTION.
If you do not specify a destination, the asynchronous RFC mechanism starts a new session within the calling system.
■ If a function module does not return a result, you can leave out addition PERFORMING RETURN_FORM ON END OF TASK.
■ If an asynchronous call calls several consecutive function modules with the same destination, you must assign a different task name to each one.
■ A calling program that starts an asynchronous RFC with PERFORMING cannot switch role areas or change to an internal mode. This is because
the asynchronous function module call reply cannot be passed on to the relevant program. You can perform a role area switch with SUBMIT or
CALL TRANSACTION.
■ If the calling program that executed the asynchronous call is terminated, even though it is awaiting replies, these replies from the asynchronous call
cannot be delivered.
■ 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.
■ The program processing continues after WAIT if either the condition of a logical expression was satisfied by the subroutine that performs the task in
question, or a specified time period has been exceeded. You can find out more about the WAIT statement in the online help for ABAP editor.
■ Key word RECEIVE only exists with the function module call CALL FUNCTION Remotefunction STARTING NEW TASK Taskname. If the
function module does not return any results, you can leave this part.
■ The effect of statement SET USER-COMMAND ‘OKCD’ is exactly as if the user had entered the function in the command field and pressed
ENTER . The current positioning of the list and the cursor are thus taken into account.
PUBLIC Page 11 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
Call-backs are not supported.
The SET USER-COMMAND ‘OKCD’ statement replaces the REFRESH SCREEN command. REFRESH SCREEN is no longer maintained
and should therefore not be used.
You should use addition KEEPING TASK only if you want to re-use the current remote context for a subsequent asynchronous call.
Keeping a remote context increases storage load and impairs performance due to additional role area management in the system.
PUBLIC Page 12 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
in a predefined application server group of an SAP system.
Parallel processing is implemented with a special asynchonous RFC variant. With your own parallel processing applications, It is therefore
important that you only use the correct variant:
CALL FUNCTION STARTING NEW TASK DESTINATION IN GROUP.
By using other variants of asynchronous RFC, you are no longer protected by the built-in safeguards in the correct keyword, and can cause your
system to crash.
You can find details in:
● Prerequisites for Parallel Processing
● Function Modules and ABAP Keywords for Parallel Processing
● Managing Resources in Parallel Processing
PUBLIC Page 13 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
The addition first determines the amount of resources (work processes) currently available (i.e. in all servers or in a group of application servers, comparable with
login servers). The resources available for executing asynchronous calls on each application server depend on the current system load.
The applications developer is responsible for the availability of RFC groups in the production system (i.e. the customer's system). For details on how to maintain
the RFC groups, see Maintaining Group Destinations For Load Distribution.
After determining the available resources, the asynchronous call is executed in an available application server. If no resources are available at that particular
time, the system executes the exception routine RESOURCE_FAILURE (see the addition Exceptions). In the case of an asynchronous function module call, this
exception must be handled by the application program.
The process for determining available resources in an RFC group is as follows:
First, the system determines the length of the dispatcher queue for the relevant application server. If it is greater than 10% of the overall length, the server makes
no resources available. If it is smaller, the system makes available the current number of free dialog processes minus 2 (as a reserve instance for other
purposes, e.g. for logon to the system or administration programs). One application server must therefore have at least three dialog processes if RFC parallel
processing is taken into account.
■ At present, only one RFC group per program environment is supported for parallel execution of asynchronous calls. Using both additions
(DESTINATION IN GROUP Groupname and DESTINATION IN GROUP DEFAULT) in one program is not allowed.
■ Exception routine RESOURCE_FAILURE is only triggered in connection with asynchronous RFCs with the additions DESTINATION IN GROUP
Groupname and DESTINATION IN GROUP DEFAULT.
You are recommended (for performance and other reasons) to use an RFC group with sufficient resources for parallel processing of asynchronous calls
Syntax
CALL FUNCTION func STARTING NEW TASK task
[DESTINATION {dest|{IN GROUP {group|DEFAULT}}}]
parameter list
[{PERFORMING subr}|{CALLING meth} ON END OF TASK].
Additions:
1. ...DESTINATION IN GROUP { group |DEFAULT}
In dialog processing, note that the maximum number of six main sessions cannot be exceeded, else an error message is displayed.
Addition 1
... DESTINATION IN GROUP {group|DEFAULT}
Effect
Specifying IN GROUP as a destination allows you to execute multiple function modules in parallel on a predefined group of application servers in the current
SAP system.
For group, you must specify a data object of the type RZLLI_APCL from the ABAP Dictionary, one that is either initial, or one that includes the name of an RFC
server group created in transaction RZ12. When specifying DEFAULT, or if group is initial, all application servers that are currently available in the current SAP
system are used as a group. Only one RFC server group may be used within a program. During the first asynchronous RFC using the addition IN GROUP, the
specified RFC server group is initialized. For each asynchronous RFC where the group is specified, the most suitable application server is determined
automatically, and the called function module is executed on this.
If the function module cannot be executed on any application server, due to not enough resources being currently available, this leads to the predefined exception
RESOURCE_FAILURE, to which a return value can be assigned, in addition to the remaining RFC exceptions. For this exception, the addition MESSAGE is not
permitted.
● The parallel processing of function modules using the addition IN GROUP makes optimum use of the resources available, and is preferred to self-
PUBLIC Page 14 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
programmed parallel processing with destinations that are specified explicitly.
● An application server that is used as part of an RFC server group for parallel processing must have at least three dialog work processes, of which one is
currently free. Other resources such as requests in the queue, number of system logons and so on, are also taken into account, and are not allowed to
exceed certain limit values.
● To ensure that only those application servers that have enough resources are accessed, we recommend that you work with explicitly defined RFC server
groups instead of working with the addition DEFAULT.
● The function modules of the function group SPBT provide service functions for parallel processing, for example, initialization of RFC server groups,
determining the used destination, or temporarily removing an application server from an RFC server group.
Addition 2
... {PERFORMING subr}|{CALLING meth} ON END OF TASK
Effect
You can use this addition to specify either a subprogram subr or, as of Release 6.20, a method meth as a callback routine, which is executed after the
asynchronously called function module has finished. For subr, you have to directly specify a subprogram of the same program. For meth, you can enter the
same details as for the general method call.
The specified subprogram subr can have exactly one SING parameter of type clike only. The method meth must be public, and can have only one non-
optional input parameter p_task of type clike. When the RFC interface is called, this parameter is supplied with the task ID of the remotely called function that
was specified in the call in task. The results of the remote function can be received in the subprogram subr or method meth using the statement RECEIVE. In
the callback routine, no statements can be executed that cause the program run to terminate or end an SAP LUW. Statements for list output are not executed.
Prerequisite for executing a callback routine is that, after the remote function has ended, the calling program is still internally available. It is then executed the next
time the work process is changed. If the program has ended, or if it is part of a call sequence in the stack, then the callback routine is not executed. The
statement WAIT can be used to stop the program execution until certain or all callback routines have been executed.
Syntax
... [EXPORTING p1 = a1 p2 = a2 ...]
[TABLES t1 = itab1 t2 = itab2 ...]
[EXCEPTIONS exc1 = n1 exc2 = n2 ... [MESSAGE mess]
[OTHERS = n_others]].
Effect
These additions are used to assign actual parameters to the formal parameters of the function module, and return values to exceptions that are not class-based.
These additions have the same meaning as for the synchronous RFC. The only exception is that no values can be copied with IMPORTING and CHANGING.
1.1.5.2.6 RECEIVE
Syntax
RECEIVE RESULTS FROM FUNCTION func
parameter list
[KEEPING TASK].
Addition:
... KEEPING TASK
Effect
This statement can be used in a callback routine specified for the asynchronous RFC, in order to receive output parameters of an asynchronously called function
func in the parameter list parameter list, and to assign return values to exceptions.
If a function module is started multiple times in a row using asynchronous RFC, the execution sequence is not fixed, but depends on the system
availability instead.
Addition
... KEEPING TASK
Effect
PUBLIC Page 15 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
With the addition KEEPING TASK, the asynchronous RFC connection is retained, together with the context of the called function module. When a new call is made
with the same task ID, the same global data of the function group is addressed. Without the addition KEEPING TASK, an asynchronous RFC connection is
completed after the remote function has been executed and/or the results have been copied.
You should only use addition KEEPING TASK if the context of the called function module is required for other function calls.
RECEIVE - parameter_list
Syntax
... [IMPORTING p1 = a1 p2 = a2 ...]
[TABLES t1 = itab1 t2 = itab2 ...]
[EXCEPTIONS exc1 = n1 exc2 = n2 ... [MESSAGE mess]
[OTHERS = n_others]].
Effect
With these additions, the defined formal parameters of the function module specified in func are transferred to the actual parameters of the callback routine in the
calling program, and return values are assigned to non-class-based exceptions. The meaning of the additions is the same as for synchronous RFC. In particular,
the special exceptions SYSTEM_FAILUREand COMMUNICATION_FAILURE can be assigned return values. If no exceptions occur, RECEIVE sets the
contents of sy-subrc to 0.
Syntax
WAIT UNTIL log_exp [UP TO sec SECONDS].
Addition:
... UP TO sec SECONDS
Effect
This variant of the statement WAIT is only intended to be used after an asynchronous RFC with callback routines. It interrupts the program execution for as long as
the result of the logical expression log_exp is false. Any logical expression can be specified for log_exp.
If the result of log_exp is false, the program waits until a callback routine of a function that was previously called asynchronously has been executed, and then
checks the logical expression again. If the result of the logical expression is true, or if the callback routines of all functions that were previously called
asynchronously have been executed, then the program execution continues with the statement following WAIT.
Addition
... UP TO sec SECONDS
Effect
Specifying UP TO restricts the program interruption to a maximum number of seconds, specified in sec. A data object of type f is expected for sec, which must
contain a positive integer. After the specified time period has passed at the very latest, the program execution continues with the statement following WAIT.
System Fields
sy-subrc Meaning
PUBLIC Page 16 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
● The statement WAIT causes a switch in the work process, which is linked to the rollout and rollin of all loaded programs. For this reason, the time given in sec
must not be less than one second, to avoid burdening the system with too many work process switches.
● Each time the statement WAIT is used, a database commit is performed. WAIT must therefore not be used between Open SQL statements that open or close
a database cursor.
● There is also a variant of statement WAIT that can be used independently of asynchronous RFC.
Exceptions
Exceptions that cannot be processed
Cause: Undefined state of the statement WAIT
Runtime error: WAIT_ILLEGAL_CONTROL_BLOCK
Cause: Negative time entry for sec.
Runtime error: WAIT_ILLEGAL_TIME_LIMIT
Ten calls are made, each occurring in separate work processes due to them having different task IDs name. In the callback routine rfc_info, the completed
function modules are counted, and information about the target system is received.
Through using the addition GROUP DEFAULT, the execution is distributed across all application servers of the current system. If no more free work processes are
available after at least one successful call, the execution of the program is stopped until all function modules started up to that point have been completed. This
stoppage is limited to a maximum of 5 seconds.
After all function modules have been started, the system waits until all callback routines have been executed. After that, the internal table task_list filled there
is output. The output shows the sequence in which the individual tasks completed, and on which application server each of them was executed.
DO 10 TIMES.
indx = sy-index.
CONCATENATE 'Task' indx INTO name.
CALL FUNCTION 'RFC_SYSTEM_INFO'
STARTING NEW TASK name
DESTINATION IN GROUP DEFAULT
PERFORMING rfc_info ON END OF TASK
EXCEPTIONS
system_failure = 1 MESSAGE mess
communication_failure = 2 MESSAGE mess
resource_failure = 3.
CASE sy-subrc.
WHEN 0.
snd_jobs = snd_jobs + 1.
WHEN 1 OR 2.
MESSAGE mess TYPE 'I'.
WHEN 3.
IF snd_jobs >= 1 AND
exc_flag = 0.
exc_flag = 1.
WAIT UNTIL rcv_jobs > = snd_jobs
UP TO 5 SECONDS.
ENDIF.
IF sy-subrc = 0.
PUBLIC Page 17 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
exc_flag = 0.
ELSE.
MESSAGE 'Resource failure' TYPE 'I'.
ENDIF.
WHEN OTHERS.
MESSAGE 'Other error' TYPE 'I'.
ENDCASE.
ENDDO.
When using transactional RFC (tRFC), the called function module is executed exactly once in the called system (service property: Exactly Once ).
The remote system does not have to be available when the RFC client program is executing a tRFC. The tRFC component stores the called RFC function in the
SAP system database under a unique transaction number (TID), along with the corresponding data.
If a call is sent, and the receiving system is down, the call remains in the local queue. The calling dialog program can proceed without waiting to see whether the
remote call was successful. If the receiving system does not become active within a certain amount of time, the call is scheduled to run in batch.
Transactional RFCs use the suffix IN BACKGROUND TASK.
As with synchronous calls, the DESTINATION parameter defines a program context in the remote system. If you call a function module with the same destination
several times (or several function modules once), you can therefore access the global data for the called function module in the same context.
The system logs the remote call request in database tables ARFCSSTATE and ARFCSDATA with all parameter values. You can display the log file using
transaction SM58. When the calling program reaches a COMMIT WORK, the remote call is forwarded to the requested system.
All tRFCs with a single destination that occur between one COMMIT WORK and the next belong to a single logical unit of work (LUW).
PUBLIC Page 18 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
You can use transactional RFCs, for example, for complex processes that require updating of related database tables during different phases in a transaction.
Transactional RFC processing ensures that all the planned updates are carried out when the program reaches the COMMIT WORK statement.
Function modules that are called transactionally cannot have any EXPORT parameters in their definition, as a corresponding IMPORTING
parameter in the calling program causes syntax errors.
Note also that you cannot make asynchronous calls to functions that perform call-backs.
System Availability
If the remote system is unavailable, the SAP System uses the relevant transaction ID (TID) to schedule report RSARFCSE as a background processing variant.
This report, which forwards asynchronous calls for execution, is called repeatedly until it succeeds in connecting with the system in question.
When scheduled in batch, RSARFCSE runs automatically at set intervals (the default setting is for up to 30 attempts at 15 minute intervals). You can customize
this interval and the length of time the program should carry on trying for. Use enhancement programs SABP0000 and SABP0003 to do this.
To configure a destination, call transaction SM59, select the screen for a destination and choose Edit ® TRFC Options . This enables you to set the maximum
number of connection attempts and the intervals at which they are made.
If the system cannot be reached within the specified amount of time, the system stops calling RSARFCSE, and the status CPICERR is written to the
ARFCSDATA table. Within another specified time (the default is eight days), the corresponding entry in the ARFCSSTATE table will be deleted (this limit can also
be customized). It is still possible to start this type of entry manually in transaction SM59.
Further Information
● You can find a description of the statements for tRFC in:
● CALL FUNCTION IN BACKGROUND TASK
Syntax
CALL FUNCTION func IN BACKGROUND TASK
[DESTINATION dest]
parameter list
[AS SEPARATE UNIT].
Addition:
... AS SEPARATE UNIT
Effect
Transactional call of a remote-capable function module specified in func using the RFC interface. You can use the addition DESTINATION to specify an
individual destination in dest. If the destination has not been specified, the destination NONE is used implicitly. Character-type data objects are expected for
func and dest.
When the transactional call is made, the name of the called function, together with the destination and the actual parameters given in parameter list, are
registered for the current SAP LUW in the database tables ARFCSSTATE and ARFCSDATA of the current SAP system under a unique transaction ID (abbreviated
as TID, stored in a structure of type ARFCTID from the ABAP Dictionary, view using transaction SM58). Following this registration, the program making the call is
continued by way of the statement CALL FUNCTION.
When executing the COMMIT WORK statement, the function modules registered for the current SAP LUW are started in the sequence in which they were
PUBLIC Page 19 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
registered. The statement ROLLBACK WORKdeletes all previous registrations of the current SAP LUW.
If the specified destination is not available for COMMIT WORK, an executable called RSARFCSE is started in the background. This attempts to start the functional
modules registered for an SAP LUW in their destination, every 15 minutes up to a total of 30 times. You can make changes to these parameters using transaction
SM59. If the destination does not become available within the given time, this is noted in the database table ARFCSDATA as a CPICERR entry. By default, this
entry in database table ARFCSSTATE is deleted after 8 days.
Addition
... AS SEPARATE UNIT
Effect
When using the addition AS SEPARATE UNIT, the relevant function module is executed in a separate context, a context in which the global data of the function
group is not influenced by previous calls. Each function module that is registered with the addition AS SEPARATE UNIT is given a separate transaction ID.
Without the addition AS SEPARATE UNIT, the usual description is applicable for the context of the called function modules. What this means is that, when using
the same destination for multiple calls of function modules belonging to the same function group, the global data of this function group is accessed collectively.
You can use the function module ID_OF_BACKGROUNDTASK to define the transaction ID (TID) of the current SAP LUW, according to a
transactional RFC.
The transactional RFC (tRFC) is suitable for realizing LUWs in distributed environments (a typical application is ALE). Here it must be noted that
although executing the function modules within a transaction ID is predefined, the sequence of the LUWs on the RFC servers does not necessarily
correspond to the sequence of SAP LUWs in the RFC client. To achieve a serialization on the RFC servers as well, the tRFC can be enhanced to
queued RFC ( qRFC). For this, you can call function module TRFC_SET_QUEUE_NAME before a transactional RFC.
Effect
These additions are used to assign actual parameters to the formal parameters of the function module. The significance of the additions is the same as for
synchronous RFC with the exception that no values can be copied with IMPORTING and CHANGING, and no return values can be allocated to exceptions that
are not class-based.
Scenario 1: tRFC
This scenario is appropriate is the data being sent is independent of each other. A calling application (client) in system 1 uses a tRFC connection to a called
application (r server) in system 2. In this scenario, data is transferred by tRFC, meaning that each function module sent to the target system is guaranteed to be
executed once only. You cannot define the sequence in which the function modules are processed or the time when this happens. If an error occurs during the
transfer, a batch job is scheduled, which sends the function module again after 15 minutes.
Scenario 2: qRFC with outbound queue
In this scenario, the sending system uses an outbound queue to serialize the data being sent. This means that mutually dependent function modules are placed in
PUBLIC Page 20 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
the outbound queue of the sending system. When the data is sent, the exact order is kept to, and the calls are sent to the target system exactly once in order .
The server system coding does not need to be changed in order to process qRFC calls. However, it must be tRFC enabled.
Scenario 3: qRFC with inbound queue (and outbound queue)
In this scenario, as well as an outbound queue in the sender system (client), there is also an inbound queue in the target system (server). If a qRFC with inbound
queue exists, this always means that an outbound queue exists in the sender system.
The inbound queue only processes as many function modules as the system resources in the target system (server) at that time allow. This prevents a server
being blocked by a client. A scenario with just one inbound queue in the server system is not possible, since the outbound queue is needed in the client system
in order to set the order and to prevent individual applications from blocking all work processes in the client system.
More Information
You can find detailed information about qRFC in:
● Queued Remote Function Call (qRFC)
If required, you can find more detailed information about function modules under:
Function Builder
To view the entire directory tree of the function module documentation, choose Synchronize from the upper left part of the screen. You can
then navigate through the entire function module documentation.
Define the destination of the RFC server in the RFC client system that calls the remote function.
Either you or your system administrator can maintain table RFCDES in transaction SM59 ( Tools ® Administration, Administration ® Network
® RFC Destinations ). For more detailed information, see Maintaining Remote Destinations.
You can then use this destination in your programs to call the function module.
Declaring Parameters
For normal (non-remote) function modules, if a parameter is not defined like an ABAP Dictionary field, it takes the data type of the actual parameter used at run-
time. However, a remote function module does not have this information available. You therefore need to define all parameter fields in a remote function module as
PUBLIC Page 21 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
reference fields, that is, they must refer to an ABAP Dictionary field with LIKE. (This applies to IMPORT, EXPORT, CHANGING and TABLES parameters.)
For character structures or fields, the caller's parameters need not be as long as expected by the called program. When incoming parameters are shorter, RFC
simply pads them with blanks. This means that the ABAP Dictionary definition of character parameters need not be exactly the same on the calling and called
sides. (However, the caller's parameters may not be longer than expected on the called side).
There are two restrictions on writing remote functions that are to be called transactionally.
● Transactional calls cannot return parameter values. As a result, the interface for these functions should not specify any EXPORT parameters.
● Functions that run transactionally may not perform call-backs: the caller's context does not necessarily still exist when the call-back is relayed
back to the original system.
Exceptions
You can trigger exceptions in a remote function just as you would in a locally called function.
Since the system raises COMMUNICATION_FAILURE and SYSTEM_FAILURE internally, there is no reason for you to trigger them in your function module.
PUBLIC Page 22 of 22
© 2014 SAP SE or an SAP affiliate company. All rights reserved.