Use More Information Related Information: On This Page
Use More Information Related Information: On This Page
On this page
Use
More Information
Related Information
Use
Communication between applications of different systems in the SAP
environment includes connections between SAP systems as well as
between SAP systems and non-SAP systems. Remote Function Call
(RFC) is the standard SAP interface for communication between SAP
systems. RFC calls a function to be executed in a remote system.
There is now a whole series of different RFC variants, each of which has
different properties and is used for a specific purpose.
Synchronous RFC
The first version of RFC is synchronous RFC (sRFC). This type
of RFC executes the function call based on synchronous
communication, meaning that the systems involved must both be
available at the time the call is made.
Asynchronous RFC (aRFC)
Despite its name, aRFC is not really an asynchronous type of
communication, as it does not meet the conditions for this. With sRFC,
for example, the called system must be available during the call.
The main characteristics of aRFC are as follows:
Function control returns to the calling program directly after the call.
The parameters of asynchronous RFCs are not logged to the database,
but sent directly to the server.
Asynchronous RFCs allow the user to carry on an interactive dialog with
the remote system.
When the caller starts an aRFC, the called server must be available to
accept the request.
The calling program can receive results from the asynchronous RFC.
Using aRFC is always a good idea when real-time communication is
established with a remote system, where processing in the calling
program should not be interrupted until the results of the called
function module have been obtained (the term asynchronous is used in
this sense here).
Transactional RFC (tRFC)
Transactional RFC (tRFC, previously known as asynchronous RFC) is
a genuine asynchronous communication method that - unlike aRFC -
executes the called function module just once in the RFC server. The
remote system need not be available at the time when the RFC client
program is executing a tRFC. The tRFC 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.
tRFC is always used if a function is executed as a Logical Unit of
Work (LUW). Within a LUW, all calls are
executed in the order in which they are called
executed in the same program context in the target system
are executed in a single transaction: they are either committed or rolled
back as a unit.
Implementation of tRFC is recommended if you want to maintain the
transactional sequence of the calls.
Disadvantages of tRFC
tRFC processes all LUWs independently of one another. Due to the
amount of activated tRFC processes, this procedure can reduce
performance significantly in both the send and the target systems.
In addition, the sequence of LUWs defined in the application cannot be
kept. It is therefore impossible to guarantee that the transactions will
be executed in the sequence dictated by the application. The only thing
that can be guaranteed is that all LUWs are transferred sooner or later.
Queued RFC (qRFC)
To guarantee that multiple LUWs are processed in the order specified
by the application, tRFC can be serialized using queues (inbound and
outbound queues). This type of RFC is called queued RFC (qRFC).
qRFC is therefore an extension of tRFC. It transfers an LUW
(transaction) only if it has no predecessors (based on the sequence
defined in different application programs) in the participating queues.
Implementation of qRFC is recommended if you want to guarantee that
several transactions are processed in a predefined order.
Background RFC (bgRFC)
bgRFC is the successor to tRFC and qRFC, with significant improvements
in terms of performance and functionality.
Note
Using bgRFC instead of tRFC and qRFC is therefore urgently
recommended.
Local Data Queue (LDQ)
The LDQ is a special case in RFC communication. Here, no data is sent
actively by the system. Instead, it is stored locally until being called by
an external application (such as a mobile device) according to the pull
principle.
Note
All asynchronous RFC procedures (tRFC, qRFC, bgRFC, LDQ) form part of
the Background Communication concept. As these procedures have
certain characteristics that set them apart from "normal" RFC, they are
described in detail separately.
Data transfer
All RFC types are transferred by means of CPI-C or TCP/IP. They
constitute a kind of gateway communication.
Caution
For information security-relevant aspects of communication with RFC,
see the RFC/ICF Implementation Guide.
More Information
Follow these links to find more information on RFC-related topics:
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 Remotefunction field can either be a literal or a variable. The field Dest can be either a
literal or a variable: its value is a logical destination (for example, "hw1071_53") known to the
local SAP System. You can define logical destinations in table RFCDES using transaction SM59,
or using the following menu path: Tools Administration,
Administration Network RFC Destinations.
Use
When you make a remote function call, the system handles parameter transfer differently than
it does with local calls.
Process
TABLES Parameters
The actual table is transferred, but not the table header. If a table
parameter is not specified, an empty table is used in the called
function.
The RFC uses a delta managing mechanism to minimize network load
during parameter and result passing. Internal ABAP tables can be used
as parameters for function module calls. When a function module is
called locally, a parameter tables 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. Then only delta information is returned to
the RFC client. This information is not returned to the RFC client every
time a table operation occurs, however; instead, all collected delta
information is passed on at once when the function returns to the
client.
The first time a table is passed, 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).
RFC Exceptions
On this page
Use
More Information
Use
For the external function call, you can use the addition EXCEPTIONS of the statement CALL
FUNCTION to assign return values to the exceptions defined in the interface of the called
function module.
In addition to the exceptions defined in the interface of the called function module, an external
function call may trigger the following predefined exceptions:
Exception SYSTEM_FAILURE occurs if a runtime error occurs during execution of the remotely-
called function module.
The exception COMMUNICATION_FAILURE occurs if the connection cannot be made to the
partner system, or if the connection is broken during communication.
Note
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.
Use
ARFC are similar to transactional RFCs, in that the user does not have to wait for their
completion before continuing the calling dialog. There are three characteristics, however, that
distinguish asynchronous RFCs from transactional RFCs:
When the caller starts an asynchronous RFC, the called server must be available to accept the
request.
The parameters of asynchronous RFCs are not logged to the database, but sent directly to the
server.
Asynchronous RFCs allow the user to carry on an interactive dialog with the remote system.
The calling program can receive results from the asynchronous RFC.
You can use asynchronous remote function calls whenever you need to establish
communication with a remote system, but do not want to wait for the function's result before
continuing processing. Asynchronous RFCs can also be sent to the same system. In this case, the
system opens a new session (window). You can then switch back and for between the calling
dialog and the called session
To start a remote function call asynchronously, use the following syntax:
CALL FUNCTION Remotefunction STARTING NEW TASK Taskname
DESTINATION ...
EXPORTING...
TABLES ...
EXCEPTIONS...
Note
The following calling parameters are available:
TABLES
passes references to internal tables. All table parameters of the function module must contain
values.
EXPORTING
passes values of fields and field strings from the calling program to the function module. In the
function module, the corresponding formal parameters are defined as import parameters.
EXCEPTIONS
See Using Predefined Exceptions for RFCs
RECEIVE RESULTS FROM FUNCTION Remotefunction is used within a FORM routine to
receive the results of an asynchronous remote function call. The following receiving parameters
are available:
IMPORTING
TABLES
EXCEPTIONS
The addition KEEPING TASK prevents an asynchronous connection from being closed after
receiving the results of the processing. The relevant remote context (roll 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 RFCs
Receiving Results from an Asynchronous RFC
Keeping the Remote Context
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
Use
To achieve a balanced distribution of the system load, you can use destination additions to
execute function modules in parallel tasks in any application server or in a predefined
application server group of an SAP system.
Caution
Parallel-processing is implemented with a special variant of asynchonous RFC. 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.
Using other variants of asynchronous RFC circumvents the built-in safeguards in the correct
keyword, and can bring your system to its knees
Details are discussed in the following subsections:
Prerequisites for Parallel Processing
Function Modules and ABAP Keywords for Parallel Processing
Managing Resources in Parallel Processing
Process
Prerequisites for Parallel Processing
Before you implement parallel processing, make sure that your application and your SAP
system meet these requirements:
Logically-independent units of work:
The data processing task that is to be carried out in parallel must be logically independent of
other instances of the task. That is, the task can be carried out without reference to other
records from the same data set that are also being processed in parallel, and the task is not
dependent upon the results of others of the parallel operations. For example, parallel
processing is not suitable for data that must be sequentially processed or in which the
processing of one data item is dependent upon the processing of another item of the data. By
definition, there is no guarantee that data will be processed in a particular order in parallel
processing or that a particular result will be available at a given point in processing.
ABAP requirements:
The function module that you call must be marked as externally callable. This attribute is
specified in the Remote function call supported field in the function module definition
(transaction SE37).
The called function module may not include a function call to the destination "BACK".
The calling program should not change to a new internal session after making an
asynchronous RFC call. That is, you should not use SUBMIT or CALL TRANSACTION in such a
report after using CALL FUNCTION STARTING NEW TASK.
You cannot use the CALL FUNCTION STARTING NEW TASK DESTINATION IN GROUP keyword to
start external programs.
System resources:
To process tasks from parallel jobs, a server in your SAP system must have at least 3 dialog work
processes. It must also meet the workload criteria of the parallel processing system: Dispatcher
queue less than 10% full, at least one dialog work process free for processing tasks from the
parallel job.
Managing Resources in Parallel Processing
You use the following destination additions to perform parallel execution of function modules
(asynchronous calls) in the SAP system:
In a predefined group of application servers:
CALL FUNCTION Remotefunction STARTING NEW TASK Taskname
DESTINATION IN GROUP Groupname
In all currently available and active application servers:
CALL FUNCTION Remotefunction STARTING NEW TASK Taskname
DESTINATION IN GROUP DEFAULT
The addition 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 depends 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). Thus, one application server must have at least 3 dialog processes if RFC parallel
processing is taken into account.
Example
Sample Code
*&---------------------------------------------------------------------*
*& Report ZPAW_RP_PARALLEL_PROCESSING
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZPAW_RP_PARALLEL_PROCESSING.
FUNCTION fm.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" EXPORTING
*" ...
*" CHANGING
*" VALUE(STARTED) TYPE I
*" VALUE(STOPPED) TYPE I
*"----------------------------------------------------------------------
ADD 1 TO started.
" do something
ADD 1 TO stopped.
ENDFUNCTION.
*&---------------------------------------------------------------------*
*& Report RAL_SPBT_DEMO
*&---------------------------------------------------------------------*
*& Releases up to SAP NetWeaver 7.55 (ABAP Platform 2020)
*&---------------------------------------------------------------------*
REPORT spbt_demo_old.
jobs_running = 0.
jobs_done = 0.
WAIT FOR ASYNCHRONOUS TASKS UNTIL jobs_running = job_count AND jobs_done = job
_count.
EXIT.
RECEIVE
Use
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.
Note
If a function module is started multiple times in a row using asynchronous RFC, the execuction
sequence is not fixed, instead it depends in the system availability.
Addition
... KEEPING TASK
Effect
With the addition KEEPING TASK, the asynchronous RFC connection is retained, as is the
context of the called function module along with it. 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 finished after the remote function is executed or the
results are copied.
Note
You must only use the 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 a synchronous RFC. In particular, the special exceptions SYSTEM_FAILURE and
COMMUNICATION_FAILURE can be assigned return values. If no exceptions occur, RECEIVE sets
the contents of sy-subrc to 0.
WAIT UNTIL
Use
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 seconds. 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
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. For this
reason, WAIT must not be used between Open SQL statements that open or close a database
cursor.
There is also one variant of the statement WAIT that can be used independently of the
asynchronous RFC.
Exceptions
Exceptions That Cannot Be Handled
Cause: Undefined status of WAIT statement
Runtime error: WAIT_ILLEGAL_CONTROL_BLOCK
Cause: Negative time entry for sec.
Runtime error: WAIT_ILLEGAL_TIME_LIMIT
Use
The qRFC (queued Remote Function Call) is an extension of the tRFC. It
allows you to serialize tRFC calls using a queue.
The tRFC call is preceded by function module TRFC_SET_QUEUE_NAME,
which starts the serialization. The calls are then actually dispatched by a
tRFC call.
The qRFC can be made with an outbound queue (serialization at the
calling application) and also an inbound queue (serialization at the
called application).
This results in the following scenarios for transactional data transfer:
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 executed, nor the time of execution. 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 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. Exactly Once In
Order).
Note
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 (& 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)
Background Communication
On this page
Use
More Information
Use
Background communication is a term used to describe various
asynchronous communication methods. With all the methods, the data
that is exchanged between calling and called applications is recorded in
the database. The database can be used both by the caller and the
called application.
From the database, the data is transferred according to either
the push principle or the pull principle. With the push principle, the
transfer from the database is triggered by one or more schedulers.
With the pull principle, the receiver (the called application) collects the
data from the database on its own. This procedure is also known as
a no-send scenario in SAP terminology.
In all cases, the system ensures the data is transferred once only with
all the procedures ( exactly once or transactional in SAP terminology).
The caller can also determine precise adherence to the call order when
the data is transferred to the called application ( exactly once in
order or queued in SAP terminology).
Three current methods of background communication are described in
the sections below:
qRFC ( queued remote function call)
bgRFC ( background remote function call)
LDQ ( local data queue)
bgRFC and LDQ are the successors of the methods qRFC and tRFC.
Unlike tRFC and qRFC, bgRFC and LDQ offer the following advantages:
Improved scalability
Less use of system resources
More detailed configuration options
Clear functional separation between the push and pull principles, as
well as between the transactional and queued methods.
Better for the developers in terms of their complete, object-oriented
API and their integration into the ABAP programming language
With the bgRFC, solutions can be developed that process
either transactional or queued methods in accordance with
the push principle.
The LDQ offers a queued method in accordance with the pull principle.
Caution
SAP strongly recommends not using the qRFC ( queued, push principle),
the qRFC no-send ( queued, pull principle), or the
tRFC ( transactional, push principle) in new applications on the basis of
the disadvantages described above.
More Information
For more information on the individual background
communication methods, see:
Queued Remote Function Call (qRFC)
bgRFC (Background RFC)
Local Data Queue (LDQ)
bgRFC Configuration
On this page
Use
Process
More Information
Use
To ensure the bgRFC communication functions optimally, various settings can or must be
made.
You can perform all the relevant steps using the transaction SBGRFCCONF.
Note
To perform bgRFC configuration tasks, you need authorizations from authorization
object S_BGRFC.
Process
You have the following configuration options:
Basic settings
Creating a Supervisor Destination
The bgRFC cannot function if a supervisor destination has not been defined.
Recreate inbound destinations
You can create separate inbound destinations for each application to distribute the load.
Assign queue prefixes to inbound destinations
You need to make these settings in order to assign existing queue prefixes for a "classic" qRFC
to an inbound destination, therefore ensuring that bgRFC works without errors.
Maintain logon server groups
By assigning server groups to an inbound destination you can distribute the load.
Scheduler Configuration
To optimize the bgRFC function in terms of system performance you can make various settings
for the bgRFC schedulers.
Note
If you do not want to make any changes here, the system uses the valid default values.
More Information
You can find information about the authorizations required for bgRFC configuration under:
bgRFC Authorizations
The settings described above can be found on the tab pages within the transaction
SBGRFCCONF.
For more information about the configuration options, see:
Creating a Supervisor Destination
Maintaining Inbound Destinations
System-Specific Settings
Application Server-Specific Settings
Destination-Specific Settings
bgRFC Authorizations
On this page
Use
More Information
Use
For the configuration and administration of bgRFC functions, you need various authorizations,
depending on the type of activities you want to perform. The following is a description of the
authorizations required for:.
bgRFC Configuration
bgRFC Monitoring
Debugging bgRFC Units
bgRFC Configuration
For bgRFC configuration, you need authorization object S_BGRFC. This object contains various
authorization fields where you can set the type and scope of the configuration authorizations.
The bgRFC Supervisor User also needs authorizations from authorization object S_RFC. These
are defined in role SAP_BC_BGRFC_SUPERVISOR.
bgRFC Monitoring
To be able to display bgRFC units in the monitor, you also need authorizations from object
S_BGRFC.
Debugging bgRFC Units
You need the following authorization objects for debugging bgRFC units depending on the
scenario:
S_BGRFC
S_DEVELOP
S_TCODE
S_RFC
S_RFCACL
Update Techniques
The main update technique for bundling database changes in a single
database LUW is to use CALL FUNCTION ... IN UPDATE TASK. This
section describes various ways of updating the database.
A program can send an update request using COMMIT WORK
To the update work process, where it is processed asynchronously. The
program does not wait for the work process to finish
the update ( Asynchronous Update ).
For asynchronous processing in two steps ( Updating Asynchronously in
Steps .)
To the update work process, where it is processed synchronously. The
program waits for the work process to finish
the update ( Synchronous Update ).
To its own work process locally. In this case, of course, the program has
to wait until the update is finished ( Local Update .)
Asynchronous Update
A typical SAP system installation contains dialog work processes and at
least one update work process. The update work processes are
responsible for updating the database. If, in a dialog work
process, function modules that are stored temporarily are released for
processing in an update work process using CALL FUNCTION ... IN
UPDATE TASK through the ABAP statement COMMIT WORK, the dialog
work process does not wait for the update request to end. This kind
of update is called asynchronous update.
The following diagram shows a typical asynchronous update:
Synchronous Update
In synchronous update, you do not submit update requests using
CALL FUNCTION …IN UPDATE TASK . Instead you use the ABAP
statement COMMIT WORK AND WAIT. When the update is finished,
control passes back to the program. Synchronous update works in the
same way as bundling update requests in a subroutine (PERFORM ON
COMMIT). This kind of update is useful when you want to use both
asynchronous and synchronous processing without having to program
the bundles in two separate ways. The following diagram illustrates the
synchronous update process:
Use this type of update whenever the changed data is required
immediately. For example, you may want to link SAP LUWs together
where one LUW depends on the results of the previous one.
Local Update
In a local update, the update program is run by the same work process
that processed the request. The dialog user has to wait for
the update to finish before entering further data. This kind of update is
useful when you want to reduce the amount of access to the database.
The disadvantage of local updates is their parallel nature. The updates
can be processed by many different work processes, unlike
asynchronous or synchronous update, where the update is serialized
due to the fact that there are fewer update work processes (and maybe
only one).
You switch to local update using the ABAP statement SET UPDATE TASK
LOCAL. This statement sets a "local update switch". When it is set, the
system interprets CALL FUNCTION ...IN UPDATE TASK as a request for
local update. The update is processed in the same work process as the
dialog step containing the COMMIT WORK. The transaction waits for
the update to finish before continuing.
By default, the local update switch is not set, and it is reset after each
COMMIT WORK or ROLLBACK WORK. You therefore need to include a
SET UPDATE TASK LOCAL statement at the beginning of each SAP LUW.
If you reset data within the local update, the ROLLBACK WORK
statement applies to both the dialog and the update part of the
transaction, since no new SAP LUW is started for the update.
In this example, the function module UPD_FM is carried out with the
value 3 in par. The update task executes the function module only once,
despite the two PERFORM ON COMMIT statements. This is because a
repeatedly registered one can only be executed once in the case of
COMMIT WORK. The subroutine itself, containing
the function module call, cannot have parameters.
Note