You are on page 1of 82

0

Remote Function Call

 Overview

 Remote destinations

 Synchronous RFC

 Asynchronous RFC

 Transactional RFC

 Queued RFC

 RFC with external programs

 Security

 SAP AG 1999

© SAP AG BC415 5-1


0.2
Remote Function Call

Overview
Overview

Remote destinations
Remote destinations

SynchronousRFC
Synchronous RFC

AsynchronousRFC
Asynchronous RFC

TransactionalRFC
Transactional RFC

QueuedRFC
Queued RFC

RFC with
RFC withexternal
externalprograms
programs

Security
Security
 SAP AG 1999

© SAP AG BC415 5-2


0.3
Topic Objectives

 In this topic, you are given an overview of the RFC


environment and the various RFC types.

 SAP AG 1999

© SAP AG BC415 5-3


0.4
RFC Features

Automatic data conversion

Automatic conversion of all RFC data types

Automatic logon to the SAP partner system

Automatic control of the data flow

Remote debugging

RFC Generator

 SAP AG 1999

 The character conversion of the data to be transmitted is performed automatically.


 Both single parameters and structures are supported for conversion.
 The logon for remote SAP partner systems is automatic. The user and password are stored in the
table RFCDES.
 RFC calls in C are available for communicating with external programs (RFC-SDK). The RFC
Generator also helps you when generating RFC programs in C.

© SAP AG BC415 5-4


0.5
RFC from SAP R/3

R/3 application server Remote system

External non-SAP system


Work process
Function
R/2 System
PROGRAM ... group Application server from
Local another R/3 Systemp
CALL FM
FUNCTION ... Another application server
from the same R/3 System

Work process (Work process)


PROGRAM ...

CALL FUNCTION ... Remote


DESTINATION ... FM
Implicit
DB commit

 SAP AG 1999

 When you call a function module locally, it runs in the same work process as the calling program.
 If a function module is called remotely, it runs in its own work process (its own SAP LUW) if the
remote system is an R/3 System.
 The remote destination can be another application server in the same or a different R/3 System, an
R/2 System, or an non-SAP system.
 Note that the calling program is rolled out for each remote function call, which triggers an implicit
database-commit.

© SAP AG BC415 5-5


0.6
Remote Destinations (Table RFCDES )

R/3 System Remote systems


R/3 application server
PROGRAM ... (for another or the same
R/3 System)
CALL FUNCTION ...
DESTINATION ... FM

RFC Sideinfo table RFCDES


R/2 System

FM

External system
Maintenance
transaction C routine
SM59

 SAP AG 1999

 You maintain RFC destinations that must specify an ABAP program when calling remote function
modules in the RFC sideinfo table RFCDES using Transaction SM59.
 For each partner system, you need to maintain one entry in the sideinfo table.

© SAP AG BC415 5-6


0.7
Remotely Called R/3 Function Modules

Properties

Processing type
Normal function module

Remote-enabled module

Update module

Interface

CHANGING parameter not allowed

Type assignment for all interface parameters is required


(by specifying a Dictionary field/structure)

 SAP AG 1999

© SAP AG BC415 5-7


0.8
Calling External C Routines using RFC

R/3 System External system

ABAP program
RFC Library
PROGRAM ... ( RFC-SDK )
.
.
.
RFC server program
CALL FUNCTION 'ABC' ...
DESTINATION 'EXTPGM'
EXPORTING ... C routine ABC
IMPORTING ...
...
TABLES ...
EXCEPTIONS ...
. C routine XYZ
. ...
.
.
.
.

 SAP AG 1999

 SAP delivers the RFC Library for all current external platforms, in which RFC calls are contained
for C programs. After installing the RFC Library on your external platform, you can implement
RFC client or RFC server programs using RFC calls.

© SAP AG BC415 5-8


0.9
Process Flow: Synchronous RFC ( sRFC )

PROGRAM
PROGRAM ...
...
..
.. Data is passed
.. Remote function

CALL FUNCTION XYZ.


CALL FUNCTION
FUNCTION 'DIALOG'.
'DIALOG'. .
DESTINATION
DESTINATION 'B'
'B' .
EXPORTING .
EXPORTING ...
...
IMPORTING
IMPORTING ...
... ENDFUNCTION.
..
.. Data is
returned
..

 SAP AG 1999

 With synchronous RFC, processing stops in the calling program until the called remote function is
processed and its output is returned. Then in the calling program, the processing continues after the
call.

© SAP AG BC415 5-9


0.10
Process Flow: Asynchronous RFC ( aRFC )

PROGRAM
PROGRAM ...
...
..
.. Data is passed
.. Remote function

CALL
CALL FUNCTION
FUNCTION 'DIALOG'.
'DIALOG'. FUNCTION XYZ.
DESTINATION
DESTINATION 'B'
'B' .
STARTING
STARTING NEW
NEW TASK
TASK 'B1'
'B1' .
EXPORTING ...
EXPORTING ... .
..
.. ENDFUNCTION.
.. Data is
returned

 SAP AG 1999

 In an asynchronous Remote Function Call, the called remote function is started and then continues
processing on its own immediately in the calling program. Remote function processing is separate
from the calling program. The function output can be received later in the program.
 Asynchronous RFC is intended for parallel processing of processes.

© SAP AG BC415 5-10


0.11
Process Flow: Transactional RFC (tRFC):

PROGRAM
PROGRAM ...
...
...
...
CALL
CALL FUNCTION
FUNCTION 'X1'
'X1'
IN
IN BACKGROUND TASK
BACKGROUND TASK
DESTINATION
DESTINATION 'B'
'B'
...
...
CALL
CALL FUNCTION
FUNCTION 'X2'
'X2'
IN
IN BACKGROUND TASK
BACKGROUND TASK
DESTINATION
DESTINATION 'B'
'B' Start with Logical Unit of Work
...
... (LUW)
data being passed
COMMIT
COMMIT WORK.
WORK. FUNCTION X1.
. (no waiting) .
. .
. .
ENDFUNCTION.

FUNCTION X2.
.
Administration .
Administration/ /Monitoring
Monitoring .
LUWs
LUWs ENDFUNCTION.

 SAP AG 1999

 Whereas with synchronous and asynchronous RFC each call makes up a single logical unit of work
(LUW) in the remote system, you can use transactional RFC to bundle several remote functions into
one LUW (with an automatic rollback mechanism in case of error).

© SAP AG BC415 5-11


0.12
Process Flow: Queued RFC ( qRFC )

Serialization of tRFC-LUWs

LUW queue

LUW n-te tRFC- LUW 1. tRFC- LUW LUW


is generated is sent
Function module X Function module A
...
Function module Y Function module B

Function module Z

 SAP AG 1999

 With tRFC, generated LUWs are processed independently of each other. This means, the order in
which they are processed is not always the order in which they are generated.
 To ensure that tRFC-LUWs are processed in the same order as they were generated, you can use
qRFC as an extension of tRFC.
 qRFC is available as of Release 4.6A and can be used in R/3-R/3 connections as well as R/3-external
connections.

© SAP AG BC415 5-12


0.13
Topic Summary

 You can use RFC to call ABAP function modules in


SAP systems and C routines in external server
programs.
 To do this, you need an RFC destination that you
maintain in the sideinfo table RFCDES.
 There are four call variants: Synchronous,
asynchronous, transactional, and queued RFC.

 SAP AG 1999

© SAP AG BC415 5-13


0.14
Remote Function Call

Overview
Overview

Remotedestinations
Remote destinations

SynchronousRFC
Synchronous RFC

AsynchronousRFC
Asynchronous RFC

TransactionalRFC
Transactional RFC

QueuedRFC
Queued RFC

RFCwith
RFC withexternal
externalprograms
programs

Security
Security
 SAP AG 1999

© SAP AG BC415 5-14


0.15
Topic Objectives

At the conclusion of this topic you will be able to:


 Maintain RFC destinations for communication
from an R/3 System.
 Use the general destinations SPACE, NONE,
and BACK.

 SAP AG 1999

© SAP AG BC415 5-15


0.16
Maintaining the RFC Sideinfo Table RFCDES

Transaction SM59

RFC destinations

+ R/2 connection
+ R/3 connection
+ Internal connections
+ Logical connections
+ TCP/IP connections
+ Connections using ABAP driver

 SAP AG 1999

 You maintain the RFC sideinfo table RFCDES using Transaction SM59.
 Depending on the remote system, maintain one destination for the corresponding type.

© SAP AG BC415 5-16


0.17
Destination for R/3 - R/3 Connection

Type 3 destination

RFC destination ABC

Connection type 3 R/3 connections

Load distribution Yes No


Target host hs5001 System number 00

Description
RFC connection to remote R/3 System ABC

Language EN
Client 800
User SMITH
Password ******

 SAP AG 1999

 If you want to connect to another SAP System, you need a destination with type 3. Note that the
name of a type 3 destination is case-sensitive.
 If you want to ensure that the RFC logon is to a particular application server, set the Load
distribution option to No. In this case, you must specify the R/3 application server using the target
host and system number parameters.
If you do want to use load distribution when you log on, set the Load distribution option to Yes. In
this case, you must specify the system ID, the message server, and the required server group. You
can find out this information in the R/3 target system from Transactions SM51 (overview of R/3
servers) and SMLG (overview of logon groups). The message server of an SAP System is contained
in the profile parameter rdisp/mshosou. You can display this using Transaction RZ11 or report
RSPFPAR.
 In the destination, you must enter the logon data for the user created in the target system (type
'dialog' or 'CPIC'). When the destination is used, the logon to the target system occurs
automatically.
If the logon language is not entered in an RFC destination, the logon language of the current caller is
used.
If the logon data is not complete or is faulty, a logon screen from the target system appears at
runtime.

© SAP AG BC415 5-17


0.18
Destination for R/3 - R/2 Connection

Type 2 destination

RFC destination K50 Gateway

Connection type 2 R/2 connection

Description
RFC connection to remote R/2 System K50

Language EN
Client 004
User SMITH
Password ******

 SAP AG 1999

 If you want to connect to an R/2 system, you need a destination with type 2. In the destination you
need to specify the logon data of an R/2 user with the type 'CPIC'. You must also specify the SNA
gateway (for IBM-R/2) or the host gateway (for Siemens R/2) through which the connection is made.
 Note that the destination name (here, it is K50) for a type 2 destination cannot be chosen at random.
It must match the name of the corresponding destination in the gateway sideinfo table (for more
information, see the online documentation on maintaining gateways).

© SAP AG BC415 5-18


0.19
Destination for R/3 - External Connection

Type T destination

RFC destination BC415 Gateway

Connection type T TCP/IP connection

Activation type Start Registration


Start on
Application server Explicit host Front end workstation

Explicit host
Program / ext_appl / abc
Target host hs5102

Description
RFC connection to external server program abc

 SAP AG 1999

 For connections to external RFC server programs, you need a destination with the type T. there are 2
variations of the T type:
1. Start: The external program is started when communication is being established.
a) On the application server: The external program is started on the current R/3 application server.

You must give the complete program path including the program names.
b) On the explicit host: The external program is started on the specified host.
You must specify the following:
- Host name --> Name of the machine where the external program is located
- Path --> Complete path including program names on an external host
c) Front end workstation: The external program is started on the current front end at runtime via
the SAPgui. You must enter the compete (absolute) path of the program including program
names.
2. Registration: These destination variations let you access a program that has already started, which

has registered itself on a gateway. This program must be started manually beforehand and registers

itself using an RFC call with a program ID on a gateway (see the online documentation). With
this variant, the start time is not required. It is suited to starting a program frequently. You must
specify the following:
- Program-ID --> ID under which the external server program registered on the SAP gateway
- Gateway --> Host and TCP/IP service of the gateway where the external
program registered (If the gateway is the one for the current application server,
this information is not required.)

© SAP AG BC415 5-19


0.20
Destinations SPACE, NONE and BACK

R/3 System A R/3 System B

CALL FUNCTION 'ABC' Remote


DESTINATION 'B' FUNCTION ABC.
...
CALL FUNCTION 'XYZ'.
FM DESTINATION 'BACK'
...
ENDFUNCTION.
CALL FUNCTION 'ABC' Local
DESTINATION SPACE FM
...

CALL FUNCTION 'ABC' Quasi-remote


DESTINATION 'NONE' Gate-
... FM way

 SAP AG 1999

 These destinations are predefined standard destinations with have the following meanings:
- SPACE: Local call of a function module
- NONE: Also a local call, but the cal request is sent to the default gateway of the current
application server and is handled there like an external call request. This destination is
suited to the RFC test if you only have one system to test.
- BACK: You can use this destination if you want to start a function module from the called
function module in the current system.
(This only functions with synchronous RFC.)
 You cannot use this destination from R/2 systems.
Destination BACK cannot be used for R/3-R/2 connections.

© SAP AG BC415 5-20


0.21
Topic Summary

 To remotely call a function module, you need an entry


in the sideinfo table RFCDES, which you maintain
using Transaction SM59.
 An RFC sideinfo entry contains communication
parameters and, if necessary, logon data required
making the connection or logging on to the remote
system.
 SPACE, NONE and BACK are predefined standard
destinations with special meanings.

 SAP AG 1999

© SAP AG BC415 5-21


0.22
Remote Function Call

Overview
Overview

Remotedestinations
Remote destinations

SynchronousRFC
Synchronous RFC

AsynchronousRFC
Asynchronous RFC

TransactionalRFC
Transactional RFC

QueuedRFC
Queued RFC

RFCwith
RFC withexternal
externalprograms
programs

Security
Security
 SAP AG 1999

© SAP AG BC415 5-22


0.23
Topic Objectives

At the conclusion of this topic you will be able to:

 Use synchronous RFC.

 SAP AG 1999

© SAP AG BC415 5-23


0.24
Synchronous RFC ( Process Flow )

PROGRAM
PROGRAM ...
...
..
Data being
..
passed
.. Remote function

CALL FUNCTION XYZ.


CALL FUNCTION
FUNCTION 'XYZ'.
'XYZ'. .
DESTINATION
DESTINATION 'B'
'B' .
EXPORTING .
EXPORTING ...
...
IMPORTING
IMPORTING ...
... ENDFUNCTION.
..
.. Data is
returned
..

 SAP AG 1999

 With synchronous RFC, processing stops in the calling program until the called remote function is
processed and its output is returned. Then in the calling program, the processing continues after the
call.

© SAP AG BC415 5-24


0.25
Synchronous RFC ( Syntax )

R/3 application server Remote SAP System

ABAP program ABAP function module


.
. FUNCTION ABC.
. .
CALL FUNCTION 'ABC' .
.
DESTINATION 'XYZ' ENDFUNCTION.
EXPORTING f1 = a1
IMPORTING f2 = a2
TABLES t1 = itab
EXCEPTIONS External program
COMMUNICATION_FAILURE = 1
SYSTEM_FAILURE = 2 C routine ABC
...
.
.
.
.
.
.

 SAP AG 1999

 The statement CALL FUNCTION ... DESTINATION enables you to call remote ABAP function
modules or C routines in external server programs.
 When you call a function in this way, always include handling for the standard exceptions
COMMUNICATION_FAILURE and SYSTEM_FAILURE.
 The exception COMMUNICATION_FAILURE is resolved by the system if the specified destination
in the sideinfo table RFCDES is not maintained, or if the connection to the remote system cannot be
established.
 The exception SYSTEM_FAILURE is resolved if the function module or C routine that you want to
start in the remote system is not available.

© SAP AG BC415 5-25


0.26
Logical Units / Remote Program Context

R/3 application server R/3 application server

Function group

ABAP program Global data

PROGRAM ...
...
CALL FUNCTION 'ABC' FUNCTION ABC.
DESTINATION 'B' .
. LUW 1
.
. ENDFUNCTION.
.
.

CALL FUNCTION 'XYZ' FUNCTION XYZ.


DESTINATION 'B' .
. LUW 2
. .
.
. ENDFUNCTION.

 SAP AG 1999

 The connection to a remote destination remains intact for as long as the context of the calling
program remains active. The function groups addressed in the remote destination remain active for as
long as the calling program itself remains active (this is the same as with local calls). This means that
if you call two function modules from the same function group one after the other, they can both
access the same global data of the function group.
 Each function module called using synchronous RFC forms its own logical unit of work (LUW)
(exception:

© SAP AG BC415 5-26


0.27
Remote Debugging

R/3 application server Remote R/3 application server

ABAP program
ABAP function module
.
.
. FUNCTION ABC.

CALL FUNCTION 'ABC' .


.
DESTINATION 'B' .

. ENDFUNCTION.
.
.

 SAP AG 1999

 You can debug function modules called remotely in R/3 - R/3 connections.

© SAP AG BC415 5-27


0.28
RFC Dialog

R/3 application server Remote R/3 application server

PROGRAM ...
.
.
.
CALL FUNCTION 'ABC' FUNCTION ABC.
DESTINATION 'B' .
.
. .
. CALL SCREEN '100'.
.
.
.
.
ENDFUNCTION.
Remote screen displayed
for user entry
Screen 100 Screen 100 Screen 100

User entry

Calling session

 SAP AG 1999

 If a remotely-called function module uses dialogs (for example, CALL SCREEN,


CALL TRANSACTION or lists), they are executed in the session of the caller (and are fully
functional).
 Note that RFC dialogs in background processing lead to a program termination with the exception
SYSTEM_FAILURE (but you can use RFC within background processing).

© SAP AG BC415 5-28


0.29
Topic Summary

 With synchronous RFC, the calling program waits


until the called function module has been
processed.
 In a Remote Function Call between two R/3
Systems, you can debug function modules that
are running remotely.
 In an RFC between R/3 Systems, all remote
dialogs are displayed on the calling program side.

 SAP AG 1999

© SAP AG BC415 5-29


0.30
Remote Function Call

Overview
Overview

Remotedestinations
Remote destinations

SynchronousRFC
Synchronous RFC

AsynchronousRFC
Asynchronous RFC

TransactionalRFC
Transactional RFC

QueuedRFC
Queued RFC

RFCwith
RFC withexternal
externalprograms
programs

Security
Security
 SAP AG 1999

© SAP AG BC415 5-30


0.31
Topic Objectives

At the conclusion of this topic you will be able to:


 Implement parallel processing by calling function
modules asychronously.
 Explain the internal resource management
techniques for asychronous RFC.

 SAP AG 1999

© SAP AG BC415 5-31


0.32
Asynchronous RFC ( Process Flow )

PROGRAM
PROGRAM ...
...
..
.. Data being
.. passed Remote function

CALL
CALL FUNCTION
FUNCTION 'XYZ'
'XYZ' FUNCTION XYZ.
DESTINATION
DESTINATION 'B'
'B' .
STARTING
STARTING NEW
NEW TASK
TASK 'B1'
'B1' .
EXPORTING ...
EXPORTING ... .
..
.. ENDFUNCTION.
.. Data is
returned

 SAP AG 1999

 In an asynchronous Remote Function Call, the called remote function is started and then continues
processing on its own immediately in the calling program. Remote function processing is separate
from the calling program. The function output can be received later in the program.
 Asynchronous RFC is intended for parallel processing of processes.

© SAP AG BC415 5-32


0.33
Asynchronous RFC (Basic Syntax)

PROGRAM
PROGRAM ...
...
.
.
.
CALL
CALL FUNCTION
FUNCTION 'XYZ'
'XYZ' Asynchronous
DESTINATION 'B'
DESTINATION 'B' FUNCTION XYZ.
call .
STARTING
STARTING NEW
NEW TASK
TASK 'T1'
'T1' .
.
EXPORTING ...
EXPORTING ... ENDFUNCTION.
TABLES
TABLES ...
...
EXCEPTIONS
EXCEPTIONS
COMMUNICATION_FAILURE
COMMUNICATION_FAILURE == 1. 1.
SYSTEM_FAILURE
SYSTEM_FAILURE == 2.
2.
.
.
.

 SAP AG 1999

 With the addition STARTING NEW TASK <task name> you can call a remote function module
asynchronously. You can use any task name.
 The function module that you call is executed in its own work process.
 You can also use aRFC in background processing. Note, however, that even here, each aRFC call
occupies a dialog work process.
 In the sideinfo table RFCDES, you can set the number of aRFC calls for each destination using the
aRFC options. After these aRFC calls an automatic load check is performed on the target server. If
resource bottlenecks are detected, the system waits for a short time for the next aRFC call,
meant for the same remote system, and the client program is rolled out of its work process. It can
then receive results from previous aRFC calls.
 During the call, you may not specify an IMPORTING addition since the call does not wait for the
end of the function module. Here, you can only handle the two system exceptions,
COMMUNICATION_FAILURE and SYSTEM_FAILURE for the same reason. The function
module output must be received and the function module-specific exceptions must be handled later
on in a different place. (See following slides)
 Receiving the function module output and handling the function module-specific exceptions are
optional, however.

© SAP AG BC415 5-33


0.34
aRFC with Confirmation (1)

PROGRAM
PROGRAM ...
...
...
...
CALL
CALL FUNCTION
FUNCTION 'XYZ'
'XYZ' FUNCTION XYZ.
DESTINATION
DESTINATION 'B'
'B'
STARTING
STARTING NEW
NEW TASK
TASK 'T1'
'T1'
PERFORMING
PERFORMING UP1 ON
UP1 ON END
END OF
OF TASK
TASK
EXPORTING ...
EXPORTING ... .
TABLES .
TABLES ...
... .
EXCEPTIONS
EXCEPTIONS
COMMUNICATION_FAILURE
COMMUNICATION_FAILURE == 11
SYSTEM_FAILURE
SYSTEM_FAILURE == 2.
2.
...
...
FORM T = T1
FORM UP1
UP1 USING
USING T.
T. ENDFUNCTION.
RECEIVE
RECEIVE RESULTS
RESULTS FROM
FROM FUNCTION
FUNCTION 'XYZ'
'XYZ'
IMPORTING
IMPORTING ......
TABLES
TABLES ...
...
EXCEPTIONS
EXCEPTIONS
COMMUNICATION_FAILURE
COMMUNICATION_FAILURE == 11
SYSTEM_FAILURE
SYSTEM_FAILURE == 22
FLIGHT_NOT_FOUND
FLIGHT_NOT_FOUND == 3.
3.
...
...
ENDFORM.
ENDFORM.
 SAP AG 1999

 A program can receive output (parameters and exceptions) from a function module that is running
asynchronously.
 To implement this, when you call use the addition "PERFORMING <subprogram> ON END OF
TASK", where the specified subroutine must exist in your program, and through which the output of
the function module is received using command "RECEIVE RESULTS FROM FUNCTION
<fbname> . .". When the function module ends, the subroutine is called automatically.
 The subroutine must also have a formal parameter with any name you choose. When the subroutine
is called, it receives the accompanying task name. This parameter lets you see which aRFC call just
ended, and you can receive the relevant
output using the RECEIVE RESULTS FROM FUNCTION command.
 The subroutine may not contain any statements that interrupt the program execution (such as
CALL SCREEN, SUBMIT, COMMIT WORK, WAIT, RFCs, W or I messages). WRITE
statements in this subroutine specially defined for aRFC have no effect.
 The subroutine can only be executed automatically if the calling program is in rollout status. ->
"WAIT UNTIL" statements (see next slide).
 The addition KEEPING TASK with the RECEIVE statement causes the function group context that
was loaded remotely to wait until the calling program has ended. This lets you use the old remote
context with later aRFC calls with the same task name.

© SAP AG BC415 5-34


0.35
aRFC with Confirmation (2)

PROGRAM
PROGRAM ...
... ..
...
...
CALL
CALL FUNCTION
FUNCTION 'XYZ'
'XYZ'
DESTINATION 'B' FUNCTION XYZ.
DESTINATION 'B'

STARTING
STARTING NEW
NEW TASK
TASK 'T1'
'T1'
PERFORMING
PERFORMING UP1
UP1 ON
ON END
END OF
OF TASK
TASK
. ...
. ... .
. .
Program waits in
WAIT UNTIL <logexp> .. .
WAIT
. UNTIL <logexp> rollout status
.
.
End of main program

T = T1
FORM ENDFUNCTION.
FORM UP1
UP1 USING
USING T.
T.
RECEIVE
RECEIVE RESULTS FROM
RESULTS FROM FUNCTION
FUNCTION 'XYZ'
'XYZ'
IMPORTING
IMPORTING / TABLES / EXCEPTIONS ...
/ TABLES / EXCEPTIONS ...
Evaluate SY-SUBRC immediately or store

Set WAIT conditions

ENDFORM.
ENDFORM.
 SAP AG 1999

 The language element WAIT UNTIL with the addition PERFORMING is only useful with aRFC,
and otherwise has no effects.
 When the WAIT UNTIL statement is executed, the conditions specified are checked.
If it is fulfilled, the program processing continues directly after the WAIT UNTIL statement.
Otherwise the system waits in rollout status for the output from the aRFCs. If the aRFC output is
now returned, the form routine specified during the call is executed and is sent back to the WAIT
UNTIL statement.
This check/wait procedure repeats until the WAIT conditions are fulfilled, or until there are no more
open RFC calls.
 Note that the WAIT UNTIL statement sets the SY-SUBRC. Therefore, store the SY-SUBRC value
(set in the form routine by exceptions-handling in RECEIVE RESULTS) in its own global variable
before leaving the form routine, if you need this value again later (after WAIT UNTIL).

© SAP AG BC415 5-35


0.36
Example: Waiting for Multiple aRFCs
PROGRAM
PROGRAM ...
...
...
...
CALL
CALL FUNCTION
FUNCTION 'X1'
'X1'
DESTINATION 'B'
DESTINATION 'B'

STARTING
STARTING NEW
NEW TASK
TASK 'T1'
'T1'
PERFORMING
PERFORMING UP1 ON
UP1 ON END
END OF
OF TASK
TASK
CALL
CALL FUNCTION
FUNCTION 'X2'
'X2'
DESTINATION
DESTINATION 'B'
'B'

STARTING
STARTING NEW
NEW TASK
TASK 'T2'
'T2'
PERFORMING
PERFORMING UP1 ON
UP1 ON END
END OF
OF TASK
TASK
...
...
WAIT
WAIT UNTIL
UNTIL NOTNOT flag1
flag1 IS
IS INITIAL
INITIAL AND
AND NOT
NOT flag2
flag2 IS
IS INITIAL.
INITIAL.
FORM UP1 USING
FORM UP1 USING T.T.
CASE
CASE T.T.
WHEN
WHEN'T1'.
'T1'. <<RECEIVE
RECEIVE RESULTS
RESULTS++Output
Output processing
processing from
from X1
X1>>..
flag1 = 'X'.
flag1 = 'X'.
WHEN
WHEN'T2'.
'T2'. <<RECEIVE
RECEIVE RESULTS
RESULTS++Output
Output processing
processing from
from X2
X2>>..
flag2 = 'X'.
flag2 = 'X'.
ENDCASE.
ENDCASE.
ENDFORM.
ENDFORM.
 SAP AG 1999

 In this program example, the are two aRFCs, and when the aRFCs are confirmed, the subroutine UP1
is always executed.
 This subroutine uses parameter T to separately decide which function module just returned its
output. Then the corresponding RECEIVE RESULTS statement is used to receive (and process)
the output.
 After processing an aRFC output, you must correspondingly adjust the WAIT UNTIL condition.
(Here: Set flag1 or flag2)

© SAP AG BC415 5-36


0.37
aRFC Between Different R/3 Systems

R/3 System A R/3 System B

R/3 application server R/3 application server

Work process Work process

PROGRAM ... Function group


CALL FUNCTION ... Remote
DESTINATION 'B' Function
Function
STARTING NEW TASK ... module
module

 SAP AG 1999

 aRFC is particularly suited for implementing parallel processing in several R/3 Systems.

© SAP AG BC415 5-37


0.38
aRFC Within the Same R/3 System

R/3 System

R/3 application server A1 R/3 application server A2

Work process Work process

PROGRAM ... Function group


CALL FUNCTION ... Internal
DESTINATION 'A2' Function
Function
STARTING NEW TASK ... remote
module
module

 SAP AG 1999

 You can also use aRFC within the same SAP R/3 System, for example, to move some of the
processing load to an application server specially used for this.
 Enter the RFC destination that refers to the corresponding application server. (You can find this
under Internal connections in Transaction SM59.)

© SAP AG BC415 5-38


0.39
aRFC Within the Same Application Server

R/3 System

R/3 application server

Work process 1 Work process 2

PROGRAM ... Function group


Local
CALL FUNCTION ...
STARTING NEW TASK ... Function
module

 SAP AG 1999

 You can also use aRFC locally within the same application server to implement parallel processing
in several work processes.
 Here you do not need to specify a destination.
 Note, however, that several work processes will be occupied by your program at the same time.

© SAP AG BC415 5-39


0.40
Load Balancing Using RFC Groups

PROGRAM
PROGRAM ...
... ..
...
...
CALL
CALL FUNCTION
FUNCTION 'XYZ'
'XYZ' Current R/3 System
STARTING
STARTING NEW
NEW TASK
TASK 'T1'
'T1'
DESTINATION
DESTINATION IN GROUP
IN GROUP 'G1'
'G1'
** DESTINATION
DESTINATION IN
IN GROUP
GROUP DEFAULT
DEFAULT
RFC group G1 RFC group G2
...
...
EXCEPTIONS Appl. Appl. Appl. Appl.
EXCEPTIONS
...
... Server Server Server Server
RESOURCE_FAILURE
RESOURCE_FAILURE == ...
... A1 A2 A3 A4

.
.
. RFC group DEFAULT

 SAP AG 1999

 You can divided the application servers for an SAP R/3 System into different RFC groups using
Transaction SM59.
 When calling a function module within this R/3 System, you can specify one of the defined RFC
groups using the addition DESTINATION IN GROUP <RFC group>, which selects the server that
has the lowest load in order to execute the function module.
Instead of specifying a specific RFC group, you can also enter the word DEFAULT. The server is
selected from all the application servers of the R/3 System.
 If all the servers of the specified group are overloaded (see next slide), the exception
RESOURCE_FAILURE is triggered.
 Note that:
- You have to specify the addition DESTINATION IN GROUP after STARTING NEW TASK as
opposed to the DESTINATION addition.
- You can only use this addition within the current SAP R/3 System (you cannot have additional
DESTINATION entries).

© SAP AG BC415 5-40


0.41
Checking the Load In an RFC Group

CALL FUNCTION 'XYZ'


STARTING NEW TASK 'T1'
DESTINATION IN GROUP 'G1'
...

Local
RFC group G1 message server

Application server A1 Resource check

a) Dispatcher queue
Dispatcher queue
load < 5%
2) At least 3 free dialog
WP1 WP2 WP3 ...
work processes

Application server A2

Dispatcher queue

WP1 WP2 WP3 ...

 SAP AG 1999

 For each server in the specified RFC group, the system checks if the application server has:
- a dispatcher queue load of < 5%, and
- at least 3 free dialog work processes
The server is considered as not being overloaded only if both of these conditions are met.

© SAP AG BC415 5-41


0.42
aRFC with Dialog

R/3 application server Remote R/3 application


server
PROGRAM ...
.
.
.
CALL FUNCTION 'ABC' FUNCTION ABC.
DESTINATION 'B' .
.
STARTING NEW TASK 'T1' .
. CALL SCREEN '100'.
.
. .
.
.
ENDFUNCTION.
Remote screen displayed
for user entry
Screen 100 Screen 100 Screen 100
Calling session
User entry

Main session External session

 SAP AG 1999

 If you have called a function module asynchronously and it contains dialogs, the relevant screens are
displayed in an additional (new external session) window on the calling side.
 When you program, limit the number of external sessions for each dialog user to 6. If the calling
dialog user already has 6 external sessions open, the exception SYSTEM_FAILURE is triggered.

© SAP AG BC415 5-42


0.43
Topic Summary

 aRFC enables you to implement parallel processing.

 You can use aRFC system-wide, for multiple application


servers, or locally on the same application server.
 Function modules running asynchronously can return
data to the calling program. To do this, the calling
program must remain active until the function module
output was returned.
 When you use aRFC, the system always ensures that
enough resources remain available on the server for
other processing.

 SAP AG 1999

© SAP AG BC415 5-43


0.44
Remote Function Call

Overview
Overview

Remotedestinations
Remote destinations

SynchronousRFC
Synchronous RFC

AsynchronousRFC
Asynchronous RFC

TransactionalRFC
Transactional RFC

QueuedRFC
Queued RFC

RFCwith
RFC withexternal
externalprograms
programs

Security
Security
 SAP AG 1999

© SAP AG BC415 5-44


0.45
Topic Objectives

At the conclusion of this topic you will able to:


 Combine several function modules in a
destination into a single LUW using tRFC.
 Program tRFC in ABAP.
 Manage tRFC-LUWs using Transaction
SM58.

 SAP AG 1999

© SAP AG BC415 5-45


0.46
Transactional RFC: Purpose, Process and Syntax

PROGRAM
PROGRAM ...
...
...
...
CALL
CALL FUNCTION
FUNCTION 'X1'
'X1' You do not receive
IN
IN BACKGROUND TASK
BACKGROUND TASK
DESTINATION function module output
DESTINATION 'B'
'B'
...
...
CALL
CALL FUNCTION
FUNCTION 'X2'
'X2'
IN
IN BACKGROUND TASK
BACKGROUND TASK
DESTINATION Start with
DESTINATION 'B'
'B' Logical Unit of Work
... data being
... passed (LUW)
COMMIT
COMMIT WORK.
WORK. FUNCTION X1.
. (no waiting) .
. .
. .
ENDFUNCTION.

FUNCTION X2.
.
Administration .
Administration/ /monitoring
monitoring .
LUWs
LUWsusing
usingSM58
SM58 ENDFUNCTION.

 SAP AG 1999

 Whereas with synchronous and asynchronous RFC each call makes up a single logical unit of work
(LUW) in the remote system, you can use transactional RFC to bundle several remote functions into
one LUW (with an automatic rollback mechanism in case of error).
 You can use tRFC with the addition IN BACKGROUND TASK, which you must place before the
DESTINATION entry. If you specify a COMMIT WORK statement, you bundle all the previously
transmitted tRFCs in one LUW.
 tRFCs are also called asynchronously. Unlike aRFC, the output from the called function module
cannot be received.
-> No IMPORTING . . . / PERFORMING . . . ON END OF TASK when calling;
-> No RECEIVE RESULTS FROM FUNCTION . . .
 In the source system, you can use the administration transaction SM58 that lets you display and
modify tRFC-LUWs.

© SAP AG BC415 5-46


0.47
Execution Mechanism

Client

tRFC call 1 L
U
tRFC call 2 W
Optional:
CALL FUNCTION
START_OF_BACKGROUNDTASK’
EXPORTING <date/time>.

COMMIT WORK.
Server
ARFCSSTATE tRFC call

Function 1 L
ARFCSDATA Job U
Execution status Function 2 W
SM58

 SAP AG 1999

 tRFC calls are first stored in the local tRFC tables ARFCSSTATE and ARFCSDATA. The execution
status of the LUWs is logged in table ARFCSSTATE, while ARFCSDATA contains the input data for
the tRFCs.
 If you do not want to execute a remote LUW immediately, rather trigger it at a later time, call the
function module START_OF_BACKGROUNDTASK before the COMMIT WORK statement
locally. Here, you must enter the date and time of execution.
 The COMMIT WORK statement automatically schedules an immediate job or a job set for a later
start time to remotely call the LUW. In the job execution, the relevant data is read from the tRFC
tables, and the corresponding tRFCs are transmitted. If the remote LUW is executed successfully,
the accompanying entries are deleted from the tRFC tables. If an error occurs, an automatic repeat
mechanism, or rollback mechanism is activated (see next slide).
 If the update is triggered locally because of the COMMIT WORK statement, the tRFCs are only
executed when the local update is successfully completed.

© SAP AG BC415 5-47


0.48
Automatic Mechanisms if an Error Occurs

Client Server
ARFCSSTATE tRFC call

Function 1 L
ARFCSDATA Job U
Execution status Function 2 W
SM58

Relevant entries deleted from tRFC tables if execution was successful


Automatic job rescheduling if partner cannot be reached
(You can set the number of repeat tries and interval length in the destination
tRFC options)

Automatic rollback in target system + error noted in ARFCSSTATE


if program terminates for remote function modules
A-message / RAISE <exception> in remote function module
No deletion + no automatic job rescheduling in source system

 SAP AG 1999

 If a connection cannot be made to the partner, this is logged in the tRFC status table ARFCSSTATE
(which you can see by using Transaction SM58), and the job is rescheduled. You can set in the
destination the number of times the system repeats the effort to connect, and the time intervals, by
using the tRFC options. The default is a maximum 30 times with a 15 minute interval.
 If, after a tRFC-LUW is successfully executed in the partner system in one of the function modules,
the program terminates with an A/X-message (MESSAGE A/X...) or triggers an exception
(RAISE...),
- all the changes made in the current LUW are automatically rolled back in the remote system, and
- the remote program termination is logged in the tRFC status table ARFCSSTATE (viewable using
SM58) in the source system.
The entries relevant to the LUW remain in the tRFC tables and the execution job is not rescheduled.
In this case, you can find the remote error using Transaction SM58, and you have to correct the
problem in the remote system. Afterward you must trigger the remote execution again also in
Transaction SM58.
 If you want to cancel and roll back this remote execution from a remote function module of a tRFC-
LUW, but you also want to reschedule the job in the source system (for example, because a master
record that is to be processed is locked and the LUW must be executed again), call the function
module RESTART_OF_BACKGROUNDTASK in the remote function module instead of
MESSAGE A... or RAISE...

© SAP AG BC415 5-48


0.49
LUW Bundling

Client program
PROGRAM
PROGRAM ...
...
...
...
CALL
CALL FUNCTION
FUNCTION 'X1'
'X1'
IN Destination B
IN BACKGROUND TASK
BACKGROUND TASK
DESTINATION 'B'
DESTINATION L
X1 U
CALL
CALL FUNCTION
FUNCTION 'X2'
'X2'
IN X2 W
IN BACKGROUND
BACKGROUND TASK
TASK
DESTINATION 1
DESTINATION 'B'

CALL
CALL FUNCTION
FUNCTION 'X3'
'X3'
IN
IN BACKGROUND
BACKGROUND TASK
TASK
DESTINATION Destination C
DESTINATION 'C'
L
CALL
CALL FUNCTION
FUNCTION 'X4'
'X4' X3 U
IN
IN BACKGROUND
BACKGROUND TASK
TASK
DESTINATION X4 W
DESTINATION 'C' 2
...
...
COMMIT
COMMIT WORK.
WORK.

 SAP AG 1999

 If tRFCs are transmitted with different destinations before the COMMIT WORK, they are grouped
into different LUWs according to their destination.
 A tRFC call with the addition AS SEPARATE UNIT is always processed as a separate LUW
independently of the other tRFCs.
 Each tRFC-LUW is assigned a unique transaction ID (viewable with Transaction SM58).
The function module ID_OF_BACKGROUNDTASK (which is called before the COMMIT WORK)
returns this ID.
You can determine the LUW execution status using the function module
STATUS_OF_BACKGROUNDTASK under the transaction ID (which is called after the COMMIT
WORK).
 If you also called the update function modules locally before the COMMIT WORK, tRFC calls are
only processed when the local update function modules have been processed successfully.
 You can also call transactional C functions. However, you must use the rollback mechanism in the
external server program (see RFC-SDK documentation and example programs).

© SAP AG BC415 5-49


0.50
Topic Summary

 You can use tRFC to process several


function modules remotely in the same LUW
with the automatic rollback mechanism.
 tRFC allows you to ensure that the function
modules you call are executed even if the
target system is unavailable when the call is
made.
 You can use Transaction SM58 to display
and process (delete and execute) faulty or
non-executed tRFC-LUWs.

 SAP AG 1999

© SAP AG BC415 5-50


0.51
Remote Function Call

Overview
Overview

Remotedestinations
Remote destinations

SynchronousRFC
Synchronous RFC

AsynchronousRFC
Asynchronous RFC

TransactionalRFC
Transactional RFC

QueuedRFC
Queued RFC

RFCwith
RFC withexternal
externalprograms
programs

Security
Security
 SAP AG 1999

© SAP AG BC415 5-51


0.52
Topic Objectives

At the conclusion of this topic you will able to:


 Serialize tRFC-LUWs in a queue using queued RFC.
 Explain the architecture and programming of queued
RFC.
 Administrate RFC queues using Transaction SMQ1.

 SAP AG 1999

© SAP AG BC415 5-52


0.53
Purpose of Queued RFC (qRFC)

Serialization of tRFC-LUWs

LUW queue

LUW n-te tRFC- LUW 1. tRFC- LUW LUW


is generated is sent
Function module X Function module A
...
Function module Y Function module B

Function module Z

 SAP AG 1999

 With tRFC, generated LUWs are processed independently of each other. This means, the order in
which they are processed is not always the order in which they are generated.
 To ensure that tRFC-LUWs are processed in the same order as they were generated, you can use
qRFC as an extension of tRFC.
 qRFC is available as of Release 4.6A and can be used in R/3-R/3 connections and R/3-external
connections.

© SAP AG BC415 5-53


0.54
Syntax

PROGRAM ...
...
CALL FUNCTION 'TRFC_SET_QUEUE_NAME' EXPORTING qname = 'Q1'.
CALL FUNCTION 'A'
IN BACKGROUND TASK
DESTINATION 'XYZ' ...
1. Place
CALL FUNCTION 'TRFC_SET_QUEUE_NAME' EXPORTING qname = 'Q1'. tRFC- LUW in
queue Q1
CALL FUNCTION 'B'
IN BACKGROUND TASK
DESTINATION 'XYZ' ...
COMMIT WORK.

CALL FUNCTION 'TRFC_SET_QUEUE_NAME' EXPORTING qname = 'Q1'.


CALL FUNCTION 'C'
IN BACKGROUND TASK
DESTINATION 'XYZ' ...
2. Place
CALL FUNCTION 'TRFC_SET_QUEUE_NAME' EXPORTING qname = 'Q1'. tRFC- LUW in
queue Q1
CALL FUNCTION 'D'
IN BACKGROUND TASK
DESTINATION 'XYZ' ...
COMMIT WORK.
...
 SAP AG 1999

 To place tRFC-LUWs in a First-In-First-Out (FIFO) queue, you must specify the queue you want to
use via the function module TRFC_SET_QUEUE_NAME before every single tRFC call.
 You can freely choose the queue name you need to specify, and it can have up to 24 characters
The queue name not start with
- an empty character
- the '%' symbol, or
- contain the '*' symbol

© SAP AG BC415 5-54


0.55
Data Storage

Queue data tRFC data

TRFCQOUT ARFCSSTATE ARFCSDATA

Do not maintain with SM58

Maintain using Transaction SMQ1

 SAP AG 1999

 The tRFC-LUWs belonging to a queue are stored in the tRFC tables ARFCSSTATE and
ARFCSDATA. However, you cannot maintain or display these LUWs using Transaction SM58. You
must use the queue administration transaction SMQ1.
 The queue data (queue attributes + pointers to the relevant tRFC-LUWs in the tRFC tables) is stored
in the TRFCQOUT table, which you can maintain using Transaction SMQ1.
The following functions are available:
- List queues
- Display queues with a list of accompanying LUWs and function modules including input data
- Start/stop transmitting the queues
- Delete queues
 If an LUW error occurs in the remote system, the queue is rolled back there. The relevant LUW and
all of the other LUWs in the queue remain in the queue and in the tRFC tables. After correcting the
error, you can use Transaction SMQ1 to transmit the queue again.

© SAP AG BC415 5-55


0.56
Topic Summary

 With qRFC, you can ensure that tRFC-LUWs


are processed in the order they were
generated (serialization).
 This is implemented using a queue for tRFC-
LUWs.
 The queue attributes and tRFC input data are
stored in the queue table TRFCQOUT and in
the tRFC tables ARFCSSTATE /
ARFCSDATA. You can maintain and display
this information using Transaction SMQ1.

 SAP AG 1999

© SAP AG BC415 5-56


0.57
Remote Function Call

Overview
Overview

Remotedestinations
Remote destinations

SynchronousRFC
Synchronous RFC

AsynchronousRFC
Asynchronous RFC

TransactionalRFC
Transactional RFC

QueuedRFC
Queued RFC

RFCwith
RFC withexternal
externalprograms
programs

Security
Security
 SAP AG 1999

© SAP AG BC415 5-57


0.58
Topic Objectives

At the conclusion of this topic you will able to:


 Understand how external RFC clients and RFC
servers are structured using C.
 Generate program frames for external RFC clients
and servers in C using the RFC Generator.

 SAP AG 1999

© SAP AG BC415 5-58


0.59
External RFC Client and Server

R/3 System External system

ABAP program
RFC library
PROGRAM ... ( RFC-SDK )
.
.
.
CALL FUNCTION 'ABC' RFC server program
DESTINATION 'EXTPGM' ...
...
. C routine ABC
.
.
C routine XYZ

...
Function module

FUNCTION FUNC1.
. RFC client program
.
.
...
ENDFUNCTION.

 SAP AG 1999

 SAP delivers the RFC Library for all current external platforms, in which RFC calls are contained
for C programs. After installing the RFC Library on your external platform, you can use RFC client
or RFC server programs with RFC calls.

© SAP AG BC415 5-59


0.60
External RFC Client

RfcOpen(...);
...
RfcCall(...);
... RfcCallReceive(...);
RfcReceive(...);
...
RfcCall(...);
...
RfcReceive(...);
...
RfcClose(...);
...

 SAP AG 1999

 This slide shows you the structure of an external RFC client.


 The connection to the SAP R/3 System is made using the RFC call RfcOpen with the destination
and logon data.
 RfcCall calls an R/3 function module. RfcReceive receives the output of the function module. This
enables you to use an asynchronous call. If you want to use a synchronous call, use RfcCallReceive
instead of these two RFC calls.
 To close the RFC connection to the SAP R/3 System, use call RfcClose.

© SAP AG BC415 5-60


0.61
External RFC Server

main(...)
....
RfcAccept(...)
RfcInstallFunction(abc,...)
RfcInstallFunction(xyz,...)

RfcDispatch(...)
RfcClose(...)
}

static RFC_RC abc(...)


{ ...
RfcGetData(...)
Data processing
RfcSendData(...)
}
static RFC_RC xyz(...)
{ ... }
 SAP AG 1999

 This slide shows you the structure of an external RFC server.


 The call RfcAccept accepts the incoming RFC connection.
 All C routines for the RFC server program, that should be called remotely, must be registered as
being remote-enabled using the call RfcInstallFunction.
 The call RfcDispatch sends the incoming call to the corresponding C routine.
 The call RfcGetData enables the C routine to receive the input sent from the calling program.
 The call RfcSendData returns the result to the calling program.
 The call RfcClose ends the RFC connection.

© SAP AG BC415 5-61


0.62
RFC Generator

R/3 System External system

RFC Library
RFC Generator ( RFC-SDK )
(SE37)

RFC client program


...
FM

RFC server program


...
External RFC client and C routine ABC
server

 SAP AG 1999

 You can use the RFC Generator to create an RFC client in C for a remote-enabled R/3 function
module. The corresponding remote call for the function module is already implemented in the
collection of program files generated by the RFC Generator.
 The RFC Generator also supports you when creating an external RFC server program in C. To do
this, first define in the SAP System a remote-enabled dummy function module with empty coding
and the interface that you want to use in the remote C routine you will be creating. The RFC
generator generates an RFC server program in C with the required remote C routine, which is used
for the function module. When you start the RFC Generator, select the option 'C Server' instead of
'C client'.
 The RFC Generator also creates a text file which contains tips on using the generated program.
 The programs generated by the RFC generator are sRFC client or sRFC server. You can also
generate aRFC, tRFC, and qRFC for R/3-external connections. For more information, see the online
documentation on RFC-API or the sample programs delivered with the RFC-SDK.

© SAP AG BC415 5-62


0.63
Unit Summary

 The RFC-SDK must be installed for RFC on the


external platform.
 You can call R/3 function modules using an external
RFC client program.
 You can call C routines within an RFC server program
that have been declared as remote-enabled from
ABAP programs.
 The RFC Generator in the SAP System generates a
collection of C program files for the dummy function
module to be used with external RFC clients or
servers.

 SAP AG 1999

© SAP AG BC415 5-63


0.64
Remote Function Call

Overview
Overview

Remotedestinations
Remote destinations

SynchronousRFC
Synchronous RFC

AsynchronousRFC
Asynchronous RFC

TransactionalRFC
Transactional RFC

QueuedRFC
Queued RFC

RFCwith
RFC withexternal
externalprograms
programs

Security
Security
 SAP AG 1999

© SAP AG BC415 5-64


0.65
Topic Objectives

At the conclusion of this topic you will able to:


 Explain which authorization checks exist for RFC.
 Explain which authorizations the remote user
specified in the RFC logon needs to call the remote
function module successfully.
 Define trust relationships between R/3 Systems, and
explain - for existing trust relationships - how users
in the source system can use the released users in
the target system for passwordless RFC logons.
 Release users in the target system for specific users
in the source system.

 SAP AG 1999

© SAP AG BC415 5-65


0.66
Authorization Check for RFC

Source system Target SAP System

User SMITH
RFC
Program - Authorization for RFC start
RFC logon with of desired function module
remote user
SMITH
- Authorization for actions
on the function module

Function module

 SAP AG 1999

 The authorization object S_RFC lets you define, for each RFC logon user, in which function groups
the user is authorized to start RFC. This user can only start function modules in these function
groups with RFC.
 This authorization check is active by default. However, you deactivate this default using a profile
parameter.
 Authorization checks for actions that call a function module remotely (for example, transaction
authorization for CALL TRANSACTION) are compared against the user master record of the
corresponding RFC logon user.

© SAP AG BC415 5-66


0.67
The Authorization Object S_RFC

Authorization for RFC logon user


Authorization 'ALL'
to start a function module
RFC_NAME: *

Object S_RFC ACTVT: 16

RFC_NAME (function group) RFC_TYPE: FUGR

ACTVT (activity)

RFC_TYPE (RFC object type) Authorization ABCD

RFC_NAME: ABCD

ACTVT: 16

RFC_TYPE: FUGR

 SAP AG 1999

 The authorization object S_RFC contains three fields:


- RFC_NAME: Can currently only contain names of function groups
- ACTVT : Can contain the value 16 (execute)
- RFC_TYPE: Can contain the value FUGR (function group)
 The above examples show the available authorizations for the object S_RFC:
The RFC logon user with the authorization 'ALL' can call all the function modules.
The RFC logon user with the authorization 'ABCD' can only call function modules from the function
group ABCD.

© SAP AG BC415 5-67


0.68
Trust Relationships (Only R/3-R/3)

Declaration of a trust relationship


using SMT1 in the system that is to
become the trusting system.

R/3 System A R/3 System B

Trusted System Trusting System

SMT1

 SAP AG 1999

 You can declare a trust relationship between two SAP R/3 Systems so that you can perform certain
RFC logons in the trusting system without a password for released users.
 You always declare a trust relationship in the system that is to become the trusting system, which
means, it is in the RFC target system.
 You use Transaction SMT1 to define a trust relationship.
 You can use Transaction SMT2 in the trusted system to display which trusting systems are declared
for the local system.

© SAP AG BC415 5-68


0.69
RFC Logon Without a Password

R/3 System A R/3 System B


Trusted System Trusting System

Trust destination (SM59)

Remote system B
User SMITH
Remote client 002 RFC logon - Released for user Ryan for
Remote user SMITH trusted system A
Remote user
No password - Authorization for RFC start
SMITH used
Logon language EN of desired function module
without
password
- Authorizations for actions
RFC
on the function module

ABAP program

Dialog user Function module


Ryan

 SAP AG 1999

 A dialog user in the trusted system (RFC source system) can use a specially released user for the
RFC logon without a password in the trusting system (RFC target system). To do this, the user
requires a trust destination, created using Transaction SM59 (Trusted system = 'Yes'), in which only
the name of the remote user is entered, but not the accompanying password.
(Note: You can also use regular destinations (with a password) with an existing trust relationship.
 To be able to use RFC logon without a password for a specific user in the trusted system, you need to
release a user in the trusting system. This is done by giving an authorization for the authorization
object S_RFCACL to the user you want to release in the trusting system.

© SAP AG BC415 5-69


0.70
The Authorization Object S_RFCACL

Release a user in the trusting system by


giving authorization

Object S_RFCACL Authorization "A400_RYAN"


RFC_SYSID RFC_SYSID: A

RFC_CLIENT RFC_CLIENT: 400

RFC_USER RFC_USER: RYAN

RFC_EQUSER RFC_EQUSER: Y

RFC_TCODE RFC_TCODE: *

RFC_INFO RFC_INFO: *

ACTVT ACTVT: 16

 SAP AG 1999

 The authorization object S_RFCACL has seven fields.


- RFC_SYSID: Calling RFC source system (trusted system)
- RFC_CLIENT : Calling client
- RFC_USER : Calling user
- RFC_EQUSER : Indicates if the user with this authorization is released for the same user in the
RFC source system
- RFC_TCODE : Calling transaction code
- RFC_INFO: Additional information on RFC source system (not currently used)
- ACTVT : Can only have the value 16 (execute)
 Example:
If user SMITH in the trusting system is authorized for 'A400_RYAN', he is released for the user
RYAN in the trusted system A. RYAN is allowed to use remote user SMITH for RFC logon without a
password for any transaction from System A, client 400. RFC_EQUSER = * means that user
SMITH is released for the same user in trusted system A.

© SAP AG BC415 5-70


0.71
Topic Summary

 To start a function module using RFC, the RFC logon


user in the target system needs a corresponding
authorization for the authorization object S_RFC.
 For an existing trust relationship between two SAP
Systems, specific users in the source system can
use the user released for them in the target system
for RFC logons without a password.
 To release a user in the target system, you need to
give an authorization for the authorization object
S_RFCACL.

 SAP AG 1999

© SAP AG BC415 5-71


Exercises

Unit: Remote Function Call


Theme: Remote destinations

 Creating a logical destination for RFC communication with another


R/3 System.

RFC destination name: DEST##


User in source system: BC415-##
Remote user for RFC logon: BC415-## ( ## = your group number)

1 To create and maintain logical destinations for Remote Function Call, use Transaction
SM59.

Create a destination in R/3 System A through which it can communicate R/3 System B
using RFC. (The names of systems A and B are given to you by your course trainer.)
You can find out the information you need using Transaction SM51 in the target system.

2 Test your destination.

Tips & When maintaining the destination, you can press ENTER after entering
Tricks connection type to update the screen, where fields relating to the
connection type appear for maintenance.

© SAP AG BC415 5-72


Unit: Remote Function Call
Theme: Synchronous RFC

 Calling an RFC function module synchronously and passing data.

Template SAPBC415_RFCSYNC_T1
Name of your solution program: ZBC415_##_RFCSYNC
Name of function module you want to call: BC415_RFC_READ_SPFLI

1 In system B, learn to use the functions of the BC415_RFC_READ_SPFLI function


module (inteface and source text).
The function module reads an entry from table SPFLI. In the function call, you pass the
relevant key values required to do this.
If the function module is unable to read a table entry, an exception is triggered.
If the function module reads an entry successfully, it passes the entry and system ID back
to the caller using its interface.

2 In system A create a program by first copying the sample program listed above.
From your program, call the function module BC415_RFC_READ_SPFLI in system B.
Check the exceptions defined in the function module.
If an error occurs, display the relevant error message, and if it is successful, output the data
returned by the function module.

© SAP AG BC415 5-73


Unit: Remote Function Call
Theme: Asynchronous RFC

 Calling an RFC function module synchronously and passing data.

Template: ZBC415_##_RFCSYNC (or SAPBC415_RFCSYNC_S1)


Name of your solution program: ZBC415_##_RFCASYNC

Calling a function module remotely and asynchronously

Copy your solution from the 'Synchronous RFC' exercise, or the model solution
SAPBC415_RFCSYNC_S1, and convert the function call, data transfer, and exception
handling to asynchronous processing.

© SAP AG BC415 5-74


Unit: Remote Function Call
Theme: Transactional RFC

 Making identical changes to a customer's telephone number in two R/3


Systems using transactional RFC.

Template: SAPBC415_RFCTRANS_T1
Name of your dialog program: SAPMZ_BC415_##_RFCTRANS
Name of your transaction: ZBC415_##
1 Making the same changes to customer data in two R/3 Systems.
1-1 Copying the program SAPBC415_RFCTRANS_T1 to your program.
This program is a module pool, with screens, and user interfaces. Ensure that
you copy all of the program components.
You need to define a transaction code for your dialog program (see name
above).
1-2 Go to the module USER_COMMAND_0200. There you will find a CASE
statement for the field OKCODE. Enter the processing step you want to
supplement under WHEN ‘SAVE’.
1-3 The function module BC415_TRFC_CHANGE_SCUSTOM_ENTR allows you
to change the telephone number of a customer (table SCUSTOM ). This
function module contains 2 import parameters:
CUSTOMER ID  customer number
I_TELEPHONE  telephine number
Call the function module locally ( local change) and then call it again
remotely using transactional RFC ( identical remote change).
1-4 In the remote system, use the Data Browser (Transaction SE16) to check that
the changes have been made correctly. If not, use Transaction SM58 (tRFC
monitor) to find out why.
1-5 Create the processing of the tRFC-LUW for a future time. To do this, use the
START_OF_BACKGROUNDTASK function module. In screen 200 you see
the entry field for the time of execution that you pass along when you call the
function module.
1-6 In the source system, use Transaction SM58 to check that the tRFC LUW has
been correctly scheduled and executed.

© SAP AG BC415 5-75


Solutions

Unit: Remote Function Call


Theme: Remote Destination

 Creating a logical destination for RFC communication with another


R/3 System.

1 Start Transaction SM59.

2 Choose Create. A screen appears, on which you should enter the name of the new
destination. Enter 3 as the connection type (target system is an R/3 System) and a
description. Press Enter to continue.

3 In the next step, you must specify an R/3 application server for the target system by
entering the relevant host name and the R/3 system number there. You can get the required
information by running Transaction SM51 in the target system. There you will see a list of
all the instances in the target system. The instance consists of the:
- host name where the instance is running (for example, hs0330)
- system ID (for example, ABC)
- the system number for the instance (for example, 17)
It would appear as follows:
hs0330_ABC_17.

4 You must now enter the RFC logon data ( language, client, user, password), and save the
destination.

5 Test your RFC destination by choosing Test connection or Remote logon.

© SAP AG BC415 5-76


Unit: Remote Function Call
Theme: Synchronous RFC

 Calling an RFC function module synchronously and passing data.

1 Source text of the solution program


REPORT sapbc415_rfcsync_s1 MESSAGE-ID bc415
TABLES spfli.
PARAMETERS: icarr LIKE sflight-carrid DEFAULT 'LH',
iconn LIKE sflight-connid DEFAULT '0400',
dest LIKE rfcdes-rfcdest DEFAULT 'NONE'.

DATA: sysid LIKE sy-sysid,


mess(80).

CALL FUNCTION 'BC415_RFC_READ_SPFLI'


DESTINATION dest
EXPORTING
carrid = icarr
connid = iconn
IMPORTING
ex_spfli = spfli
sys = sysid
EXCEPTIONS
invalid_data = 1
communication_failure = 2 MESSAGE mess
system_failure = 3 MESSAGE mess.

© SAP AG BC415 5-77


CASE sy-subrc.
WHEN 1.
WRITE: / text-001 .
EXIT.
WHEN 2.
WRITE: / mess.
EXIT.
WHEN 3.
WRITE: / mess.
EXIT.
ENDCASE.

WRITE: / text-004, sysid COLOR 5.


SKIP.
WRITE: spfli-carrid, spfli-connid, spfli-cityfrom, spfli-cityto.

© SAP AG BC415 5-78


Unit: Remote Function Call
Theme: Asynchronous RFC

 Calling an RFC function module synchronously and passing data.

1 Source text of the solution program


REPORT sapbc415_rfcsync_s1 MESSAGE-ID bc415
TABLES spfli.

PARAMETERS: icarr LIKE sflight-carrid DEFAULT 'LH',


iconn LIKE sflight-connid DEFAULT '0400',
dest LIKE rfcdes-rfcdest DEFAULT 'NONE'.

DATA: sysid LIKE sy-sysid,


mess(80),
flag,
retcode LIKE sy-subrc.

CALL FUNCTION 'BC415_RFC_READ_SPFLI'


DESTINATION dest
STARTING NEW TASK 'T1'
PERFORMING back ON END OF TASK
EXPORTING
carrid = icarr
connid = iconn
EXCEPTIONS
communication_failure = 2 MESSAGE mess
system_failure = 3 MESSAGE mess.
CASE sy-subrc.
© SAP AG BC415 5-79
WHEN 2.
WRITE: / mess.
EXIT.
WHEN 3.
WRITE: / mess.
EXIT.
ENDCASE.

WAIT UNTIL flag = 'X'.

CASE retcode.
WHEN 0.
WRITE: / text-004, sysid COLOR 5.
SKIP.
WRITE: spfli-carrid, spfli-connid, spfli-cityfrom, spfli-cityto.
WHEN 1.
WRITE: / text-001, / text-002.
WHEN 2 OR 3.
WRITE mess.
ENDCASE.

*---------------------------------------------------------------------*
FORM back USING t.

RECEIVE RESULTS FROM FUNCTION 'BC415_RFC_READ_SPFLI'


IMPORTING
ex_spfli = spfli
sys = sysid
EXCEPTIONS
invalid_data = 1
communication_failure = 2 MESSAGE mess
system_failure = 3 MESSAGE mess.

retcode = sy-subrc.
flag = 'X'.

ENDFORM.

© SAP AG BC415 5-80


Unit: Remote Function Call
Theme: Transactional RFC

 Making identical changes to a customer's telephone number in two R/3


Systems using transactional RFC.

1 Screen 200 (Flow Logic)

PROCESS BEFORE OUTPUT.


MODULE status_0200.
MODULE set_values.
PROCESS AFTER INPUT.
MODULE user_command_0200.
2 Modul user_command_0200

MODULE user_command_0200 INPUT.

CASE okcode.
WHEN 'SAVE'.
CALL FUNCTION 'BC415_TRFC_CHANGE_SCUSTOM_ENTR'
EXPORTING
customer_id = scustom-id
i_telephone = scustom-telephone
EXCEPTIONS
no_data_found = 1.

IF sy-subrc <> 0.
MESSAGE a514 WITH scustom-id.
ELSE.
MESSAGE i515.
ENDIF.

CALL FUNCTION 'BC415_TRFC_CHANGE_SCUSTOM_ENTR'


© SAP AG BC415 5-81
IN BACKGROUND TASK
DESTINATION destination
EXPORTING
customer_id = scustom-id
i_telephone = scustom-telephone

CALL FUNCTION 'START_OF_BACKGROUNDTASK'


EXPORTING
startdate = sy-date
starttime = time.

COMMIT WORK.
MESSAGE i517 WITH time.

WHEN 'SM58'.
CALL TRANSACTION 'SM58'.

WHEN 'BACK'.
LEAVE TO SCREEN 100.

WHEN 'END'.
LEAVE PROGRAM.

WHEN 'CANC'.
LEAVE TO SCREEN 100.

ENDCASE.

ENDMODULE. " user_command_0200 INPUT

© SAP AG BC415 5-82

You might also like