Professional Documents
Culture Documents
SAP AG
Contents I / Week 4
Exercises
Solutions
SAP AG
Chapter 1 Basic Techniques
SAP AG
Chapter 1 Objectives
SAP AG
Linking Options Overview
R/3
External
R/3 R/2
system
SAP AG
n Communication is possible between different R/3 systems, between R/3 and R/2, between R/3 and
external systems, and also between R/2 and external systems.
Basis Interfaces of the R/3 System
R/3 System
SAP AG
n At different levels in the R/3 System, there are various data communication options. These include the
following:
This course covers the Basis techniques for direct communication (time-critical data).
n Although ABAP/4 supports the use of Native SQL, any direct database accesses to SAP tables should
be read-only. Table updates usually cause problems for data consistency because of the complexity of
table dependencies. For this reason, changes should be made using the relevant SAP transaction
programs with batch input or the ABAP/4 statement CALL TRANSACTION ... USING.
n At application level, the following Basis techniques are available:
seq. file
SAP AG
n SAP R/3 naturally supports the file transfer technique on the application server and on frontends.
n In ABAP/4, you implement the interface to the file system on the application server with the key words
READ DATASET and TRANSFER TO.
n On frontends, you implement the interface to the file system with the following function modules:
WS_UPLOAD: Reads a file in the file system where the SAPGUI is running into an internal table
in the
R/3 System.
WS_DOWNLOAD: Stores the contents of an internal table as a file on the SAPGUI machine.
Indirect Communication II
Batch input
Batch input
preparation
Import data
SD
SD FI
FI
MM CO
CO
PP
PP R/3 AM
Client / Server
QM
QM ABAP/4
ABAP/4 PS
PS
PM
PM WF
WF
HR
HR IS
SAP AG
Warehouse A
4 434518 759691
SD
SD FI
MM CO
CO
PP
PP R/3 AM
Warehouse B QM
QM
Client
Client // Server
ABAP/4
Server
PS
PS
PM
PM WF
HR IS
IS
4 434518 759691
SAP AG
n Time-critical applications such as entering warehouse movements , goods receipt, or goods issue,
require direct communication between the local warehouse computer and the central system.
Direct Communication I
SAP AG
SAP AG
n The remote call to a function module (routine) in a partner system represents a further level of
complexity in the data exchange process.
n RFC is related to RPC (Remote-Procedure-Call) in a UNIX-TCP/IP environment.
n RFC is based on CPI-C.
n SAP has implemented the RFC interface.
n For application programmers, this remote call process is much easier to handle than program-to-
program communication because data is exchanged only via defined parameters.
Direct Communication Techniques - OLE
OLE
Remote Function
Calls
CPI-C
SAP AG
n In a desktop environment, SAP components include a layered architecture for integration with R/3.
n Apart from the RFC SDK (Software Development Kit) for desktops, SAP also supplies special OLE
products for use with Windows platforms.
n OLE (Object Linking and Embedding) is a Microsoft Corporation standard. OLE 2.0 has also been
adopted by other manufacturers in their desktop applications.
n OLE is an object layer which is located above the RFC interface in desktop environments. OLE 2.0-
compatible applications can communicate with R/3 3.0 via this interface. SAP’s implementation of the
OLE layer is based on RFC API commands.
Network: TCP/IP and SNA LU6.2
R/3
TCP/IP
SAP AG
RFC
CPI-C 7
6
LU6.2 5
(APPC)
TCP/IP
4
(sockets)
3
Token Ring
Token Ring
Ethernet
Ethernet
2
SDLC
X.25
... 1
SAP AG
n In very simple terms, the ISO-OSI 7-layer model can be split into three sections:
A: At the lowest level (layer 1) are the different networks such as Ethernet, Token-Ring, X.25 etc. There
is a backup layer (2) between the network layer and the routing layer (3).
B: In the middle level (layers 3 and 4) are the transport protocols, including the well-known protocol
TCP/IP. Strictly speaking, TCP should be assigned layer 4 and IP to layer 3.
Since the SNA-LU6.2 protocol is normally based on IBM’s own SNA architecture model, it is shown in
the ISO-OSI 7-layer model on layers 3 to 6. Nevertheless, it should still be considered as a transport
protocol.
C: The session, presentation and application layers (5, 6, 7) form the upper third of the model. End-users
can only access the application layer. The programming interface CPI-C is also included at this last
level.
RFC is to be found at a higher level still. It is thus based on CPI-C.
SAP Gateway (CPI-C Handler)
R/3 R/3
SD FI
SD
SD FI
MM CO
CO
R/3 MM
MM CO
CO
PP AM
AM
PP R/3 AM
AM
Client / Server
QM ABAP/4 PS Client
Client // Server
Server
QM ABAP/4
ABAP/4 PS
PS
PM WF
PM
PM WF
HR IS
IS
HR
HR IS
SAP
gateway
IBM/SNI host
R/2
R/2
External
program
SAP AG
SAP AG
n Each system from which you set up a CPI-C communication requires a side information table. Side
information tables can be compared to telephone directories.
n The terms LU (logical unit) and TP (transaction program) come from the SNA environment. In a
TCP/IP environment, different terms are used.
n Side information tables contain parameters which are needed for communication purposes. The three
most important of these are:
Symbolic destination:
The program setting up a connection uses a symbolic destination which must exist in the side
information table. A symbolic destination can be compared with a name in a telephone directory.
Partner LU:
The partner LU (logical unit) specifies where the communication partner is to be found. It can be
compared with an address in a telephone directory.
Partner program:
The partner program is the program which is started in the partner system or the program to which the
connection is made. It can be compared with the telephone number of the partner.
Chapter 1 Summary
SAP AG
Chapter 2 Linking Options
SAP AG
Chapter 2 Objectives
SAP AG
Communication Between SAP Systems
R/3
R/3 R/3
R/3
IBM SNI
R/2
R/2 R/2
R/2
SAP AG
n The subsequent sections cover the following scenarios for communication between SAP systems:
R/3
R/3
SAP AG
n There are several options for communication between R/3 and external systems, but you have to know
whether an external platform is supported by SAP or not. To find out which platforms can be linked to
R/3, refer to SAP Supported Network Products.
n If a platform cannot be linked to R/3 through CPI-C / RFC, this does not mean that no online
communication is possible. The options for these platforms are described in the subsequent sections.
n The question of which system sets up the connection will also be discussed in more detail.
Technical Representation of the SAP Gateway
gwrd gwrd
gwhost
LU6.2
X1SA
R/2 (SNI)
gwrd
X1SA
SAP AG
n The SAP gateway or the CPI-C Handler is involved in every communication with an R/3 System.
n The SAP gateway is supplied with every R/3 System.
n The SAP gateway is a program pool in the R/3 System’s executable directory. All gateway programs
begin with "gw".
n The SAP gateway consists of the following programs:
gwhost
gwims
gwmon
gwrd
gwwp
n At runtime, you can identify gateway processes with the UNIX command "ps -ef | grep gw".
n The SAP gateway is responsible both for TCP/IP and LU6.2 connections.
SAP Side Information Tables (CPI-C)
R/2: XCOM XCOM
DEST LU TP ...
UNIX sideinfo
NT DEST = GWHOST
GWHOST = is0001
Windows GWSERV = sapgw00
OS/2 LU = hw5001
TP = sapgw00
PROTOCOL = I
SAP AG
n The side information table is a configuration table where you define the parameters that are necessary for
a communication.
n The table has a different name in different systems.
n In R/2, it is known as XCOM and can be maintained with Transaction TM31.
n In R/3, it is known as TXCOM and can be maintained with Transaction SM54 or SM31.
n In external systems, the side information table is always called sideinfo. In UNIX, for example, you can
edit side information with the editor program "vi". The side information table is used for CPI-C and RFC
connections in external systems.
The RFC Tables RFCDES (R/3) and RFCD (R/2)
SAP AG
n To implement a communication with a Remote Function Call (RFC), you must make control entries in
the relevant tables.
n For an RFC connection initiated from R/3, you need to make an entry in the table RFCDES.
n For an RFC connection initiated from R/2, you need to make an entry in the table RFCD. This entry
points to the table XCOM.
Communication Between Two R/3 Systems
hs5001, sapgw00 hs5101, sapgw01
TCP/IP
SAP AG
n Communication between two R/3 Systems is always based on the transport protocol TCP/IP.
n For R/3 - R/3 communication, you need to maintain the R/3 tables TXCOM (for CPI-C) and RFCDES
(for RFC).
n The destination Dest can be any name you choose.
n LU (logical unit - related to IBM's SNA) is the "host name" of the R/3 partner system.
n TP (transaction program name) is the sapgwXX of the partner system. Since a gateway service is assigned
to every application server, this name is unique.
n For Prot (protocol), you enter an “I” for R/3 - R/3 communication.
n The Gateway host entry is optional and specifies the host name of an alternative gateway. By default, the
system uses the gateway of the application server from which the communication is set up.
n The Gateway service entry only makes sense if there is also an entry for Gateway host. It specifies the
service sapgwXX of the alternative gateway.
n For an R/3 - R/3 RFC connection, you must make an entry in the table RFCDES. To maintain this table,
you use Transaction SM59. The connection type that you specify in the transaction is 3.
Communication Between R/3 and R/2
R/3
R/3
IBM SNI
IMS DCAM
CICS UTM
R/2
R/2 R/2
R/2
SAP AG
n Since R/3 - R/2 communication involves a number of different scenarios, you have to decide the
following:
- Which program is setting up the connection? The R/2 program or the R/3 program?
n These different scenarios are covered on subsequent pages.
R/3 à R/2 Communication (IBM)
Connection setup from R/3
hs5001 hs5002
UNIX, NT (T01) Host (K50)
SAP gateway
R/3 R/2
ABAP/4 ABAP/4
SNA subsystem
SAP AG
n For communication from R/3 to R/2, an SNA gateway must be active (i.e. an SAP gateway plus the
relevant SNA subsystem). Ideally, this should be installed as a standalone gateway.
n For the SNA-LU6.2 connection, the specific SNA product (SNA subsystem) of the hardware
manufacturer must be installed and configured on the gateway machine.
n You can find out which products are supported on which platforms, and in which version, in the overview
SAP Supported Network Products.
n In the case of a CPI-C communication between R/3 and R/2 where the R/3 System is the initiator of the
communication, you need to make an entry in der R/3 table TXCOM and an entry in the gateway table
sideinfo.
n Table TXCOM:
UNIX, NT (T01)
Host (K50) SNA subsystem
SAP gateway
R/2 Progr: gwhost
ABAP/4 R/3
SAP gateway ABAP/4
LU6.2 TCP/IP (remote)
shared memory (local)
SAP AG
n The switching program gwhost is started on the machine where the SNA software is installed. gwhost
then looks for an entry in the side information table where the destination matches the TP specification in
the R/2 table XCOM (the program started by the SNA subsystem does not have to be called gwhost - it
can be copied beforehand or a symbolic link can be set up, e.g. ln -s gwhost T01). If you want to set up a
connection from R/2 to several R/3 Systems, each R/3 System must be defined at the SNA services level
on the one hand, and have its own intermediate program (e.g. T01, T02, ... ) on the other. There must of
course also be an entry in the side information table for each R/3 System. The symbolic destination is
identical with the name of the intermediate program (DEST=T02). To reach different destinations, e.g.
different R/3 Systems, this means that the intermediate program must be declared to the SNA subsystem
under different names.
n You should ensure that the side information file can be found and read by the switching program. To do
this, you need to know the identity of the user who started the program. Of course, the authorizations of
the side information file must be set so that the user can read them.
n The switching program is required for CPI-C and RFC connections.
n For an RFC connection, you need to make the appropriate entry in the table RFCD.
R/3 à R/2 Communication (SNI)
Connection setup from R/3
SAP AG
n On the external machine (BS2000), there must be an SAP gateway active (the connection must be set up
from the gateway of the BS2000 host).
n On BS2000 machines, the SAP gateway can be accessed via TCP/IP. However, the following
requirements must be satisfied:
SAP AG
n The connection is set up via the SAP gateway of the R/3 System.
n The communication is made by an intermediate step in the program gwhost which is running on the
BS2000 host.
n Entries in the side information tables:
Dest=<program name>(gwhost)
LU=<target machine> (host name_1)
TP=<dispatcher> (sapdpXX)
GWHOST=<GW machine> (host name_2)
GWSERV=<GW services> (sapgwYY)
Protocol=<I> (I)
n For an RFC connection, you need the appropriate entry in the table RFCD.
R/3 à External Program (UNIX)
External program on SAP-supported UNIX platforms
hs5001, sapgw00 hs5002, sapgw01
UNIX (T01) UNIX UNIX
SAP AG
n For an RFC connection, you need to make the appropriate entry in the table RFCDES with Transaction
SM59.
n Since the SAP gateway uses the values in TXCOM or RFCDES, you do not need an entry in the side
information table. The external program is started via the SAP gateway.
n A distinction is made as to whether the SAP gateway runs on the same machine as the external program
or not.
The SAP gateway has a particular ID which corresponds to the user name (c11adm) used to start it.
==> The external program must be in the user’s search path and able to be started with this ID
The SAP gateway starts the external program with Remote Shell or Remote Execute. Also, the above user
must be known in the target system and have an entry in the .rhost.
R/3 à External Program (TCP/IP)
l Systems not supported by SAP, but accessible via
TCP/IP
UNIX, NT
R/3
SAP gateway
CPI-C / RFC
socket program
TCP/IP
DEC OpenVMS
HP MPE
External IBM host system
socket program IBM AS400
SNI host system
...
SAP AG
n You can also connect external systems online to R/3 Systems for which there is no CPI-C / RFC support.
n This section covers systems which are accessible via TCP/IP.
n Systems accessible via TCP/IP always provide programming-API sockets. The socket interface is the
API of TCP.
n An SAP CPI-C / RFC program can thus communicate with a socket program.
n This means, for example, that you can connect DEC OpenVMS machines, HP MPE machines, IBM
hosts, the IBM AS400 series, as well as SNI hosts via the TCP/IP protocol.
n A CPI-C / RFC gateway program, which communicates a) with R/3 via CPI-C or RFC and b) with the
external socket program via sockets, thus assumes the gateway function. You must develop this gateway
program to suit your own requirements.
n From the point of view of the R/3 System, only one CPI-C or RFC program is started (see also previous
page).
R/3 à External Program (Windows NT)
UNIX, NT
R/3
SAP gateway
SAPgui
TCP/IP
data stream (TCP/IP)
NT NT
SAP gateway
e
SAPgui x e c
External External
program program
SAP AG
Dest LU TP Prot
R3FE Dummy Ext. prog. F
SAPgui
data stream (TCP/IP)
UNIX, NT Windows
R/3 External
SAPgui c program
SAP gateway exe
SAP AG
n An external program, usually an RFC program, is started on a Windows machine by the SAPgui. Here,
you cannot call the program through the SAP gateway.
n Entry in RFCDES with Transaction SM59:
Connection type: T
Program location: User
Program: c:\tmp\extpgm
n A frontend program is connected to an R/3 System via the SAP gateway which is running on an NT or
UNIX machine.
n For WfW and Windows 3.1, the CPI-C interface is not supported.
R/3 à External Program (OS/2)
UNIX, NT
R/3
UNIX, NT
SAP gateway
SAPgui
TCP/IP
data stream (TCP/IP)
OS/2 OS/2
exe
SAPgui c
External External
program program
SAP AG
n Under OS/2, the situation is the same as with Windows NT. You can start a program from the SAPgui or
through the SAP gateway. Since OS/2 has a multi-user capability, the SAP gateway does not have to be
on the OS/2 system.
n An external program in OS/2 is connected to R/3 via the SAP gateway.
n Under OS/2, you can start an external program from the SAPgui, via remsh or from a remote SAP
gateway.
n The external program is started via remsh:
Entry in TXCOM:
Entry in TXCOM:
Dest LU TP Prot Gateway host Gateway
service
R3FE host name_1 Ext. prog. E host name_1 sapgwXX
n For an RFC connection, you must make the appropriate entry in the table RFCDES with Transaction
SM59.
R/3 à IBM Host / AS400
External program based on IBM CPI-C or APPC
UNIX
R/3
OS/2
UNIX SAP gateway
NT SNA subsystem
LU6.2 LU6.2
APPC APPC
CPI-C CPI-C
SAP AG
n If a machine can be accessed via the SNA protocol LU6.2, it always has at least the programming API
APPC (Advanced Program to Program Communication). Communication between external APPC and
SAP CPI-C programs is possible.
n Normally, systems accessible via LU6.2 have CPI-C, which is easier to use and itself based on APPC.
This means that communication between external CPI-C programs and SAP CPI-C programs is
guaranteed.
n Machines in the IBM AS400 series have both APPC und CPI-C. External programs are started via
SNA-LU6.2:
Entry in TXCOM:
The name of the TXCOM destination corresponds to an entry in the side information of the SAP gateway
(see also R/3 - R/2 Communication with connection setup from R/3).
n Calling an external RFC program is not possible because, at present, no SAP RFC SDK (Software
Development Kit) is supplied for the above platforms.
External Program (TCP/IP) à R/3
hs5001, sapgw00
T01
R/3
ABAP/4
TCP/IP
Dest = T01
LU = hs5001
TP = sapgw00
GWHOST = hs5001
GWSERV = sapgw00
Protocol = I
SAP AG
n The side information table "sideinfo" on the source machine must be in the current directory.
Alternatively, before calling the program, you must place the SHELL variable SIDE_INFO in the path
where the side information table is located.
n The side information table "sideinfo" for the SAP gateway is stored in the data directory (e.g.
/usr/sap/<SID>/DVEBMGS00/data) and defined for the SAP gateway ID (<SID>adm) by the SHELL
variable SIDE_INFO.
n The information in the side information tables can be wholly or partly taken from the external program
(see SAP_CMINIT, RFC connections).
n If the external program and the SAP gateway are running on the same machine, the entry in the side
information table can contain all information:
DEST=<Symbolic destination>
GWHOST=<GW machine>
GWSERV=<GW services>
PROTOCOL=<I>
LU=<Target machine>
TP=<Gateway>
External Program (LU6.2) à R/3
hs5001, sapgw00
UNIX, NT (T01)
External system SNA subsystem
SAP gateway
External program Program: gwhost
R/3
SAP gateway ABAP/4
LU6.2 TCP/IP (remote)
shared memory (local)
Dest = T01
LU = hs5001
TP = sapgw00
GWHOST = hs5001
GWSERV = sapgw00
Protocol = I
SAP AG
n If the source machine is not an IBM host, this type of communication is only possible if both LU6.2
products support peer-to-peer communication (PU type 2.1).
n Calling an external RFC program is not possible because, at present, no SAP RFC SDK (Software
Development Kit) is supplied for platforms accessible via LU6.2.
n All other requirements are the same as those already listed for R/2 -> R/3 communication.
Gateway Monitor
SAP AG
n The purpose of the gateway monitor is to monitor connections. It allows you to display all the
connections currently managed by an SAP gateway. The gateway monitor includes the following
functions:
SAP AG
Chapter 3 Remote Function Call
l Synchronous RFC
l Asynchronous RFC
l Transactional RFC
SAP AG
Chapter 3 Objectives
SAP AG
Supporting RFC on Heterogenous Platforms
R/3
R/3
RFC
RFC
RFC
R/2
R/2 External
External
R/3
R/3 system
system
RFC
SAP AG
Development environment:
Remote debugging
RFC generator
SAP AG
n The conversion of data for transfer between linked systems is performed automatically.
n LOGON to the SAP partner system is also performed automatically (the user’s name and password are
stored in the table RFCDES).
n For single parameters, the conversion of all data types (CHAR, NUMC, DATE, TIME, HEX, FLTP,
INT) is supported. Please note that you should not use mixed data types (i.e. character and numeric
types) in the same transfer structure (structures and internal tables).
n The communication flow between programs is controlled internally.
n For R/3-to-R/3 connections, the RFC development environment provides remote debugging.
n The RFC generator allows you to create external RFC programs (server and client) in C or Visual
Basic.
ABAP/4 Function Modules
Function Library
FM group: FIBU
FM_01 ... FM use
FM maintenance PROGRAM ...
FM_02 ...
FM_02 TABLES ...
FM group: ZIBU
Interface
FM_03 ...
Import
FM_04 ... CALL FUNCTION
Export 'FM_02'
Tables EXPORTING ...
IMPORTING ...
Exceptions
Program
Documentation
Administration
SAP AG
n ABAP/4 function modules are divided into function groups in the Function Library. A function group
contains functions which perform similar tasks (e.g. calendar functions) or work with the same data (1st
function fills an internal table, 2nd function edits an internal table, ...).
n You can assign a group to a particular application (FI, HR) or flag it for general use (*).
Local Call of Function Modules
n In R/3, function modules are ABAP/4 programs which are stored centrally in the Function Library.
They can be called locally by any ABAP/4 program. Function modules are similar to functions in C, and
procedures in PASCAL or COBOL. Both C functions and PASCAL or COBOL procedures are also
stored in a central library.
n Function modules have a defined interface. Input parameters are passed to them via the IMPORTING
or CHANGING interface. Single result parameters can be returned via the EXPORTING and
CHANGING interface, but internal tables are passed to the TABLES interface. When creating a
function module, you can define IMPORTING parameters as optional. Since they have a predefined
value, you do not have to assign a value when calling a function module.
n Interface parameters should reference Dictionary reference structures.
n CHANGING parameters contain fields or field strings which can be passed from the program to the
function module when the function module is called, and returned to the calling program when the
processing of the function module has finished.
n For each function module, you can raise exceptions which the function module can trigger if an error
occurs.
n You maintain function modules with Transaction SE37.
External Functions
External program
RFC SDK
... ( SAP )
...
LINK
Call RFC function A RFC library
... RFC function set:
RFC function A
RFC function B
...
Function 1
(Prg. routine) Standard functions:
Function A
Function 2 Function B
(Prg. routine) ...
...
SAP AG
n The SAP RFC SDK (Software Development Kit) is delivered with all R/3 Systems.
n As in the CPI-C SDK, the RFC SDK contains executable programs for the relevant hardware platform,
libraries, include programs, and also ABAP/4 and C programs. Accompanying text files describe the
structure of the SDK and provide information about how the programs are to be compiled on the
different platforms.
n The RFC libraries provide the functionality for creating external client or server programs
(programming languages include C and Visual Basic - in general, all languages which allow you to link
C libraries). Essentially, the libraries contain the calls required for RFC such as OPEN, ACCEPT and
SEND. They also provide a number of standard function routines for testing purposes.
REMOTE FUNCTION CALL (RFC)
SAP system A
FUNCTION FUNC.
DESTINATION 'DEST'
...
EXPORTING
f1 = a1 ENDFUNCTION.
IMPORTING
f2 = a2 External program
CHANGING
f3 = a3 C routine
TABLES
t1 = tab ...
EXCEPTIONS
COMMUNICATION_FAILURE = 1
SYSTEM_FAILURE = 2
...
SAP AG
n Function modules can also be called by remote systems if the function module is designed for RFC.
n If SAP R/2 or R/3 is the RFC server system, the function module name is FUNC. If a C program is the
RFC server program, FUNC is the name of a function installed previously with RFC API.
n DEST is the symbolic destination of the partner system. The destination must be defined in the table
RFCDES.
n You can use the EXPORTING and IMPORTING parameters to pass and receive field or field string
values.
n With CHANGING, you can pass values of fields or field strings to or from the function module.
n With TABLES, you can pass references to internal tables. Table parameters should have homogenous
data types.
n All interface parameters must refer to Dictionary reference structures (unlike local calls to function
modules).
n You use the EXCEPTIONS parameter to specify the exceptions the calling program is to handle itself.
Function Modules: RFC Capability
l Transaction: SE37, Administration
l RFC-enabled function modules
Process type
Normal
FUNCTION TEST.
SELECT *...
ENDFUNCTION.
SAP AG
n To start a function module by remote start, it must be flagged as RFC-enabled in the function module
administration facility. If RFC support is set, the system generates an import stub when you create the
module. This import stub is part of an ABAP/4 program and is executed when the function module is
called by a remote system.
Table RFCDES
RFC destinations
+ R/2 connections
+ R/3 connections
+ Internal connections
+ Logical connections
+ CMC connections
+ SNA/CPI-C connections
+ TCP/IP connections
+ Connections via ABAP/4 driver
SAP AG
I Internal: Same SAP system; communication from application server to application server.
( => same database). You cannot maintain this type. When the system is started, the entries are set
automatically.
2 Partner system is an R/2 System.
3 Partner system is another R/3 System => other database.
S Partner is a program which can be accessed via the LU6.2 protocol. No RFC SDKs are yet
available
for these platforms. Such a partner program would have to use hard APPC calls.
L Logical partner:
Reference is to an existing destination. Existing values (e.g. user name and password) can be
overwritte and new values can be added.
M CMC (Common Messaging Call) connection. This destination is designed for an R/3-to-R/3
connection
which uses the standard programming interface CMC for mail systems.
T Partner is an external RFC program based on TCP/IP.
X The RFC data flow can be passed to a self-defined ABAP/4 program
(ABAP/4 CPI-C program).
n Similarly, R/2 contains the table RFCD (which references the table XCOM).
Destinations BACK, SPACE and NONE
System A System B
...
...
...
...
ENDFUNCTION. Result A
Result B ENDFUNCTION.
SAP AG
n When executing a RFC function, you can call an RFC-enabled function in the calling system with
CALL FUNCTION ... DESTINATION 'BACK'. You can use the BACK destination with RFC
between two R/3 systems and between R/3 and external C programs (RFC SDK), as well as with the
RFCDES connection types 3 and T.
n Two functions can call each other recursively.
n If you want to execute a function module locally, you specify the destination SPACE.
n You specify the destination NONE if you want to execute a function module locally, but the call to be
performed is technically a REMOTE call (i.e. via a gateway). (See RFC test without partner system.)
Remote Debugging
R/3 A R/3 B
...
SAP AG
PROGRAM RS01.
.
.
.
CALL FUNCTION 'FUNC1'.
DESTINATION 'B' FUNCTION FUNC1.
STARTING NEW TASK 'ABC' ...
EXPORTING ... ENDFUNCTION.
TABLES ...
.
.
.
SAP AG
n You use STARTING NEW TASK to generate a new task which calls the function module. The
original program continues to run after the remote function call has been started.
n The client program in the above example can receive no confirmation messages from the called
function module since IMPORTING, CHANGING or EXCEPTIONS are not possible with CALL and
because the connection is closed right after the CALL. You also cannot use the destination BACK in the
called function module.
n If the called function module performs dialogs, the relevant screens are displayed in the client system in
the new session.
n Using this technique, you can not only make connections to another remote R/3 System, but you can also
execute remote function modules on any computer in your own R/3 System (with distributed systems).
Asynchronous RFC with Return of Data
R/3 server A R/3 server B (same or other R/3)
PROGRAM RS01.
...
CALL FUNCTION 'FUNC1'.
DESTINATION 'B' FUNCTION FUNC1.
STARTING NEW TASK 'ABC'
PERFORMING FUNC1_RETURN ON END OF TASK.
EXPORTING ... ...
TABLES ...
...
AT USER-COMMAND.
...
SAP AG
n In the above example, the called function module can return data or exceptions to the client program,
although the function module has been started asynchronously. By using the PERFORMING addition,
you ensure that the connection to the partner remains open.
n When the called function module is processed, the FORM routine specified after the CALL-FUNCTION
parameter PERFORMING is called.
n The FORM routine must have a formal parameter (any name is allowed). This parameter is supplied
automatically with the relevant task ID when the routine is called.
n By using RECEIVE RESULTS FROM FUNCTION ... in the FORM routine, you can get the
asynchronously processed function module to return data and exceptions. By using the SET USER-
COMMAND statement, you can start the program event directly.
Asynchronous RFC: Parallel Processes
PROGRAM PARAL01.
...
CALL FUNCTION 'A'
DESTINATION '1'
STARTING NEW TASK 'A'
PERFORMING 'BACK' ON END OF TASK.
CALL FUNCTION 'B'
DESTINATION '2'
STARTING NEW TASK 'B'
PERFORMING 'BACK' ON END OF TASK.
...
FORM BACK USING TASK.
CASE TASK.
WHEN 'A'. ... AFLAG = 'X'.
WHEN 'B'. ... BFLAG = 'X'.
ENDCASE.
SET USER-COMMAND 'CHECK'.
ENDFORM.
AT USER-COMMAND.
CASE SY-UCOMM.
WHEN 'CHECK'.
IF AFLAG = 'X' AND BFLAG = 'X'.
...
SAP AG
n By starting several RFCs with STARTING NEW TASK, you can roll out calculations to other servers
(with distributed systems) or systems, or run them in parallel.
n If you have to wait for the result of some or all called function modules, you can control this in the list
environment via the event AT USER-COMMAND by setting flags.
n Note:
You can perform the same action in a dialog chain (screen sequence) without using SET USER-
COMMAND to trigger the AT USER-COMMAND list event. Please note that the function modules
first run separate from the client program. You do not know when the individual function modules have
finished or, consequently, when the relevant FORM routine is internally triggered. The processing of the
FORM routine is inserted into the current PAI event of the client program. PAI is then processed again
from the beginning.
RFC Dialog
R/3 System 1 R/3 System 2
Variant 1: Synchronous
PROGRAM RS01. FUNCTION DIALOG.
... ...
CALL FUNCTION 'DIALOG'. CALL SCREEN '100'.
DESTINATION ... ...
... ENDFUNCTION.
Screen
Screen 100
100 Screen
Screen 100
100
Variant 2: Separated
PROGRAM RS01.
...
CALL FUNCTION 'DIALOG'.
DESTINATION ...
STARTING NEW TASK 'A'...
Caller
Caller Screen
Screen 100
100
session
session
1st session 2nd session
SAP AG
n RFC dialog (or RFC with screens) allows you to display screens (dialog and list screens) in the client
system and process them in a remote system within a RFC.
n In the called function module, you can call a screen using (for example) CALL SCREEN. The screen is
then transported and displayed in the client system. The same applies to CALL TRANSACTION,
SUBMIT AND RETURN, and CALL DIALOG.
n There are two call techniques:
1) Synchronous RFC:
Here, the client program executes the call and waits until the called function module has finished. All
dialog steps executed by the called function module are displayed in the original session of the client
program. Only when the function module is finished does the client program continue processing after
CALL FUNCTION.
Here, the client program continues processing directly after CALL FUNCTION. The function module is
run asynchronously on a remote system. All dialog steps executed by the called function module are
displayed in a new session in the client system. RFC dialog thus behaves like a remote login.
n Transaction SC38 allows you to start a R/2 program. The list output of the this program is displayed in
the R/3 SAPGUI.
Transactional RFC (tRFC)
R/3
R/3
Table RFCDES:
SD FI
MM
MM
PP
PP
QM
QM
R/3
Client
CO
CO
Client // Server
ABAP/4
Server
AM
AM
PS
TRFC options
ABAP/4
PM
PM WF
WF
HR
HR IS
IS
R/3
R/3
tRFC
Automatic job Function
Job module(s)
scheduling MM
SD
SD FI
FI
CO
CO
PP
PP R/3 AM
Client / Server
QM
QM ABAP/4
ABAP/4
PS
PS
PM
PM WF
HR IS
IS
Program
with tRFC
Administration tables
Administration transaction
DB
SM58
SAP AG
n Transactional RFC (tRFC): You can also submit Remote Function Calls when the target system is not
available. For example, the connection to a partner system may have been interrupted or the partner
system itself is not currently active.
n The function module is flagged to be run asynchronously. It is not executed immediately, but the data
passed with EXPORTING or TABLES is stored in a database table.
n Automatic job scheduling is performed. The job starts the relevant function module(s) in the partner
system.
n You set parameters for the relevant connection via the table RFCDES:
PROGRAM ASYN01.
.
.
.
CALL FUNCTION 'A'
DESTINATION '1'
IN BACKGROUND TASK
EXPORTING ...
TABLES ...
...
COMMIT WORK.
SAP AG
Exactly Once!
COMMIT WORK.
n By using CALL FUNCTION ... IN BACKGROUND TASK, you store the called data in internal
tables.
n COMMIT WORK stores the context data of the function calls in the database (general data such as the
name of the function module in table ARFCSSTATE; concrete data passed with CALL in table
ARFCSDATA). Then, the send job is scheduled.
n The send job reads the database tables ARFCSSTATE and ARFCSDATA and tries to set up a
connection to the partner system. If an error occurs, the send job is re-scheduled.
n You can analyze the log file with Transaction SM58. This allows you to display and edit function calls
that have not yet been executed.
n If you want to send an LUW later, you can specify this event by calling the function module
START_OF_BACKGROUNDTASK before COMMIT WORK.
RFC Between R/3 and External Programs
ABAP/4
...
CALL FUNCTION... External
DESTINATION... RFC server
... program
RFC
Function module
FUNCTION... External
RFC client
ENDFUNCTION. program
SAP AG
n ABAP/4 programs can exchange data with an external program via the RFC interface.
n External programs can call a function module in the R/3 System via the RFC interface.
External RFC Program: Client
RfcOpen(...);
...
RfcCall(...);
...
RfcReceive(...);
...
} RfcCallReceive (...);
RfcCall(...);
...
RfcReceive(...);
...
RfcClose(...);
SAP AG
n The above program is an RFC client program, i.e. it initiates a communication and connects to the RFC
server program.
n RfcOpen sets up a connection to the partner system (INIT, ALLOCATE, LOGON). You are then
logged on to the SAP system.
n RfcCall calls a function module (SAP system) or a function (external system) and transfers parameters
and tables.
n RfcReceive allows you to receive replies after RfcCall has been called. RfcReceive waits until a reply
has been received.
n Instead of RfcCall and RfcReceive, you can use a function called RfcCallReceive.
n RfcClose closes the conversation with the partner system.
n Between a CALL and a RECEIVE you can always use a RfcLists. This tells you whether a function has
been processed or whether the connection is still open.
n You pass connection parameters via RfcOpen (at least the client, user name and password) or a side
information file. From Release 3.0, you should use saprfc.ini as the side information file. You can also
use the following features:
--> Addressing R/3 via load balancing (specify the message server)
--> An external server program can be registered at an SAP gateway
(--> Demon). This saves the start time usually required (performance option).
External RFC Program: Server
main(...)
{ ...
RfcAccept(...)
...
RfcInstallFunction(...)
...
RfcDispatch(...)
...
RfcClose(...)
}
...
RfcSendData(...)
}
SAP AG
n The above example demonstrates how an external RFC server program should be structured.
n RfcInstallFunction installs all RFC-enabled functions in this program. You must explicitly declare all
program functions. This allows RfcDispatch to find them.
You can call these in R/3 from the menu bar of Transaction SM59 when you display a RFC destination
(system information: target system, function list, test connection)
n RfcDispatch waits for a function call for an internal program function and subsequently calls this
function.
The SAP RFC SDK
rfcsdk/bin/rfcexec
sapinfo
startrfc
srfctest
srfcserv
trfctest
trfcserv
lib/librfc.a
include/sapitab.h
saprfc.h
text/*.doc
*.txt
*.c
SAP AG
n The SAP RFC SDK (Software Development Kit) is delivered with every R/3 System.
n The RFC SDK contains executables, libraries, include files as well as ABAP/4 and C programs for the
hardware platform. Text files describe the structure of the SDK and explain how the programs on the
various platforms are compiled and connected.
n The bin directory contains a number of executables which provide test and special functionality.
n The lib directory contains the function library.
n Data types and prototypes of the RFC calls are defined in the saprfc.h file.
n Functions for the handling of internal tables are stored in the sapitab.h file.
Desktop SDK (for Windows)
Desktop SDK
RFC SDK
lib\librfc.dll ( --> 16 oder 32 Bit )
...
help
SAP AG
n In Windows environments, RFC SDK is delivered with special utilities for constructing application
solutions in the area of desktop integration.
n The desktop SDK contains additional and Windows-specific documentation concerning desktop
integration questions (see the directory help). It also provides Windows-specific software layers which
hide the actual RFC calls and thus facilitate the access to RFC solutions. Some of these additional layers
are offered as C++ classes.
n The RFC Logon Manager provides a standardized logon dialog which all RFC applications under
Windows can use. It also allows you to monitor active RFC sessions.
n Visual RFC (VRFC) provides optimized session management (optimized usage of sockets on the PC)
and also a number of standard dialogs (e.g. logon dialog).
SAP RFC Programs
l sapinfo R/3
R/3
l startrfc
l rfcexec
l srfctest
SD FI
l srfcserv MM
PP R/3
CO
Client / Server
AM
QM ABAP/4 PS
PM WF
HR IS
l trfctest
l trfcserv
SAP AG
n The RFC SDK (Software Development Kit) contains three executable programs which are also available
in C source code. These programs are as follows:
sapinfo: Client program which sets up the connection to the partner system and retrieves various
system
information. It can be used as a connection test program.
startrfc: Client program which can start any function module in the SAP system, pass parameters
or
tables to it, and receive results in the form of parameters and tables. RFC program for
connecting external systems to an SAP System.
rfcexec: Server program which is started by an SAP system and allows you to start several
predefined
functions. It can also be used for testing the connection between an SAP system and an
external
system.
srfctest: Client program for synchronous RFC (connection and performance tests possible).
srfcserv: Server program for synchronous RFC (connection and performance tests possible).
trfctest: Client program for transactional RFC
trfcserv: Server program for transactional RFC
RFC Server: rfcexec
n Three functions of rfcexec:
u RFC_REMOTE_PIPE
u RFC_REMOTE_FILE rfcexec
rfcexec
remote-pipe
remote-pipe
u RFC_REMOTE_EXEC {{
...
}}
remote-file
remote-file
{{
...
}}
Start remote-exec
remote-exec
R/3
R/3
Output {{
...
}}
start
MM
MM
PP
SD
SD
R/3
FI
FI
CO
CO
AM
AM
remote pipe
Client / Server
QM ABAP/4 WF
PS
PS
PM WF
HR
HR IS
SAP AG
n The SAP RFC server program rfcexec provides the three following functions as standard:
RFC_REMOTE_PIPE
Can call an operating system command or start a program. The programs’s standard output is redirected
to the SAP system and output in the SAPGUI.
RFC_REMOTE_FILE
Allows the system on which the rfcexec is started to read a file into an internal table. The contents of the
internal file can also be stored as a file on the external system.
RFC_REMOTE_EXEC
Can start a program without having to redirect the output of the program to the SAPGUI.
RFC: Connection and Performance Test
ABAP/4 program SRFCTEST
R/3 ABAP/4:
Start
Server: Function modules
Client program: SRFCTEST Possible RFC tests:
1. CONNECTION
External RFC programs: 2. PERFORMANCE
3. TRANSACTIONAL RFC
Client program: srfctest
Server program: srfcserv Selection
Client program: trfctest
Server program: trfcserv Destination dest_srfcserv
...
Result list
SAP AG
n Both the R/3 System and the libraries contain a number of test programs. The functionality covers
everything from connection tests to performance measurement.
ABAP/4:
SRFCTEST After starting the program, you must select the desired execution option (with the
cursor). You then specify the Logical destination and the No. of desired function
calls
(only relevant with the execution option PERFORMANCE). The execution
options
PERFORMANCE and TRANSACTION RFC allow you to specify a number of
additional parameters (e.g. the number of table lines).
C:
srfctest Client program for synchronous RFC (calls an ABAP/4 function module or a C
function)
srfcserv Server program for synchronous RFC (can be used as partner program for
srfctest or
SRFCTEST
trfctest Client program for transactional RFC
trfcserv Server program for transactional RFC
n The programs use the destination NONE as the default. If you want to test other destinations, you must
maintain the table RFCDES first.
RFC Generator
SAP AG
n The RFC generator is available from Release 2.1G or 2.2A. From Release 3.0, full functionality is
available as far as the generation of server programs is concerned.
n For an existing function module with a fully defined interface, the RFC generator generates the relevant
C or Visual Basic programs (in the client or server version).
n If you want to generate an external server program, you first have to create a dummy function module
(interface!) in R/3 (analogous to the desired function in the external server program).
RFC Generator for C Programs
R/3
FI
CO
CO
AM
AM
R/3 generates
generates
QM
QM
PM
PM
Client
Client // Server
ABAP/4
Server
WF
WF
PS
programs
programs
HR
HR IS
......
main(
main() )
R/3
R/3 {{
RfcOpen(...);
RfcOpen(...);
......
RfcCallReceive(...,"ABC",...);
RfcCallReceive(...,"ABC",...);
RFC
RFC request
request
FUNCTION
FUNCTIONABC.
ABC. ......
DATA_PROCESSING RfcClose(...);
RfcClose(...);
DATA_PROCESSING }}
ENDFUNCTION. result
result
ENDFUNCTION.
SAP AG
n In Transaction SE37, you can start the RFC generator by choosing Utilities->Interface->Generate.
You have to be in the interface display or change mode of this function module. There, you can generate
C programs.
n In the subsequent dialog box, you can specify which programs are to be generated. You can also enter
the directories where the individual files are to be stored after the generation on the frontend machine.
n After the generation process has been completed, the individual files are transferred to the frontend.
n The accompanying text files include a description of the files to be generated or loaded on the frontend.
They also describe the compilation and/or the linking of the programs.
RFC Generator for Visual Basic Programs
R/3
FI
CO
CO
AM
AM
R/3 generates
generates
QM
QM
PM
PM
Client
Client // Server
ABAP/4
Server
WF
WF
PS
programs
programs
HR
HR IS
REM
REM function
functionmodule
module
DIM
DIM ......
R/3
R/3 DIM ......
DIM
RfcReceiveTxt
RfcReceiveTxt( () )
RFC
RFC request
request
FUNCTION
FUNCTIONABC.
ABC. ......
DATA_PROCESSING
DATA_PROCESSING
ENDFUNCTION. result
result
ENDFUNCTION.
SAP AG
n You can use the RFC generator to generate Visual Basic programs. Downloading generated Visual
Basic programs only makes sense on Windows platforms which support Visual Basic.
n The generated program starts the corresponding SAP function module without you having to include any
Visual Basic code.
RFC Example in Visual Basic
Declare Function RfcOpenExt Lib "librfc.dll" ...
Declare Sub RfcClose Lib "librfc.dll" ......
hRfc = RfcOpenExt(destination, mode, host, sysnr, ...)
...
hSpace = RfcAllocParamSpace(3, 0, 1)
rc% = RfcAddExportString(hSpace, 0, "COMPANY", 7, 0, 4, MyCompany)
rc% = RfcAddExportString(hSpace, 1, "CUSTOMER", 8, 0, 10, MyCustomer)
rc% = RfcAddExportString(hSpace, 2, "YEAR", 4, 6, 4, MyYear)
thSales = ItCreate("SALES", 20 , 0, 0)
rc% = RfcAddTable(hSpace, 0, "SALES", 5, 0, 20, thSales)
RfcRc = RfcCallExt(hRfc, hSpace, "GET_SALES_BY_MONTH")
...
If RfcRc = 0 Then
RfcRc = RfcReceiveExt(hRfc, hSpace, xException)
End If
If RfcRc = 0 Then
MsgBox "Function Call Failed !"
RfcClose(hRfc)
End If
SAP AG
n The above example shows RFC calls in a Visual Basic program fragment. Many details have been
omitted, including the access to the results of the function calls, but you the fragment does contain the
code for the following tasks:
Declaring RFC calls
Logging on to the R/3 System
Defining the parameters and calls
Error handling
Chapter 3 Summary
SAP AG
Exercise for Chapter 3
Report name: ZBCE##C1
Function group: ZE##
Function module: Z_BC415_##_...
Logical destination: BC415_##
##: Group number
Implement an RFC communication between two R/3 systems
to read data (airline carrier information) from a server system
and output it in the client system.
Proceed as follows:
3. Use the ‘A’ mode for the transaction to be called during the
function module call.
CASE SY-SUBRC.
WHEN 1.
WRITE: / 'You have selected an invalid carrier ID.'.
EXIT.
WHEN 2.
WRITE: / MESS.
EXIT.
WHEN 3.
WRITE: / MESS.
EXIT.
ENDCASE.
LOOP AT CARRITAB.
WRITE: / CARRITAB-CARRID,
15 CARRITAB-CARRNAME,
40 CARRITAB-CURRCODE.
ENDLOOP.
FUNCTION TRAIN415_RFC_GET_CARRIER.
*"----------------------------------------------------------------
-
*"*"Local interface:
*" IMPORTING
*" VALUE(CARRID) LIKE SCARR-CARRID DEFAULT SPACE
*" TABLES
*" CARRIER STRUCTURE SCARR
*" EXCEPTIONS
*" NO_CARRIER_FOUND
*"----------------------------------------------------------------
-
IF CARRID NE SPACE.
TRANSLATE CARRID USING '+_*%'.
ELSE.
CARRID = '%'.
ENDIF.
IF SY-SUBRC NE 0.
MESSAGE E038 RAISING NO_CARRIER_FOUND.
* No data for this selection (New input please)
ENDIF.
ENDFUNCTION.
Solution 2 for Chapter 3
*&----------------------------------------------------------------
*
*& Report RS415032
*
*&
*
*&----------------------------------------------------------------
*
REPORT RS415032.
CUSTITAB-TELEPHONE = PHONE.
CUSTITAB-ID = CUSTID.
APPEND CUSTITAB.
CUSTITAB-TELEPHONE = PHONE.
CUSTITAB-ID = CUSTID.
APPEND CUSTITAB.
IF SY-SUBRC <> 0.
EXIT.
ELSE.
COMMIT WORK.
ENDIF.
Chapter 4 ABAP/4 Desktop Integration
Components
SAP AG
Chapter 4 Objectives
SAP AG
Why Desktop Integration?
SAP AG
n The integration of existing desktop programs is a decisive factor in the context of open interfaces to the
R/3 System.
n Since the intention is to employ current programming languages to enable users to access data in R/3,
SAP supplies the RFC SDK (Software Development Kit) for frontend platforms.
n If you want to access desktop documents or objects in desktop applications from R/3, Windows
frontends now allow you to make use of special desktop functionality such as OLE (Object Linking and
Embedding) for MS Windows environments which is within the scope of ABAP/4 in R/3.
SAP Desktop Integration: Tools
SAP AG
n For desktop integration purposes, you can use the complete RFC SDK (Software Development Kit) as
supplied for all other R/3 platforms (e.g. UNIX, Windows NT). The RFC SDK is imported explicitly to
frontends by the SAP installation program SAPSETUP.EXE which allows you to opt for "individual"
installation by selecting components of the SAP frontend programs to suit your own requirements. The
RFC SDK is included in the component "Desktop Development Kit".
n In addition to the normal functionality of the RFC SDK, Windows frontends include the sub-directory
SAPSRV with OLE 2.0 Automation-specific implementations. These programs are covered in more
detail later.
Objects, Methods and Properties
Behavior
Restrictions
Core object Rules
Properties
Interfaces
Components
Sub-types Methods
Events
SAP AG
n Objects, methods and properties are terms from the field of object-oriented programming. Before
concentrating in more detail on OLE-specific programming, these terms should be explained.
n Objects have properties which characterize the objects. You can select and set these properties.
n To perform special functions on the objects, you define methods (functions).
n The objects themselves can be defined in object hierarchies where you can work with inherited properties
and methods.
n In R/3, function modules are now presented as objects which R/3 makes available externally via the
object-oriented interface (OLE Automation). There is thus an RFC object hierarchy.
Component Architecture
OLE
Remote Function
Calls
CPI-C
SAP AG
n In a desktop environment, SAP components for integration with R/3 have a layered architecture.
n The CPI-C foundation layer offers low-level program-to-program communication from the desktop with
an R/3 application server via TCP/IP. CPI-C itself is not available as an API for development on all
desktop platforms.
n The RFC layer allows access to function modules from a wide range of platforms. Here, the underlying
CPI-C commands are concealed and transparent to the user.
n OLE (Object Linking and Embedding) is an object layer which is located above the RFC interface in a
desktop environment. OLE 2.0-compatible applications can communicate with R/3 Release 3.0 via this
interface. SAP’s implementation of the OLE layer is based on RFC API commends.
Object Linking and Embedding (OLE)
What is OLE?
n Object Linking and Embedding enables Windows applications
to make use of functions in an highly integrated manner.
n The Excel table below has been integrated into PowerPoint.
SAP AG
n Originally, OLE was supposed to stand for Object Linking or Embedding, since the term OLE embodies
two quite different processes.
n Object Linking is very similar to DDE (Dynamic Data Exchange) which is a further development of a
intermediate file used by different programs to exchange data. For example, the OLE server program
selects data and copies it to the intermediate file, while the OLE client program can retrieve the data. The
retrieval can be performed in a number of different ways. The advantage of OLE over DDE is that the
OLE server program is also responsible for displaying the data, as shown above. Here, PowerPoint is the
OLE client program which has imported the table from the OLE server program Excel.
n Object Embedding is more widespread than Object Linking. Here, an object is completely embedded in
an OLE client program. The data must then be managed by the OLE client program. The OLE server
program is called only if new objects are retrieved or exisiting objects are changed.
n Object Automation represents a considerable enhancement of OLE 2.0. It allows OLE server programs
to access objects individually and OLE client programs to manipulate them using properties and
methods.
OLE 2.0 Components
Drag
Drag
Automation
Automation and
and drop
drop
Visual
Visual
editing
editing
Structured
Structured
storage
storage Component
object
model
Compound
Compound
Data
Data transfer
transfer documents
documents
Naming
Naming and
and
Notification
Notification link tracking
link tracking
OLE 1.0 interoperability
SAP AG
n The OLE Automation functionality of OLE 2.0 has been implemented in R/3 Release 3.0. Other OLE
2.0 components have are not currently integrated into R/3.
OLE 2.0 Automation
l OLE client
n An application that can generate and control objects made
available by an OLE 2.0-compatible application (server).
l OLE server
n A server represents the objects, methods and properties of an
application to be used by another desktop application (client).
SAP AG
n In a desktop environment, an OLE 2.0 application "registers" its own application objects that can be
generated and used by other applications. The registered objects each have specific methods and
properties. A method is a function used only for this object (e.g. in Excel, cells have the method Clear,
which deletes the contents of the cell). A property is an attribute of the object (e.g. if application has the
property Visible and its value is True, the application can be seen on the desktop).
n OLE 2.0 Automation allows you to access objects and methods of another OLE 2.0-capable application
from an application program. The access is object-oriented.
R/3 and OLE 2.0 Automation
OLE Automation
ABAP/4
Visual
Visual Basic
Basic // Visual
Visual C++
C++
SAP OLE
OLE 2.0
2.0 Automation
Automation interface
interface
objects
SAP AG
n This graphic illustrates the combinations between R/3 Release 3.0 and other OLE Automation-capable
applications. You can access the OLE objects of desktop applications and manipulate them from an
ABAP/4 program.
n At the same time, you can also use desktop application programs to access R/3 OLE objects which are
made available on the desktop by a special SAP-specific program.
n In subsequent sections, the bi-directional aspect of OLE Automation accesses is described in more detail.
OLE Client Architecture in R/3
SAP AG
n In the above example, the access is from ABAP/4 programs to OLE objects made available on the
desktop by application programs.
n Special ABAP/4 OLE statements use the SAPGUI to make RFCs on the desktop side. The SAPGUI
software then executes OLE-specific calls from the desktop.
n In this way, you can use an ABAP/4 program to control all desktop application objects made available
via an OLE 2.0 Automation server program (e.g. EXCEL, MS Word, ...).
OLE 2.0 Client Properties
SAP AG
n Normally, all consecutive OLE statements are buffered by the ABAP/4 processor and sent to the
frontend together. Here, a statement may also refer to the results of preceding statements.
n Even if the next command is not an OLE statement, developers can direct the collection to continue by
setting a series of properties in a loop. For this functionality, you must use the NO FLUSH option with
OLE calls.
OLE 2.0 Programming Tools
SAP AG
n All applications controlled by ABAP/4 must be entered in the table TOLE which you maintain with the
Transaction SOLE. This table also indicates whether type information exists for a particular
application. Type information describes all the objects of an application, all its properties and methods,
as well as its parameters.
n You can load type information into the R/3 System (table OLELOAD) with the Transaction SOLI. The
ABAP/4 processor can then perform the necessary type conversions and be language-independent of the
OLE application. For all OLE applications delivered as standard by SAP, the English version is supplied
in the OLELOAD.
n In addition to runtime information in the table OLELOAD, you can also use the Transaction SOLI to
load other information such as documentation and WinHelp references. You can then access this
information in the SAP environment with the Object Browser (Transaction SOLO).
n For programming in the OLE environment, you must use the OLE-specific include OLE2INCL.
ABAP/4 Statements for OLE 2.0
SAP AG
n You must first define the object with the above DATA statement.
n CREATE OBJECT checks the existence of the object and generates an OBJECT_HANDLE. To be able
to address an OLE Automation server from ABAP/4, the server must be registered as a class in the R/3
System.
n GET PROPERTY allows you to copy the property property to the field field.
n SET PROPERTY sets the property property with the contents of the field field.
n You use CALL METHOD to call the method method (either a literal or a variable) of the object object.
With EXPORTING, you pass the field values to the parameters of the method.
n FREE OBJECT releases the resources at the frontend.
n For more detailed documentation about the above key words, refer to the ABAP/4 online help.
Programming Example in ABAP/4
l Example transaction in R/3: OLE
l INCLUDE OLE2INCL.
SAP AG
n The Transaction OLE is an example of OLE client functionality of ABAP/4 in the R/3 System. It allows
you direct access to the desktop applications MS Word, Excel and Visio.
n Usage example for Excel:
The "Start" button generates the Excel application object and activates the application window.
There should be an Excel file on your PC. Please enter the complete path of this file in the document
area.
The "Edit File" button opens the specified file for processing in the Excel application object. At the
same time, it generates a spreadsheet object and activates the menu bars and the tools of the desktop
application.
The "Get Cell" button copies the contents of the active call in Excel to the field in the SAP data area.
You can then change this value and write it back to the active cell in Excel with "Transfer".
The "Release" button releases the OLE object
If you change the Excel sheet with "Transfer", Excel notes this and displays another dialog box for you
to confirm whether you want to save the modified file.
n The example report RS41504A implements the above ABAP/4 code.
OLE Server Architecture in R/3
Desktop workstation
Permanent
MS Excel
RFC objects
O
L
MS Access
E
2.0 RFC
Automation
server
OLE R/3
RFC
RFCAPI
API
Automation System
client
SAP AG
n To enable you to access them, OLE objects in the R/3 System are made available to other OLE 2.0 client
applications by the RFC Automation server program (AMRFCSRV.EXE).
n The Automation server objects have been implemented as a layer via the RFC API function library. The
RFC Automation server converts the OLE calls to RFC API calls.
n The R/3 SAPGUI software does not have to be installed on the frontend for a desktop user to be able to
use the Automation server objects. The only requirements are installation of the RFC SDK (Software
Development Kit) on the desktop and a Winsocket-compatible network interface for this functionality.
Automation Server
Output log
SAP AG
n The Automation Assistant is frontend application for Automation server objects that runs under (16 bit)
Windows.
n This tool allows developers to retrieve information about the function module interface of the R/3
application server and execute the function. It is also possible to display transactions in the R/3 System
with their screens and fields.
n You can use an OLE application to make the windows of the Automation Assistant visible by setting the
property "RFC.Application.Visible" to "True". In this case, the property "
RFC.Application.Server.Visible" must also be set to "True".
RFC Object Hierarchy
Application
Application
Server objects
collection
Server
Server
Function
collection
Connection
Connection
Imports
collection Function
Function
Exports Tables
collection collection
Parameter
Parameter Structure
Structure Table
Table
Rows
collection
Row
Row
SAP AG
n The above RFC object hierarchy represents the objects for OLE client programs available through the
Automation server.
n When accessing these objects, programmers must observe the following sequence of steps:
Ÿ Create the server object and set up the connection (connection object).
Ÿ Create at least one function object for the server object.
Ÿ Assign a value to the export parameter object.
Ÿ Call the method function of the server object.
Ÿ Use the import parameter objects to call the result of executing the function module.
Ÿ Close the connection and release all objects.
n The properties and methods for the individual objects are described in the online help. There now follow
some examples of programming with these objects, properties and methods.
Creating an RFC Server Object
Application
Server
OR
Application
With "application object" and the method Add
Server collection Set RFCApp = CreateObject("RFC.Application")
Set RFCObjs = RFCApp.ServerObjects
Set RFCServer = RFCObjs.Add("Server1")
Server
SAP AG
n To work with other objects in the RFC object hierarchy apart from the application object, you must
generate a server object.
n To generate a server object, there are two options.
1. When using CreateObject("RFC.ServerObject"), the following steps are executed automatically:
a. An application object is created.
b. An entry for a new server object is added to the server collection object.
c. A server object is created.
2. When using CreateObject("RFC.Application"), the following steps are executed:
a. An application object is created.
When using RFCObjs.Add to create a server object, the following steps are executed:
a. An entry for a new server object is added to the server collection object.
b. A server object is created.
Setting Up a Connection to R/3
ODER
Server
SAP AG
n To call a function module in R/3, you must set up a connection to an R/3 application server. Only one
connection is possible for each server object. There are two ways of setting up a connection:
Ÿ “Logon” method:
You should use this method if the user has to enter most of the connection information. Since it
automatically displays a dialog field for entry of the logon information, you then do not need to code
this.
Ÿ “Open” method:
You should use this method if you can set all the connection information in the program, since no
dialog field is automatically displayed in this case. The “Open” method works only if all the logon
information is predefined.
Calling an R/3 Function (1)
EXCEPTIONSTR,
PARAM1:= LocParam1, Server
PARAM2:= LocParam2,
PARAM3:= LocParam3)
Function collection
SAP AG
n When observing the conventions governing specified arguments for calling a function module (dynamic
function object of the server), the exception string must be the first parameter in the command line.
n The Automation server automatically creates a function object as well as import and export objects.
n The import parameters for the function call are assigned automatically from the local parameters defined
in the command line.
Calling an R/3 Function (2.1)
Function collection
l Adds the function object to the
function collection Function
l OLE client application does not need
to support specified arguments
Imports coll. Exports coll.
l Syntax for Visual Basic code
Parameter
SAP AG
n For Visual Basic, programming via 'Names Arguments' is not possible. For this reason, each function
module called must be added as a function object to the function collection object with the method
“Add”.
Calling an R/3 Function (2.2)
Parameter
SAP AG
n Before calling the function module with the method “Call”, you must also set the export parameters
using the exports collection object.
n To get the import parameters after the function call, you must assign the local variable to the object item
of the import collection. This is different from dynamic retrieval where the import parameters of the local
variables are assigned automatically.
Working with Tables: Results (1)
Next
Row
SAP AG
n When using a function call with specified arguments (where the function object is a dynamic method of
the server object), it is not necessary to retrieve the table object with the table collection because the
variable TableObj is automatically assigned to the table object.
n The syntax used for navigation in the rows collection is specific to VBA (Visual Basic for Applications).
The construction "For Each" is not supported by Visual Basic 3.0. Programmers using Visual Basic
must access the table entries with the code specified in the next graphic.
Working with Tables: Results (2)
TableObj.Freetable
SAP AG
n The above syntax applies for accessing table object cells with Visual Basic 3.0.
n There are two other methods for working with data of a table object: UnloadTable and SetTable.
UnloadTable unloads the contents of a server table objects into a local variable, since the data changes
each time the function is called.
SetTable allows you transfer the data from a local table to a server table object.
Working with Tables: Entry (1)
For x = 1 to NumRows
TableRow= TableObj.AppendRow
TableRow( ”R 3TableField1 ”)= “....”
TableRow( ”R 3TableField2 ”)= “...”
Next x
RESULT = RFCServer.R3FunctionName(
EXCEPTIONSTR,
PARAM1:= LocParam1,
R3TABLENAME:= TableObj,
PARAM3:= LocParam3)
SAP AG
Working with Tables: Entry (2)
For x = 1 to NumRows
TableRow= TableObj.AppendRow
TableObj.Cell(x, ”R 3TableField1 ”)= “....”
TableObj.Cell(x, ”R 3TableField2 ”)= “...”
Next x
...
RFCFunction.Call
SAP AG
Exercise for Chapter 4
Report name: ZBCE##D1
Main report: RS415047
##: Group number
Implement an OLE link between R/3 (OLE client) and your PC
application Excel (OLE server). The report should download
flight customer data to Excel and present it in an Excel sheet.
Proceed as follows:
4. Then, you can return to the first R/3 System and test the
connection to both your programs with the CPI-C destination
you have specified.
Solution for Chapter 4
*&---------------------------------------------------------------------*
*& Report RS415041 *
*& *
*&---------------------------------------------------------------------*
REPORT RS4155041.
*
* OLE-specific include file
*
INCLUDE OLE2INCL.
*
* Data definitions of OLE objects with type ole2_object
*
DATA: EXCEL TYPE OLE2_OBJECT.
DATA: BOOKS TYPE OLE2_OBJECT.
DATA: BOOK TYPE OLE2_OBJECT.
DATA: CELL TYPE OLE2_OBJECT.
*
* Definition of loop counter
*
DATA: I TYPE I VALUE '5'.
*
* Internal table CUSTOMER with structure of SCUSTOM table
*
DATA: BEGIN OF CUSTOMER OCCURS 0.
INCLUDE STRUCTURE SCUSTOM.
DATA: END OF CUSTOMER.
*
* Call function with program parameter DISCOUNT
* All customers with discount rates greater than or equal to discount
* are returned to the internal table CUSTOMER
*
CALL FUNCTION 'TRAIN415_RFC_NORMAL_WITHITAB'
EXPORTING
IDISC = DISCOUNT
TABLES
CUSTOM = CUSTOMER
EXCEPTIONS
INVALID_DISCOUNT = 1.
IF SY-SUBRC <> 0.
WRITE: / TEXT-005 .
EXIT.
ENDIF.
*
* Create object EXCEL of OLE class 'EXCEL.APPLICATION'
*
CREATE OBJECT EXCEL 'EXCEL.APPLICATION'.
CALL METHOD OF EXCEL 'WORKBOOKS' = BOOKS.
CALL METHOD OF BOOKS 'ADD' = BOOK.
*
* Fill line in EXCEL sheet with header lines of table columns
*
PERFORM FILL_CELL USING 2 1 'ID'.
PERFORM FILL_CELL USING 2 2 'Name'.
PERFORM FILL_CELL USING 2 3 'Telephone'.
PERFORM FILL_CELL USING 2 4 'Discount'.
*
* Loop at customr table and print values in EXCEL sheet
*
LOOP AT CUSTOMER.
PERFORM FILL_CELL USING I 1 CUSTOMER-ID.
PERFORM FILL_CELL USING I 2 CUSTOMER-NAME.
PERFORM FILL_CELL USING I 3 CUSTOMER-TELEPHONE.
PERFORM FILL_CELL USING I 4 CUSTOMER-DISCOUNT.
I = I + 1.
ENDLOOP.
*
* Make the EXCEL sheet visible on the desktop
*
SET PROPERTY OF EXCEL 'VISIBLE' = 1.
WRITE: / TEXT-006 .
*
* Now leave the EXCEL application
* Note: You must go to the EXCEL application and respond to
* the dialog box
*
AT LINE-SELECTION.
CALL METHOD OF EXCEL 'QUIT'.
*
* Release all OLE objects
*
FREE OBJECT CELL.
FREE OBJECT EXCEL.
FREE OBJECT BOOKS.
*
* FORM routine which fills the specified cell in the EXCEL sheet
* with the given value
*
FORM FILL_CELL USING I J VAL.
CALL METHOD OF EXCEL 'CELLS' = CELL EXPORTING #1 = I #2 = J.
SET PROPERTY OF CELL 'VALUE' = VAL.
ENDFORM.
Chapter 5 CPI-C Interface
l Overview
l Basic functionality in the starter set
l Additional functionality
l Development environment
SAP AG
Chapter 5 Objectives
SAP AG
CPI-C Implementation
R/3
ABAP/4
SAP AG
e.g. CPI-C implementation by IBM according to SAA (System Application Architecture), UPIC by SNI
(Universal Programming Interface for Communication), etc.
General Flow
System 1 System 2
Side info
table
(Client)
Program 1 (Server)
Initialize connection Program 2
SAP AG
n With program-to-program communication, the general flow is the same regardless of the programming
language used. The following rules apply:
- With half duplex communication, only one program is authorized to send data at any one time. When one
program is in send mode, the other is in receive mode.
- The program setting up the communication always has the right to send data first.
- The other (started) program is in receive mode first.
- Switching the direction of the communication is achieved by setting off CMRCV in send mode. Then, the
partner program can send data.
- Mutiple communication switching is possible.
n One program sets up the connection ( = client); a partner program accepts the connection ( = Server).
n In the communication initiator system, a side information table must exist. This table is needed for the
connection initialization.
SAP Side Information Tables
R/2: XCOM XCOM
Dest LU TP ...
UNIX sideinfo
NT Dest = C11
GWHOST = is0001
Windows GWSERV = sapgw00
OS/2 LU = hw5001
TP = sapgw00
Protocol = I
SAP AG
n Each system from which you set up a CPI-C communication requires a side information table. Side
information tables can be compared to telephone directories.
n This table contains entries with parameters required for communication purposes. The three most
important of these are:
Symbolic destination:
The program setting up a connection uses a symbolic destination which must exist in the side
information table. A symbolic destination can be compared with a name in a telephone directory.
Partner LU:
The partner LU (logical unit) specifies where the communication partner is to be found. It can be
compared with an address in a telephone directory.
Partner program:
The partner program is the program which is started in the partner system or the program to which the
connection is made. It can be compared with the telephone number of the partner.
n Side information tables have different names in different systems:
SAP AG
This group contains SAP-specific functions which are either needed for communication with R/2 or R/3,
or which are optional.
CPI-C Calls in ABAP/4
SAP AG
n The CPI-C starter set has been implemented in ABAP/4 with the key word COMMUNICATION and
its six variants.
n For all variants, you can find the return code value of the operation either in the system field SY-
SUBRC or in the optional parameter RETURNCODE (R/2, from Rel. 5.0).
CPI-C Functions for C Programs
SAP AG
n The CPI-C starter set and other CPI-C function calls (advanced function calls (subset) and SAP-specific
functions) are available to the programming language C for external platforms (see the document "SAP
Supported Network Products").
n The CPI-C starter set consists of the following calls:
ABAP/4 C
REPORT
REPORTXYZ.
XYZ. ...
...
...
#include "{pathname}/cpic.h"
...
SAP AG
n For CPI-C programs, both ABAP/4 and C contain includes (reports or files) with data definitions on the
one hand and conversion tables on the other.
ABAP/4:
RSCPICDF: This report performs all CPI-C definitions as specified by IBM or X/Open. It defines, for
example, the different return codes.
RSEBCASC: This include program contains both the conversion tables for converting EBCDIC to
ASCII
and vice-versa.
C program:
Here, you have to include the header file cpic.h. You can specify the file name explicitly or the file must
exist in the central include directory. In this file, all constants, structures and function prototypes are
declared.
For the data conversion, you can use the file convert.txt. The explicit path to this file is declared via the
environment variable CONVERT.
Initializing Connections (INIT)
ABAP/4 C
...
... ...
COMMUNICATION
COMMUNICATION INIT
INIT CMINIT (
DESTINATION dest
DESTINATION dest convid,
IDIDconvid
convid dest,
[ [RETURNCODE
RETURNCODE rc
rc] ] &rc );
...
...
...
SAP AG
n The program setting up the CPI-C connection must first execute an INIT call. This uses a symbolic
address to access the side information file (which contains the connection and communication
parameters).
n symbolic_dest: Symbolic name (entry in the side information table)
conversation_id: This value is returned by the routine and must be specified in all subsequent CPI-
C calls
for this connection.
return_code: Error code: (0 (CM_OK) --> routine executed without error).
n The variables are defined in the include RSCPICDF for ABAP/4, and in the file "cpic.h" for C.
ABAP/4 C
...
...
COMMUNICATION
COMMUNICATION ...
ALLOCATE
ALLOCATE
IDIDconvid
convid CMALLC (
[ [RETURNCODE
RETURNCODE rc
rc] ] convid,
&rc );
...
...
...
SAP AG
ABAP/4: CONVID C 8
RC X 2
C: convid PCONVERSATION_ID
rc CM_RETCODE
n If CMALLC is executed without error, the program for this connection will be in SEND mode.
Accepting Connections Passively (ACCEPT)
ABAP/4 C
...
...
COMMUNICATION ACCEPT
CMACCP (
ID convid
convid,
[ RETURNCODE rc ] &rc );
...
...
SAP AG
n A passive program must accept the connection before data can be exchanged.
n You should assign appropriate types and lengths to variables:
ABAP/4: CONVID C 8
RC X 2
C: convid PCONVERSATION_ID
rc CM_RETCODE
n If the ACCEPT is executed without error, the program for this connection will be in RECEIVE mode.
conversation_id: This value is returned by the routine and must be specified in all subsequent CPI-
C calls
for this connection.
ABAP/4 C
... ...
SAP AG
n With the SEND command, you can send data packets of up to 30,000 bytes.
n All the data in the buffer output is sent to the receiving program. However, it is not actually transferred
until the buffer is full or after the next RECEIVE or DEALLOCATE.
If a particular length send_length is specified, the appropriate number of bytes is transferred from the
buffer output to the receiving program.
n A SEND is allowed only within the send status.
n You must assign appropriate types and lengths to variables:
ABAP/4: CONVID C 8
OUTPUT C
SEND_LENGTH P max. 30,000
RC X 2
C: convid PCONVERSATION_ID
output PCPIC_CHAR max. 30,000
send_length CPIC_INT
request_to_send_received REQUEST_TO_SEND_RECEIVED
(not evaluated)
rc CM_RETCODE
Receiving Data (RECEIVE)
ABAP/4 C
l ... ...
SAP AG
n Data is received in the buffer input in accordance with the buffer length. After the call, rec_length
contains the number of bytes placed in the buffer. The DATAINFO and STATUSINFO fields contain
information about the call.
n If a RECEIVE occurs in send mode, the right to send is transferred to the receiving program, together
with any existing user data in the network buffer. The sending program then assumes RECEIVE mode.
n You must assign appropriate types and lengths to variables:
ABAP/4: C:
CONVID C 8 convid
PCONVERSATION_ID
INPUT C max. 30,000 input PCPIC_CHAR
DATAINFO X 4 data_info PDATA_RECEIVED
STATUSINFO X 4 status_info PSTATUS_RECEIVED
REQ_LENGTH P requested_length CPIC_INT (max.
30,000)
REC_LENGTH X 4 received_length CPIC_INT
RC X 2 rc CM_RETCODE
request_to_send_received
PREQUEST_TO_SEND_RECEIVED
n If the HOLD parameter is set, the current work process is kept (no roll-out, roll-in).
Status and Data Information in RECEIVE
* Status information ABAP/4: Include report RSCPICDF
DATA: INT4(4) TYPE X.
...
DATA:
CM_NO_STATUS_RECEIVED LIKE INT4 VALUE '00000000',
CM_SEND_RECEIVED LIKE INT4 VALUE '00000001',
* Data information
CM_NO_DATA_RECEIVED LIKE INT4 VALUE '00000000',
CM_COMPLETE_DATA_RECEIVED ... VALUE '00000002',
...
typedef
typedef int
int STATUS_RECEIVED;
STATUS_RECEIVED; C: Header file cpic.h
......
##status_info
status_info
#define
#defineCM_NO_STATUS_RECEIVED
CM_NO_STATUS_RECEIVED 00
#define
#defineCM_SEND_RECEIVED
CM_SEND_RECEIVED 11
##data_info
data_info
typedef
typedef int
int STATUS_RECEIVED;
STATUS_RECEIVED;
...
...
#define
#define CM_NO_DATA_RECEIVED
CM_NO_DATA_RECEIVED 00
#define
#define CM_COMPLETE_DATA_RECEIVED
CM_COMPLETE_DATA_RECEIVED 22
SAP AG
n The status information is used to switch the send direction. The values have the following meanings:
ABAP/4 C
... ...
SAP AG
n This call closes the CPI-C connection. If there is still data in the buffer, it is transferred before the
connection is closed. The local system resources are then released.
n Only the sending program should close the connection.
n You should assign appropriate types and lengths to variables:
ABAP/4: C:
SAP AG
n Return codes provide information about the outcome of calls. You use the returned values to aid general
progran flow control and error handling in the event of communication terminations.
n In ABAP/4, the return code value is copied to the system field SY-SUBRC.
n The return codes are defined in the include report RSCPICDF.
n The return code is 2 bytes long and has the type X.
CPI-C Advanced Function Calls
...
SAP AG
This group contains a subset of the X/Open advanced function calls. SAP provides a subset of the
X/Open CPI-C advanced function calls for external programs.
n You use CMSPLN (Set_Partner_LU_Name) and CMSTPN (Set_Transaction_Program_Name) to set
the partner LU and partner transaction programs. CMSPLN and CMSTPN only make sense after a
CMINIT and before a CMALLC, i.e. only in programs which set up a connection. Then, you can
overlay the contents of the side information file.
n CMCNVO (Convert_Outgoing) and CMCNVI (Convert_Incoming) are the function calls for
converting data from EBCDIC to ASCII and vice-versa.
n CMFLUS (Flush) immediately transfers network buffer data to the partner program.
CPI-C SAP-specific Functions
...
SAP AG
n SAP-specific CPI-C functions are partly required for communication with SAP R/2 or R/3. Optional
SAP-specific CPI-C functions simplify the development of remote CPI-C programs.
n SAP_CMINIT (optional) and SAP_CMACCP(required in a passive program) inform the program
which gateway handler is being used (gateway host, gateway service, protocol type), but these details are
generally available in the relevant side information. SAP_CMINIT only makes sense before a CMINIT.
Accordingly, the partner program must then contain a SAP_CMACCP before the CMACCP in order to
receive the communication parameters.
n SAP_CMLOGON (optional) creates the connect string necessary for logging on to an R/2 or R/3
System.
n SAP_CMCERR (optional) checks whether the data received by the R/2 or R/3 System is an error
message.
n In the case of an error, SAP_CMPERR (optional) returns a short explanation of the error.
n You can use SAP_CMLOADCONVTAB (optional) to load a special conversion table.
SAP_CMMODCONVTAB (optional) modifies an area of the current conversion table.
Communication with an ABAP/4 Program
R/2
R/2
R/3
R/3 Communication
Communication program
program
External
External
system
system
R/2
R/2 R/3
R/3
SAP
SAP Basis
Basis System
System
Communication program
ABAP/4 (FORM routine)
SAP AG
n An ABAP/4 program is interpreted by a language processor embedded in the SAP Basis System.
n This architecture first requires a connection to be set up with the SAP Basis System:
REPORT RSCPICSV.
...
FORM FORM1.
...
COMMUNICATION ACCEPT
...
COMMUNICATION RECEIVE
...
ENDFORM.
SAP AG
VSE
VSE
R/2
R/2 MVS
MVS
BS2000
BS2000
EBCDIC
UNIX
UNIX
R/3
R/3 ASCII
SAP AG
n Data conversion is required between systems using the ASCII character set and those using EBCDIC,
unless the partner system is being used purely for data archiving purposes.
Conversion Commands
ABAP/4:
C:
SAP AG
n If an EBCDIC host system is attempting to communicate with an R/3 ASCII machine, the data must be
converted, but it is not important whether the sending program or the receiving program performs the
conversion.
n You can use include programs (RSEBCASC in ABAP/4, cpic.h in C) to convert data. It is even possible
to convert between code pages. You must maintain the relevant code page in the SAP system. In R/3,
you do this with the Transaction SPAD.
n CMCNVO() converts from ASCII to EBCDIC.
n CMCNVI() converts from EBCDIC to ASCII.
n For the C functions SAP_CMLOADCONVTAB() and SAP_CMMODCONVTAB(), you use a special
conversion table in the file convert.txt (for the precise syntax, see the online manual BC
Communication: Programming).
Logon String for the SAP System
l ABAP/4: l C:
w Database structure w SAP_CMLOGON (
CPICCONN output,
&send_length,
Field Length reqid,
reqtype,
REQID 4 amode,
REQTYPE 4 client,
AMODE 1 usr,
IMODE 1 pwd,
FILL1 2 language,
MAND 3 prog,
NAME 12 form,
CODE 8 &rc
LANG 1 );
KORR 1
PROG 8
MODN 30
SAP AG
n In an ABAP/4 (client) program, you can use the ABAP/4 Dictionary structure CPICCONN. Set the data
and then send the logon string with COMMUNICATION SEND.
n In a C program, you first set up the logon string with SAP_CMLOGON and then send it with
CMSEND. The logon string is appropriately formatted and converted from ASCII to EBCDIC because
a logon string is expected in EBCDIC both for R/2 and for R/3.
Logon to the SAP System
Logon
CONN CPIC 1
1 4 5 8 9 10 11 12 75
Client (3)
User name (12) FORM routine (30)
Password (8) ABAP/4 program
Language ID (1) Unused (1)
------------------------------------------------------------------------------------------------------------------------
Acknowledgement
CPIC 1
1. Negative acknowledgement
APPC CPIC 1
2. Negative acknowledgement
FREE 1 00027 E027 User not allowed
SAP AG
n The general header is sent only when you logon to the SAP System.
n The header is twelve bytes long; the last three characters are blank.
n The program name specifies the ABAP/4 program that contains a FORM routine. The FORM routine is
activatred internally by the SAP task handler.
n If an error occurs, the connection is terminated with the request ID FREE and an error text.
n As confirmation of the logon, the SAP System sends back the general header with the request ID APPC.
The data is then transferred in free format.
Logon to the Basis System
ABAP/4 C
REPORT RSCPIC01. ......
TABLES: CPICCONN. CMINIT
CMINIT...
...
INCLUDE RSCPICDF. CMALLC
CMALLC... ...
INCLUDE RSEBCASC.
.
..
... .
COMMUNICATION INIT ... SAP_CMLOGON
SAP_CMLOGON( (
COMMUNICATION ALLOCATE ... output,
output,
CPICCONN-REQID = 'CONN'. &sendlength,
&sendlength,
CPICCONN-REQTYPE = 'CPIC'. "CONN",
"CONN",
CPICCONN-AMODE = '1'. "CPIC",
"CPIC",
... '1',
'1',
CPICCONN-PROG = 'ABAPPROG'. ......
.
..
SAP AG
n The logon data record must always be sent to an SAP System in EBCDIC format.
n In ABAP/4, you can use the TRANSLATE statement for data conversion. The include program
RSEBCASC contains conversion tables for a conversion to IBM’s EBCDIC character set, but you can
also specify certain code pages explicitly.
n In C, you can make use of the relevant functionality via the SAP libraries.
CPI-C Development Environment
SAP AG
n The SAP CPI-C SDK (Software Development Kit) is delivered with every R/3 System.
n The CPI-C SDK contains excutable programs for the relevant hardware platform, libraries and include
files, as well as ABAP/4 and C programs. Accompanying text files describe the structure of the SDK
and provide important information about how programs are compiled and imported to the individual
platforms.
n The directory structure in the file system is as follows:
ABAP/4 programs
ACPICT1
ACPICT2
C programs
ccpict1t
ccpict2t
SAP AG
n Every R/3 System delivered contains the ABAP/4 programs ACPICT1 and ACPICT2. ACPICT1 is a
client program, i.e. a program which initiates a communication. ACPICT2 is a server program started
by a partner program. Both ABAP/4 programs are supplied for the R/2 System from Release 5.0G.
n The C programs ccpict1t and ccpict2t (directory cpicsdk/bin) are also delivered with the CPI-C SDK.
ccpict1t is a client program, ccpict2t is a server program.
n You can use these programs at least to test the connection to the partner system or the partner program.
So, ccpict1t can call the R/3 program ACPICT2, while ACPICT1 can call ccpict2t.
Executing CPI-C Test Programs
ACPICT1
CPI-C test program
Program parameters
DEST
ABAP
CONVERT
USER
PWD
ccpict1t
SAP AG
n For the connection test, you need to start the program ACPICT1 in R/3. In the program parameters, you
specify the partner program. If this is a C program, you do not need to specify values for USER and
PWD (password). If you want to set up a connection to an R/2 ABAP/4 program, you must set the
ABAP and CONVERT flags, as well as USER and PWD.
n You can pass the required program parameters to the client program ccpict1t via the command line. To
find out which parameters these are, execute ccpict1t without specifying any parameters.
Developing, Testing and Error Detection
l ABAP/4:
Debugging
System log
l C:
Trace files
Gateway monitor
Developer traces
SAP AG
gwmon pf = /sapmnt/<SID/profile/<SID>_<instance>
n Developer traces - in this case the gateway traces - are written by the R/3 system processes.
There are various trace files, e.g. for the gateway reader process (dev_rd) and for other possibly active
gateway work processes (with SNA link) (dev_wp0 bis dev_wp<n>). The relevant files are stored in the
work directory.
You can set the trace level in the gateway monitor. In R/3, you evaluate the files with Transaction ST11.
Chapter 5 Summary
SAP AG
Exercise 1 for Chapter 5
Report name: ZBCE##E1 (active)
ZBCE##E2 (passive)
Main report: RS415057 (active)
RS415058 (passive)
Logical destination: BC415_##
##: Group number
Implement a CPI-C communication between two R/3 Systems
where the data (information about a special airline carrier) is
read from a server system and output in a client system.
Proceed as follows:
4. Then, you can return to the first R/3 System and use your
CPI-C destination to test the connection of both your
programs.
Solution for Chapter 5
&----------------------------------------------------------------*
*& Report RS415051 *
*& *
*&---------------------------------------------------------------*
REPORT RS415051.
TABLES SPFLI.
TABLES CPICCONN. "Logon record
INCLUDE RSEBCASC.
INCLUDE RSCPICDF.
*----------------------------------------------------------------*
* CPI-C: CM_INIT *
*----------------------------------------------------------------*
FORMAT COLOR 1.
WRITE: / 'CM_INIT #', DEST.
COMMUNICATION INIT DESTINATION DEST ID CONVID RETURNCODE CPIC_RC.
FORMAT COLOR 2.
WRITE: / 'RC:', CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
*----------------------------------------------------------------*
* CPI-C: CM_ALLOCATE *
*----------------------------------------------------------------*
SKIP 1.
FORMAT COLOR 1.
WRITE: / 'CM_ALLOC'.
COMMUNICATION ALLOCATE ID CONVID RETURNCODE CPIC_RC.
FORMAT COLOR 2.
WRITE: / 'RC:', CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
*----------------------------------------------------------------*
* CPI-C: CM_SEND: Logon to SAP *
*----------------------------------------------------------------*
TRANSLATE CPICCONN USING ASC_TO_EBC.
SKIP 1.
FORMAT COLOR 1.
WRITE: / 'CM_SEND SAP logon'.
COMMUNICATION SEND ID CONVID BUFFER CPICCONN RETURNCODE CPIC_RC.
FORMAT COLOR 2.
WRITE: / 'RC:', CPIC_RC.
SKIP 1.
FORMAT COLOR 1.
WRITE: / 'Received data:'(004).
FORMAT COLOR 6.
LOOP AT ISPFLI.
NEW-LINE.
WRITE: ISPFLI-CARRID,
ISPFLI-CONNID,
ISPFLI-CITYFROM,
ISPFLI-CITYTO.
ENDLOOP.
*----------------------------------------------------------------*
* CPI-C: Deallocate *
*----------------------------------------------------------------*
SKIP 1.
FORMAT COLOR 1.
WRITE: / 'CM_DEALL'.
COMMUNICATION DEALLOCATE ID CONVID RETURNCODE CPIC_RC.
FORMAT COLOR 2.
WRITE: / 'RC:', CPIC_RC.
*&---------------------------------------------------------------*
*& Report RS415052 *
*& *
*&---------------------------------------------------------------*
REPORT RS41505D.
INCLUDE RSEBCASC.
INCLUDE RSCPICDF.
TABLES SPFLI.
DATA BEGIN OF ISPFLI OCCURS 1.
INCLUDE STRUCTURE SPFLI.
DATA END OF ISPFLI.
DATA: RBUFFER(255).
DATA: DUMMY.
FORM SEND.
*----------------------------------------------------------------*
* CPI-C: CM_ACCEPT *
*----------------------------------------------------------------*
COMMUNICATION ACCEPT ID CONVID RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
*----------------------------------------------------------------*
* CPI-C: CM_RCV Receive carrier ID *
*----------------------------------------------------------------*
COMMUNICATION RECEIVE ID CONVID
BUFFER SPFLI-CARRID
RETURNCODE CPIC_RC
DATAINFO DI
STATUSINFO SI
RECEIVED RL.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
*
* Read data
*
SELECT * FROM SPFLI
WHERE CARRID = SPFLI-CARRID.
*----------------------------------------------------------------*
* CPI-C: CM_SEND Send selected data to partner program *
*----------------------------------------------------------------*
COMMUNICATION SEND ID CONVID
BUFFER SPFLI
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
ENDSELECT.
*----------------------------------------------------------------*
* CPI-C: Deallocate *
*----------------------------------------------------------------*
COMMUNICATION DEALLOCATE ID CONVID
RETURNCODE CPIC_RC.
ENDFORM.
Outlook: Using OCX Components
RFC
BAPI function libraries
modules
or RFC API
customer-specific Desktop
application
function modules
Table view
Table
R/3
application Logon Includes
visualization
SAP AG
n What is OCX?
OCX (Ole custom Control eXtension) is an OLE object which combines the different OLE features in
one. Like DLLs, OCXs are compiled on Windows-based systems and exist in the process environment
of the application. All OCX properties and methods are primarily represented via the OLE Automation
interface.
n The SAP environment contains the following OCXs:
Ÿ Table OCX
Ÿ Table view OCX
Ÿ Logon OCX
Outlook: SAP Business Objects
l Object-oriented
approach with
R/3
l Management of
objects in the
Business
Object
Repository
n In Release 3.0 of the R/3 System, an object-oriented approach has been directly implemented in the SAP
business workflow development. This includes encapsulation of functions and modules, and also
inheritance, i.e. hierarchical relationships between object types.
n An object type is the definition/description of all objects generated at runtime. It is thus available at the
time of definition, whereas objects are always edited at runtime.
n Objects are defined by a key structure which consists primarily of key fields of the relevant tables which
make up the business document. Besides the key structure, you can define other proerties which
correspond to the database fields of tables.
n Methods in R/3 are the implementation of actions (e.g. performed by ABAP/4 reports, function modules
or transactions) and can be executed with the relevant object.
Outlook: SAP Business Object Active X
Architecture
MS Excel Business
Visual Basic objects
...
OLE Automation
clients
SAP AG
n For external applications, you will be able to access business objects in R/3 by using SAP Business
Object Active X (implemented as an OCX, OLE Control eXtension).
n The external application accesses R/3 objects via OLE Automation calls directed to SAP Business
Object Control. The calls are then passed on as pure RFC calls to the R/3 Object Broker.
n This allows you to access all object types managed via the SAP Business Object Repository. In R/3,
you access the Object Repository with Transaction SWO1.
Outlook: Object Hierarchy
Factory
Business objects
collection
Business object
SAP AG
blnLogged = oBOF.Logon
oBOF.Logoff
blnLogged = False
SAP AG
n In the above example, a factory object is generated first. Logon to the R/3 System is performed with the
“Logon” method.
n Then, the R/3 business object "USR01" is accessed with the key field value "MUELLER".
n Before logoff from the R/3 System, the business object can be processed.
Data Transfer
SAP AG
Contents II / Week 4
Exercises
Solutions
SAP AG
Chapter 1 Sequential Files
SAP AG
Chapter 1 Objectives
SAP AG
Overview
R/3
R/3
ABAP/4 program
Sequential file
SAP AG
n You can process sequential files with the statements READ DATASET (for read operations) and
TRANSFER (for write operations).
n The sequential file must be visible to the application server. Files on the current presentation server
cannot be processed with TRANSFER or READ DATASET. For further information about files of this
type, see the chapter Local Files.
Data Imports and Exports
Customer system
Fabe
Farbe
Customer
Customer
program
program Sequential
file R/3 System
SAP
SAP
program
program
SAP AG
n Sequential files are located at the interface between a customer system and the R/3 System.
n Sequential files are suitable for importing data from a customer system to the R/3 System and for
exporting data from the R/3 System to a customer system.
File Processing
Open file
Process file
Close file
SAP AG
n Before data records can be written to a sequential file or read from a file, the file must be opened.
n After processing, the file is closed.
n In the program, you call the file by its absolute file name. The absolute file name consists of the exact
path and the actual (relative) file name, e.g. '/tmp/bc180/d01' (note that file names are case-sensitive).
n The format of file names is largely dependent on the operating system. You can access portable
programs with the function module FILE_GET_NAME which returns the physical name for a given
logical file name. See also the online documentation for the module in Transaction SE37 or refer to the
online ABAP/4 User’s Guide.
Opening a File
OPEN
OPEN DATASET
DATASET <file
<file name>
name>
OUTPUT
FOR INPUT
APPENDING
IF
IF SY-SUBRC
SY-SUBRC NE
NE 0.
0.
..
..
..
SAP AG
n To open a file, you use the statement OPEN DATASET <file name>. Depending on whether this is
successful, SY-SUBRC is set to 0 or 8. Errors are ignored.
n If you do not specify any further options, the file is opened for reading.
n Possible options:
FOR OUTPUT
Opens the file for writing. If the file already exists, its contents are deleted, but this applies only after
the end of the program. If the statement occurs in a program, the cursor is simply positioned at the
beginning of the file. You must then specify CLOSE DATASET in order to delete the file. If the file
does not exist, it is generated.
FOR INPUT
Opens an existing file for reading. If the file is already open, the cursor is positioned at the beginning of
the file. You do not have to specify FOR INPUT explicitly.
FOR APPENDING
Opens the file for writing at the end of the file. If the file does not exist, it is generated. If the file is
already open, the cursor is positioned at the end.
Opening a File (Binary and Text Mode)
OPEN
OPEN DATASET
DATASET <file
<file name>
name>
OUTPUT
FOR INPUT
APPENDING
IN BINARY MODE
TEXT MODE
IF
IF SY-SUBRC
SY-SUBRC NE
NE 0.
0.
..
..
..
SAP AG
The data is not interpreted by the read and write operations READ DATASET and TRANSFER. The
data areas specified for these key words are input or output directly. You do not have to specify IN
BINARY MODE explicitly.
IN TEXT MODE
If you open a file with this option, the system assumes that the file has a line structure. Each time
READ DATASET or TRANSFER is executed, one line is always input/output and the data is always
processed up to the end-of-line selection. If the data area is too large for the line that is read, the
remaining area is padded with blanks. If it is too small, the end of the line is lost.
n If you make no additional specification, the file is opened in binary mode.
Binary Mode and Text Mode
Binary mode Text mode
ABAP/4
ABAP/4 ABAP/4
ABAP/4
program
program A B C program
program A B C
A B A B
A B C D A B C D
TRANSFER TRANSFER
A B C A B A B C D A B C A B A B C D
SAP AG
n The example above illustrates the difference between binary mode and text mode:
Three fields of different lengths are transferred at any one time. The data is then read into three fields of
the same length.
n In text mode, the operating system-specific line-end character is set after every data record.
n Blanks at the end of a data record are not suppressed in text mode.
Opening a File - AT POSITION
OPEN
OPEN DATASET
DATASET <file
<file name>
name>
AT POSITION <position>
MESSAGE <field>
SAP AG
With this addition, you can specify a file position (in bytes) from the beginning of the file. The next read
or write operation then takes place at this point. You cannot position the cursor before the beginning of
the file.
Although this addition can be used together with IN TEXT MODE, this has little sense as the physical
format of a text file is largely dependent on the operating system.
MESSAGE <field>
If an error occurs when opening the file, the associated operating system message is stored in the field
<field>.
For information on other additions, refer to the online documenation.
Transferring Data Records
Sequential
file
data
record
SAP AG
Sequential
file
data
record
SAP AG
n Each READ DATASET statement reads one record from a sequential file into a field or structure.
Possible structures are field strings or table work areas.
n The execution of the READ DATASET statement depends on the mode:
SAP AG
n You use the CLOSE DATASET <file name> statement to close a sequential file explicitly.
n As with OPEN DATASET, errors are ignored.
n In a program, all opened files are implicitly closed each time the screen changes, and then reopened
exactly as they were before when processing resumes.
n At the end of a program, all files are closed.
n Opening and closing files explicitly aids readability. Also, the advantage of using OPEN DATASET is
that you can use the addition MESSAGE to avoid a programmed termination if an error occurs when
opening the file (SY-SUBRC = 8). In addition, you should be aware that, in cases where a file is read,
or generated and read, several times in the same report, only explicit opening or closing guarantees that
the cursor will be repositioned at the beginning of the file.
n A file is not closed implicitly when READ DATASET reaches the endo of a file.
n You can use the DELETE DATASET <file name> to delete a sequential file explicitly. If this is
successful, SY-SUBRC is set to 0.
n You can display the current state of the file in debugging by choosing Goto -> System -> System areas
and then entering (or selecting) DATASETS.
Example: Creating a File
REPORT RSFFF01A.
TABLES SFLIGHT.
* INCLUDE RSFFF01B.
DATA: BEGIN OF REC,
CARRID LIKE SFLIGHT-CARRID,
CONNID LIKE SFLIGHT-CONNID,
FLDATE LIKE SFLIGHT-FLDATE,
PLANETYPE LIKE SFLIGHT-PLANETYPE,
END OF REC.
PARAMETERS
FILE(20) DEFAULT '/tmp/RSFFF01A'
LOWER CASE.
START-OF-SELECTION.
OPEN DATASET FILE FOR OUTPUT.
GET SFLIGHT.
MOVE-CORRESPONDING SFLIGHT TO REC.
TRANSFER REC TO FILE.
END-OF-SELECTION.
CLOSE DATASET FILE.
SAP AG
n First you define the structure to be transferred. In this example, it is a field string, but it could also be a
help field, the header liner of an internal table or an ABAP/4 Dictionary work area.
n The field string can also be transferred from an include report.
n Next, you fill the structure. In principle, all statements that perform a value assignment can be used
here. Examples include MOVE, COMPUTE, MOVE-CORRESPONDING, MOVE TO and WRITE
TO. Refer also to the relevant online documentation.
n Finally, you transfer the structure with the TRANSFER statement.
Example: ABAP/4 Dictionary Structures
REPORT RSFFF01C.
TABLES: SFLIGHT, SBC420A.
PARAMETERS
FILE(20) DEFAULT '/tmp/RSFFF01A'
LOWER CASE.
GET SFLIGHT.
MOVE-CORRESPONDING SFLIGHT TO SBC420A.
TRANSFER SBC420A TO FILE.
WRITE: / SBC420A-CARRID, SBC420A-CONNID,
/ SBC420A-FLDATE, SBC420A-PLANETYPE.
ULINE.
REPORT RSFFF01D.
TABLES: SFLIGHT, SBC420A.
DATA: BEGIN OF REC.
INCLUDE STRUCTURE SBC420A.
DATA: END OF REC.
PARAMETERS
FILE(20) DEFAULT '/tmp/RSFFF01A'
LOWER CASE.
GET SFLIGHT.
MOVE-CORRESPONDING SFLIGHT TO REC.
TRANSFER REC TO FILE.
WRITE: / REC-CARRID, REC-CONNID,
/ REC-FLDATE, REC-PLANETYPE.
ULINE.
SAP AG
n You can also use structures from the ABAP/4 Dictionary for data transfer. To do this, declare the
structure with TABLES.
n Then, in your program, do either of the following:
- use the work area declared with TABLES
- copy the structure for your field string with INCLUDE STRUCTURE.
n You can display the ABAP/4 Dictionary structure in the ABAP/4 Editor with the SHOW command.
Example: Reading a File
REPORT RSFFF01E.
TABLES SFLIGHT.
* INCLUDE RSFFF01B.
DATA: BEGIN OF REC,
CARRID LIKE SFLIGHT-CARRID,
CONNID LIKE SFLIGHT-CONNID,
FLDATE LIKE SFLIGHT-FLDATE,
PLANETYPE LIKE SFLIGHT-PLANETYPE,
END OF REC.
PARAMETERS
FILE(20) DEFAULT '/tmp/RSFFF01A'
LOWER CASE.
START-OF-SELECTION.
OPEN DATASET FILE FOR INPUT.
DO.
READ DATASET FILE INTO REC.
IF SY-SUBRC NE 0. EXIT. ENDIF.
WRITE: / REC-CARRID,REC-CONNID,
/ REC-FLDATE,REC-PLANETYPE.
ULINE.
ENDDO.
CLOSE DATASET FILE.
SAP AG
n First you define the structure to be read. In this example, it is a field string. It can also be transferred
from an include report.
n The structure used for reading with READ DATASET must match the structure used for writing with
TRANSFER.
n You read the data records into your structure within a loop and process them.
n READ DATASET does not require a logical database. You can therefore analyze your extract data
along with data from any logical database (which you then specify in the report attributes).
Example: Extending a File
REPORT RSFFF01F.
TABLES: SFLIGHT, SBC420A.
START-OF-SELECTION.
OPEN DATASET FILE FOR APPENDING
IN BINARY MODE.
GET SFLIGHT.
MOVE-CORRESPONDING SFLIGHT TO SBC420A.
TRANSFER SBC420A TO FILE.
WRITE: / SBC420A-CARRID, SBC420A-CONNID.
END-OF-SELECTION.
CLOSE DATASET FILE.
SAP AG
n To append data records to the end of the file, you use the FOR APPENDING addition of the OPEN
DATASET statement.
Example: Variable Format (Generate)
REPORT RSFFF01G.
TABLES: SFLIGHT, SBOOK.
INCLUDE RSFFF01I.
PARAMETERS:
FILE(20) DEFAULT '/tmp/RSFFF01G'
LOWER CASE.
START-OF-SELECTION.
OPEN DATASET FILE FOR OUTPUT
IN BINARY MODE.
GET SFLIGHT.
MOVE-CORRESPONDING SFLIGHT TO REC1.
MOVE 'A' TO REC1-FLAG.
TRANSFER REC1 TO FILE.
WRITE REC1-CARRID, REC1-CONNID,.......
GET SBOOK.
MOVE-CORRESPONDING SBOOK TO REC2.
MOVE 'B' TO REC2-FLAG.
TRANSFER REC2 TO FILE.
WRITE REC2-BOOKID, REC2-CUSTID,.......
END-OF-SELECTION.
CLOSE DATASET FILE.
SAP AG
n The above example generates a sequential file with data records of different structures.
n The include program is defined as follows:
DATA: BEGIN OF REC1, FLAG.
INCLUDE STRUCTURE SBC420A.
DATA: END OF REC1.
DATA: BEGIN OF REC2, FLAG.
INCLUDE STRUCTURE SBC420B.
DATA: END OF REC2.
n The structure SBC420A is used for flight data, while the structure SBC420B holds reservation data.
n A flag should indicate whether the next data record contains flight data or reservation data.
Example: Variable Format (Read)
REPORT RSFFF01H.
TABLES: SBC420A, SBC420B.
DATA: FLAG.
PARAMETERS
FILE(20) DEFAULT '/tmp/RSFFF01G'
LOWER CASE.
START-OF-SELECTION.
OPEN DATASET FILE FOR INPUT
IN BINARY MODE.
DO.
READ DATASET FILE INTO FLAG.
IF SY-SUBRC NE 0. EXIT. ENDIF.
CASE FLAG.
WHEN 'A'.
READ DATASET FILE INTO SBC420A.
WRITE: / SBC420A-CARRID SBC420A-CONNID,
SBC420A-FLDATE, SBC420A-PLANETYPE.
WHEN 'B'.
READ DATASET FILE INTO SBC420B.
WRITE: / SBC420B-BOOKID, SBC420B-CUSTID,
SBC420B-CUSTYP, SBC420B-CLASS.
ENDCASE.
ENDDO.
END-OF-SELECTION.
CLOSE DATASET FILE.
SAP AG
n The above program reads the data records of the file created with the previous program.
n The program assumes that an ID (‘A’ or ‘B’) precedes each data record.
n The file is opened in binary mode and the records are read in the length of the structure specified.
Defining Structures - Summary
Define structures
Open file
Write
Write Read
Read
No Yes
Close file
SAP AG
n In a file processing program, you first define the structures required for the data records with the
TABLES or DATA statement. The program uses these structures as internal buffers for the data
records.
n You then open the sequential file for reading or writing with the OPEN statement.
n When writing to the file, you transfer the filled structures to the file with TRANSFER statements.
n When reading the file, you fill the structures set up for the data records with READ DATASET for
further processing in the program.
n To close the sequential file, you exit file processing with the CLOSE DATASET statement.
Chapter 1 Summary
SAP AG
Exercises on Chapter 1: Sequential Files
Task:
Create a file with flight/reservation data. The data records are
to be entered by the user individually.
Programming hints:
a) Use the include report specified above for the data
structure.
The structure contains the airline carrier ID, flight ID, flight
date, booking ID and customer ID (CARRID,CONNID,
FLDATE, BOOKID, CUSTOMID).
b) Using the PARAMETERS statement, define a selection
screen on which the flight/reservation data can be entered.
c) Transfer the data record in text mode.
d) A new data record is to be added to the file whenever the
report is started.
Task:
Create a program that reads in the data of your
flight/reservation file BAN## and outputs it to the screen.
Model Solution 1 for Chapter 1: Sequential Files
REPORT RSFFF011 .
* STRUCTURE SBC420C:
* Alternative:
* INCLUDE RSFFF01L.
PARAMETERS:
START-OF-SELECTION.
CONNID TO REC-CONNID,
FLDATE TO REC-FLDATE,
BOOKID TO REC-BOOKID,
CUSTOMID TO REC-CUSTOMID.
* List output
WRITE: / REC-CARRID,
/ REC-CONNID,
/ REC-FLDATE,
/ REC-BOOKID,
/ REC-CUSTOMID.
ULINE. SKIP.
* STRUCTURE SBC420C:
* Alternative:
* INCLUDE RSFFF01L.
PARAMETERS:
START-OF-SELECTION.
DO.
IF SY-SUBRC NE 0.
COUNT = SY-INDEX - 1.
EXIT.
ENDIF.
* List output
/ REC-CARRID,
/ REC-CONNID,
/ REC-FLDATE,
/ REC-BOOKID,
ULINE.
ENDDO.
SKIP.
SAP AG
Chapter 2 Objectives
SAP AG
Task Overview
External system
SAP R/2
SAP R/3
SAP AG
n The reasons for transferring data without a basic interactive dialog with the user are:
Ÿ The datasets are large and already exist on an electronic data medium
Ÿ The data is transferred to another system and only then imported into the SAP system.
Problem Overview
SAP
SAP
interfaces database
External
data
Checks SAP
database
External
data
SAP AG
n You must not transfer external data directly to the SAP database.
n External data must be checked before it is transferred to the SAP database.
Technique Overview
External system
SAP R/2
SAP R/3
Queue
Batch
input
sessions
Application
program
SAP
database
SAP AG
n Large data sets are transferred to the SAP system using batch input.
n Batch input is an automatic procedure. It is often referred to as BDC (Batch Data Communication).
n To guarantee data consistency, the transfer data is subject to the same checks and updates as dialog
data which is entered interactively by the user. Examples include:
- Format checks
- Automatic value range check (against check table or fixed value range)
- Conversion of user data to program data and vice-versa
- Field default values
n The transfer data is stored temporarily in the form of a batch input session in a queue file.
A batch input session is a collection of business processes (transactions).
n A user dialog is simulated in a batch input procedure.
Screen Technique Overview
Dialog step
Input
Input Output
Output Input
Input Output
Output
modules
modules modules
modules modules
modules modules
modules
t
PAI
PAI PBO
PBO PAI
PAI PBO
PBO
Input
Input Processing
Processing Input
Input Processing
Processing
SAP AG
n In an SAP system, dialog and background processing are controlled by screen programs.
n A screen program controls one dialog step.
n The components of a dialog step are:
Ÿ A PBO (Process Before Output) event which prepares the screen for output
Ÿ User input
Ÿ A PAI (Process After Input) event which processes user input
Batch Input Processing
Sequential
file
Batch
Batch input
input program
program
Source file
Batch
Batch input
input function
function
SAP
SAP R/3
R/3
Flight
Customer connections Reservation
data data
SAP AG
n Batch input or BDC (Batch Data Communication) is an automatic procedure for transferring data to the
SAP system without a user dialog.
n A user dialog is simulated for this procedure so that the same checks and updates can be performed.
n A central component of this procedure is a queue file.
n This file receives the data via batch input programs and groups associated data together into ‘sessions’.
n To load the data into SAP databases, you process the sessions with the batch input function (menu
options Systems -> Services-> Batch input, Transaction SM35).
Batch Input Program
Sequential file
ABAP/4
Structure
Structure Dictionary
READ DATASET
BDCDATA
BDCDATA
Batch input program
BDC
BDC
table
table
INCLUDE
STRUCTURE
CALL FUNCTION
Queue
file
SAP AG
Batch
Batch input
input
Transaction 1 Transaction 2
SAP
SAP R/3
R/3
Flight
Customer connections Booking
data data
SAP AG
n The queue file collects the individual screens and combines them into sessions.
n You process these sessions with the batch input function (choose Systems -> Services-> Batch input or
call Transaction SM35). As when you execute application functions (with add or change transactions)
in the dialog interface, this sends data to the log file. When you subsequently perform an update, the
data reaches the relevant SAP databases.
n The batch input function starts the application functions specified in the relevant session (indicated by
their transaction codes).
n The data from the session is now copied to the screens belonging to the online transaction specified.
Format of a Batch Input Session
Session header
l User who has created the session
l Client in wh íc h session is to be processed
l Session name
l Batch input user
l Date from when the session may be processed (lock date)?
l Delete session after processing (Keep function)?
Transaction
...
Close session
SAP AG
n A batch input session consists of a header part (session header, described by the ABAP/4 Dictionary
structure APQI) and a data part (transactions, described by the ABAP/4 Dictionary structure APQD).
Creating a Batch Input Session
Open
Open batch
batch
input session
input session
Insert
Insert data
data
for transactions
for transactions
Close
Close batch
batch
input session
input session
SAP AG
BDC_OPEN_GROUP
BDC_OPEN_GROUP
Client CLIENT
CLIENT
Session name GROUP
GROUP
Lock date HOLD
HOLD
Delete session after KEEP
KEEP
processing
BDC user name USER
USER
BDC_INSERT
BDC_INSERT
Transaction
Transaction code
code TCODE
TCODE
BDC
BDC table
table DYNPROTAB
DYNPROTAB
BDC_CLOSE_GROUP
BDC_CLOSE_GROUP
SAP AG
n Function modules (function group SBDC) are available for creating batch input sessions.
n You will learn about these function modules in the following slides. Refer also to the online
documentation.
Function Module BDC_OPEN_GROUP
CALL FUNCTION ’B
CALL FUNCTION ’B DC_OPEN_GROUP’
DC_OPEN_GROUP’
EXPORTING
CLIENT = <client>
GROUP = <session name>
HOLDDATE = <lock date>
KEEP = <delete flag>
USER = <BDC user name>
EXCEPTIONS
QUEUE_ERROR = 1
CLIENT_INVALID = 2
GROUP_INVALID = 3
.
.
.
SAP AG
n You open a batch input session with the function module BDC_OPEN_GROUP.
n The parameters you must specify are as follows:
CLIENT (Client)
GROUP (Session name)
USER (User name)
n Specification of the following parameters is optional:
HOLDDATE (Earliest session start date)
KEEP (ID whether session should be deleted after successful processing;
KEEP = ' ': Delete session (default value)
KEEP = 'X': Do not delete session)
n You receive various return values via EXCEPTIONS. You can read these with SY-SUBRC.
n USER must always be specified; The user type should be BDC.
n In online processing, the online user (and not the user name specified) is used for the authorization
checks.
Function Module BDC_INSERT
CALL FUNCTION ’B
CALL FUNCTION ’B DC_INSERT’
DC_INSERT’
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
SAP AG
n You use function module BDC_INSERT to insert the data for ONE transaction into a session.
n To transfer the data, you require an internal table (BDC table).
n You must specify the following parameters:
TCODE (transaction code),
DYNPROTAB (BDC table).
BDC Table
Program
Program Screen
Screen Start
Start Field
Field name
name Field
Field contents
contents
SAP AG
DATA:
DATA: BEGIN
BEGIN OF
OF <BDC
<BDC table>
table>
OCCURS
OCCURS <OCCURS
<OCCURS parameter>.
parameter>.
INCLUDE
INCLUDE STRUCTURE BDCDATA.
STRUCTURE BDCDATA.
DATA:
DATA: END
END OF <bdc
OF <bdc table>.
table>.
SHOW
SHOW BDCDATA
BDCDATA
Field
Field name
name Type
Type Length
Length Short
Short text
text
PROGRAM
PROGRAM CHAR
CHAR 88 BDC
BDC module
module poolpool
DYNPRO
DYNPRO NUMC
NUMC 44 BDC
BDC screen
screen number
number
DYNBEGIN
DYNBEGIN CHAR
CHAR 11 BDC
BDC start
start of
of aa screen
screen
FNAM
FNAM CHAR
CHAR 35
35 BDC field name
BDC field name
FVAL
FVAL CHAR
CHAR 132
132 BDC
BDC field
field contents
contents
SAP AG
n You declare the BDC table as an internal table with the ABAP/4 Dictionary structure 'BDCDATA'.
n The field <BDC table>-FVAL differentiates between upper and lower case, but the fields <BDC table>-
PROGRAM and <BDC table>-FNAM are not case-sensitive.
Filling the BDC Table
FORM <fill_BDC table>.
REFRESH <BDC table>.
CLEAR <BDC table>.
MOVE: <program name> TO <BDC table>-PROGRAM,
<number1> TO <BDC table>-DYNPRO,
'X' TO <BDC table>-DYNBEGIN.
APPEND <BDC table>.
CLEAR <BDC table>.
MOVE: <field11> TO <BDC table>-FNAM,
<value11> TO <BDC table>-FVAL.
APPEND <BDC table>.
CLEAR <BDC table>.
MOVE: <field12> TO <BDC table>-FNAM,
<value12> TO <BDC table>-FVAL.
APPEND <BDC table>.
...
ENDFORM.
SAP AG
n The BDC table is set up line by line. As for every internal table, you do this with MOVE and APPEND
statements.
n The fields of the table header line should be reset to their initial value with CLEAR.
Function Module BDC_CLOSE_GROUP
CALL FUNCTION ’B
CALL FUNCTION ’B DC_CLOSE_GROUP’
DC_CLOSE_GROUP’
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
SAP AG
n You close a batch input session with the function module BDC_CLOSE_GROUP.
n You receive various return values via EXCEPTIONS. You can read these with SY-SUBRC.
Example: Change Customer Data
BC_TRAVEL
BC_TRAVEL data
data model
model for
for training
training
Change
Change customer
customer data
data
(Transaction
(Transaction TFBA)
TFBA)
Customer number 1
Save
Save
SAP AG
n In this example, the application function Change customer data (Transaction TFBA) demonstrates the
creation of a BDC program.
n Here, a customer’s address data is to be changed.
n Before writing a BDC program for the application function, you must know the application function (so
that the BDC program can simulate your input on the screen).
Preparations for BDC Program
Program
Program SAPMTFBA
SAPMTFBA
Screen
Screen number
number 100
100
Code
Code /5
/5 or
or Aend
Aend
Field
Field BDC_OKCODE
BDC_OKCODE
Help
Help
F1
F1 System
Change cust. data
Status
Technical
Technical info
info
Customer number_______
Table
Table SCUSTOM
SCUSTOM
Field
Field ID
ID
SAP AG
Program
Program SAPMTFBA
SAPMTFBA
Screen
Screen number
number 100
100
Field
Field list
list
System
Kundendaten ä n dern
Change cust. data
Status
Field name Ln Cl Lg Fmt. I O
SCUSTOM ID 8 36 08 NUMC x x
...
Customer number________ OK 0 0 04 OK
...
...
SAP AG
n In the Screen Painter (choose Tools -> ABAP/4 Workbench -> Screen Painter, or call Transaction
SE51), you can get a complete list of fields for a particular screen. This is an alternative to the online
help function).
Structure of the BDC Table
PROGRAM
PROGRAM SCREEN
SCREEN SCRNSTART
SCRNSTART FNAM
FNAM FVAL
FVAL
SAPMTFBA 0100 X
SCUSTOM-ID ID
BDC_OKCODE /5
SAPMTFBA 0200 X
SCUSTOM-NAME CUSTNAME
SCUSTOM-POSTCODE POSTCODE
SCUSTOM-CITY CITY
SCUSTOM-CUSTTYPE CUSTTYPE
SCUSTOM-DISCOUNT DISCOUNT
SCUSTOM-TELEPHONE TELEPHONE
BDC_OKCODE /11
SAP AG
n Before you write the batch input program, you have to run the transaction and note down the screen
numbers, screen sequence and the screen field names to be addressed later in the program. You enter
this data in the BDC table.
n The field name for the OK code is the same for all screens: BDC_OKCODE. The value for the OK
code consists of a slash '/' and the function key number (example: '/11').
Declaration Part 1
REPORT RSFFF02A.
PARAMETERS:
NAME LIKE APQI-GROUPID DEFAULT SY-UNAME,
ID LIKE SCUSTOM-ID DEFAULT '00000001',
CUSTNAME LIKE SCUSTOM-NAME DEFAULT 'SCHMIDT',
POSTCODE LIKE SCUSTOM-POSTCODE DEFAULT '69000',
CITY LIKE SCUSTOM-CITY DEFAULT 'HEIDELBERG',
CUSTTYPE LIKE SCUSTOM-CUSTTYPE DEFAULT 'B',
DISCOUNT LIKE SCUSTOM-DISCOUNT DEFAULT '10',
TELEFON LIKE SCUSTOM-TELEPHONE DEFAULT '06221/
123456'.
SAP AG
n In the declaration part of the BDC program, you define the BDC table.
n In this example, the data is entered directly on the selection screen (via PARAMETERS).
Creating Sessions
START-OF-SELECTION.
WRITE: / 'Start BDC session creation',
SY-MANDT, NAME, SY-UZEIT.
PERFORM GENERATE_BDC_DATA.
SAP AG
n You require the function modules for opening and closing sessions.
n To insert the data in the session, you set up the BDC table in a subroutine and call the function module
BDC_INSERT.
Filling the BDC Table 2
FORM GENERATE_BDC_DATA.
REFRESH BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-PROGRAM = 'SAPMTFBA'.
BDC_TAB-DYNPRO = '0100'.
BDC_TAB-DYNBEGIN = 'X'.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = 'SCUSTOM-ID'.
BDC_TAB-FVAL = ID.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = 'BDC_OKCODE'.
BDC_TAB-FVAL = '/5'.
APPEND BDC_TAB.
SAP AG
n Two fields are transferred for the first screen of Transaction TFBA.
Filling the BDC Table 3
CLEAR BDC_TAB.
BDC_TAB-PROGRAM = 'SAPMTFBA'.
BDC_TAB-DYNPRO = '0200'.
BDC_TAB-DYNBEGIN = 'X'.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = 'SCUSTOM-NAME'.
BDC_TAB-FVAL = CUSTNAME.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = 'SCUSTOM-POSTCODE'.
BDC_TAB-FVAL = POSTCODE.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = 'SCUSTOM-CITY'.
BDC_TAB-FVAL = CITY.
APPEND BDC_TAB.
ENDFORM.
SAP AG
n For the second screen of Transaction TFBA, the fields 'SCUSTOM-NAME', 'SCUSTOM-
POSTCODE' and 'SCUSTOM-CITY' are transferred.
Filling the BDC Table 4
CLEAR BDC_TAB.
BDC_TAB-FNAM = 'SCUSTOM-CUSTTYPE'.
BDC_TAB-FVAL = CUSTTYPE.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = 'SCUSTOM-DISCOUNT'.
BDC_TAB-FVAL = DISCOUNT.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = 'SCUSTOM-TELEPHONE'.
BDC_TAB-FVAL = TELEFON.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = 'BDC_OKCODE'.
BDC_TAB-FVAL = '/11'.
APPEND BDC_TAB.
ENDFORM.
SAP AG
PARAMETERS:
FILE(30) DEFAULT '/tmp/RSFFF02B'
LOWER CASE,
CODE1 LIKE SCUSTOM-POSTCODE DEFAULT
'9999999999',
CODE2 LIKE SCUSTOM-POSTCODE DEFAULT
'1111111111',
CUST1 LIKE SCUSTOM-CUSTTYPE DEFAULT 'B',
CUST2 LIKE SCUSTOM-CUSTTYPE DEFAULT 'P'.
START-OF-SELECTION.
OPEN DATASET FILE FOR OUTPUT
SAP AG
n In the following example, the postal code is changed according to a particular algorithm. In addition,
business customers (type B) are changed to private customers (type P), and vice-versa. For this, the
customer masters are changed with a batch input program for Transaction TFBA. A sequential file with
the required data is generated with this program.
Generating a Sequential File for BDC Program 2
SELECT * FROM SCUSTOM
WHERE ID BETWEEN '00000001'AND '00000050'.
MOVE SCUSTOM-ID TO REC-ID.
IF SCUSTOM-POSTCODE(1) BETWEEN '1' AND '5'
OR SCUSTOM-POSTCODE(1) BETWEEN 'A' AND 'M'.
MOVE CODE1 TO REC-POSTCODE.
ELSE.
MOVE CODE2 TO REC-POSTCODE.
ENDIF.
IF SCUSTOM-CUSTTYPE EQ 'P'.
MOVE CUST1 TO REC-CUSTTYPE.
ELSE.
MOVE CUST2 TO REC-CUSTTYPE.
ENDIF.
END-OF-SELECTION.
CLOSE DATASET FILE.
ULINE. SKIP.
WRITE: / TEXT-001, FILE.
SAP AG
REPORT RFFF02C.
PARAMETERS:
FILE(30) DEFAULT '/tmp/RSFFF02B'
LOWER CASE,
NAME LIKE APQI-GROUPID DEFAULT SY-UNAME.
DATA:BEGIN OF REC,
ID LIKE SCUSTOM-ID,
POSTCODE LIKE SCUSTOM-POSTCODE,
CUSTTYPE LIKE SCUSTOM-CUSTTYPE;
END OF REC.
START-OF-SELECTION:
OPEN DATASET FILE FOR INPUT.
SAP AG
n In the declaration part of the BDC program, you define the BDC table and a structure for reading in the
data.
Reading in the Data and Creating Sessions
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING CLIENT = SY-MANDT
GROUP = NAME
USER = 'BC420BDC'
KEEP = 'X'.
DO.
READ DATASET FILE INTO REC.
IF SY-SUBRC NE 0. EXIT. ENDIF.
WRITE: / REC-ID USING NO EDIT MASK,
REC-POSTCODE, REC-CUSTTYPE.
PERFORM GENERATE_BDC_DATA.
WRITE: / TEXT-002,
SY-MANDT, NAME, SY-UZEIT.
END-OF-SELECTION.
CLOSE DATASET FILE.
SAP AG
n You require the function modules for opening and closing sessions.
n To insert the data in the session, you set up the BDC table in a subroutine and call the function module
BDC_INSERT.
n You set up the BDC table and call the subroutine in a loop for reading in the data with READ
DATASET.
n The called subroutine is similar to the subroutine in the first program example.
Functionality of Transaction SM35
Batch
Batch input
input sessions
sessions
Overview
Overview Batch
Batch input
input process
process logs
logs
Locked
Locked sessions
sessions
Select
Select sessions
sessions for
for deletion
deletion
Administration
Administration Lock
Lock sessions
sessions
Release
Release sessions
sessions
Process
Process in
in foreground
foreground
Process
Process Display
Display errors
errors only
only
Process
Process in
in background
background
SAP AG
n You can process sessions with the Batch input function (choose System -> Services -> Batch input, or
call Transaction SM35). Information is provided on status, screen sequence, screen contents, the user
doing the processing, processing mode, server, as well as the user used for the authorization check.
n In Release 3.0, the user can activate Expert mode if required. This function deactivates error message
344 'Batch input data does nto exist for this screen’ for interactive session processing. This option is of
particular interest if you want to branch to other transaction processing, which does not correspond to
the screen sequence in the batch input program.
n The Extended log function allows you to record W, I and S messages in addition to E messages. This
option is also available if you are processing sessions in the background.
Copying Data to Screens
TCODE
TCODE
==
’T’TFBA’
FBA’
Customer
Customer no.
no. 11 Customer
Customer no.
no. 11
Name
Name Hess
Hess Name
Name Hess
Hess
Location
Location Berlin
Berlin PostCode
PostCode 11111
11111 Post.code
Post.code87342
87342
PostCode11111
PostCode11111 Location Berlin
Location Berlin Location
Location UlmUlm
Tel.
Tel. 123
123 Tel.
Tel. 123
123 Tel.
Tel. _
_
TCODE
TCODE
==
’T’TFBA’
FBA’
Customer
Customer no.
no. 21
21
Customer
Customer no.
no. 21
21
Location
Name
Name Müller
Mü ller Name
Name Müller
Mü ller
Location Hof
Hof Post.code
Post.code Post.code 93333
93333 Post.code
Post.code60000
60000
Post.code 93333
93333 Location Hof Location Frankf.
Tel. __ Location Hof Location Frankf.
Tel. Tel. __ Tel. __
Tel. Tel.
.. .. .. ... .. .. ..
SAP AG
n When you process a session with Transaction SM35, the system uses the transaction code (TFBA in
this case) to search for the start screen. Only the relevant session data is copied to this start screen.
n The subsequent screen is then processed. First the data is read from the SAP database and then the
session data is copied to the screen.
n When the transaction has been processed, the system searches for the next transaction code in the
session and starts the transaction.
Processing Modes
SAP AG
n In the ‘Process in foreground’ mode, all screens of a transaction are displayed. The authorizations of the
user doing the processing apply. If a session terminates abnormally in test mode, you can use the
Restart function to branch directly to the session overview (where you can restart the processing).
n In the ‘Display errors only’ mode, screens are displayed only when an error occurs. A transaction
contains an error if a type E (error) or type A (termination) dialog message is output. The authorizations
of the user doing the processing apply.
n In the ‘Process in background’ mode, the session is processed in the background. Your screen is
available for input as soon as the session has been passed to the background control system. The
authorizations of the BDC user specified in the header part of the session apply.
n When processing a session, the update mode is always synchronous (i.e. the next transaction is called
only when the update for the preceding transaction has been completed).
Batch Input Processing
Function
Function OK
OK code
code
Exit
Exit active
active batch
batch input
input transaction
transaction and
and /n
/n
flag as incorrect
flag as incorrect
Delete active batch input transaction in
/bdel
/bdel
session
Exit
Exit batch
batch input
input processing
processing and
and flag
flag as
as /bend
/bend
incorrect
incorrect
Switch
Switch display
display mode
mode from
from "Display
"Display errors
errors /bda
/bda
only"
only" to
to "Process
"Process in
in foreground"
foreground"
Switch
Switch display
display mode
mode from
from "Display
"Display in
in /bde
/bde
foreground"
foreground" to
to "Display
"Display errors
errors only"
only"
SAP AG
n In correction mode (‘Process in foreground’ or ‘Display errors only’), you can control the processing of
your session by choosing System -> Services-> Batch input or by entering a command in the command
field.
Session Status
Processed
Processed Session
Session successfully
successfully processed
processed
Session
Session was
was processed,
processed, but
but still
still
Incorrect
Incorrect contains
contains incorrect
incorrect transactions
transactions
Session created, but not yet
To
To be
be processed
processed processed
Creating
Creating Session
Session currently
currently being
being recorded
recorded
Processing
Processing Session
Session currently
currently being
being processed
processed
Session
Session is
is processed
processed in
in the
the
Background
Background background
background
SAP AG
Sequential
Sequential files
files
Create session t2
t
t1 Process session
SAP
SAP database
database
SAP AG
n When you create batch input programs, bear in mind that session creation and session processing take
place at different times (t1 and t2). What is processed at time t2 is already planned at time t1.
n Example: At time t2, the batch input system can no longer respond to dialog messages (except through
user input in correction mode).
n The batch input system does not take over any SPA/GPA parameters at time t2.
Summary of User Preparations
Run
Run application
application function
function
Note
Note program
program names
names
and
and screen numbers
screen numbers
Note
Note field
field names
names
Note
Note screen
screen sequence
sequence
and
and function
function codes
codes
Create
Create BDC
BDC table
table layout
layout
SAP AG
n When you create a batch input program, you must know the transaction it is based on.
n You therefore run the transaction and make a note of the screen numbers, screen sequence and screen
field names to be addressed later in the program.
n You enter this data in the BDC table.
Summary of Batch Input Programs
Define
Define structure
structure and
and BDC
BDC table
table
Open
Open file
file and
and session
session
Read
Read in
in data
data record
record
Fill
Fill BDC
BDC table
table
Insert
Insert BDC
BDC table
table into
into session
session
Close
Close file
file and
and session
session
SAP AG
SAP AG
Exercises for Chapter 2: Introduction to Batch Input
Processing
Task:
For your file TEL## (you may have to recreate it with program
RSFFF02D) or for the model file TELXX, write a batch input
program which enters the telephone numbers in the relevant
SCUSTOM records using transaction TFBA.
Programming hint:
For transaction TFBA, use the following screens in the order
specified:
Screens Fields
0100 SCUSTOM-ID
BDC_OKCODE
0200 SCUSTOM-TELEPHONE
BDC_OKCODE
ID REC-FLAG 1 U N
Customer ID REC-ID 8 x
Name REC-NAME 25 x x
Postal code REC-POSTCODE 10 x x
City REC-CITY 25 x x
Customer type REC-CUSTTYPE 1 x x
Cust. discount REC-DISCOUNT 3 x x
Telephone REC-TELEPHONE 30 x x
This structure is defined in the include program RSFFF02F.
The ID has one of the following values:
• 'U' (Update): Change SCUSTOM record
• 'N' (New): Add this SCUSTOM record
The 'U' and 'N' records are filled almost identically, only the 'U'
records also contain a customer ID.
Use the following screens in the order specified:
Screens for task 2
ID LIKE SCUSTOM-ID,
END OF REC.
PARAMETERS:
START-OF-SELECTION.
EXPORTING
CLIENT = SY-MANDT
GROUP = NAME
USER = 'BC420BDC'
KEEP = 'X'.
DO.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
PERFORM GENERATE_BDC_DATA.
EXPORTING
TCODE = 'TFBA'
TABLES
DYNPROTAB = BDC_TAB.
ENDDO.
WRITE: / TEXT-002,
END-OF-SELECTION.
*-----------------------------------------------------------------
*
* FORM GENERATE_BDC_DATA
*
*-----------------------------------------------------------------
*
* ........
*
*-----------------------------------------------------------------
*
FORM GENERATE_BDC_DATA.
REFRESH BDC_TAB.
ENDFORM.
*-----------------------------------------------------------------
*
* FORM DYNPRO
*
*-----------------------------------------------------------------
*
* ........
*
*-----------------------------------------------------------------
*
* --> DYNBEGIN
*
* --> NAME
*
* --> VALUE
*
*-----------------------------------------------------------------
*
IF DYNBEGIN = 'X'.
CLEAR BDC_TAB.
'X' TO BDC_TAB-DYNBEGIN.
APPEND BDC_TAB.
ELSE.
CLEAR BDC_TAB.
VALUE TO BDC_TAB-FVAL.
APPEND BDC_TAB.
ENDIF.
ENDFORM.
INCLUDE RSFFF02F.
PARAMETERS:
START-OF-SELECTION.
WRITE: / TEXT-001,
EXPORTING
CLIENT = SY-MANDT
GROUP = NAME
USER = 'BC420BDC'
KEEP = 'X'.
DO.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
CASE REC-FLAG.
WHEN 'U'.
TCODE = 'TFBA'.
PERFORM GENERATE_BDC_DATA_TFBA.
WHEN 'N'.
TCODE = 'TFBB'.
PERFORM GENERATE_BDC_DATA_TFBB.
WHEN OTHERS.
EXIT.
ENDCASE.
EXPORTING
TCODE = TCODE
TABLES
DYNPROTAB = BDC_TAB.
REC-CUSTTYPE, REC-DISCOUNT.
ULINE.
ENDDO.
WRITE: / TEXT-002,
* FORM GENERATE_BDC_DATA_TFBA
*
*-----------------------------------------------------------------
*
* ........
*
*-----------------------------------------------------------------
*
FORM GENERATE_BDC_DATA_TFBA.
REFRESH BDC_TAB.
ENDFORM.
*-----------------------------------------------------------------
*
* FORM GENERATE_BDC_DATA_TFBB
*
*-----------------------------------------------------------------
*
* ........
*
*-----------------------------------------------------------------
*
FORM GENERATE_BDC_DATA_TFBB.
REFRESH BDC_TAB.
ENDFORM.
*-----------------------------------------------------------------
*
* FORM DYNPRO
*
*-----------------------------------------------------------------
*
* ........
*
*-----------------------------------------------------------------
*
* --> DYNBEGIN
*
* --> NAME
*
* --> VALUE
*
*-----------------------------------------------------------------
*
IF DYNBEGIN = 'X'.
CLEAR BDC_TAB.
VALUE TO BDC_TAB-DYNPRO,
'X' TO BDC_TAB-DYNBEGIN.
APPEND BDC_TAB.
ELSE.
CLEAR BDC_TAB.
VALUE TO BDC_TAB-FVAL.
APPEND BDC_TAB.
ENDIF.
ENDFORM.
Chapter 3 Special Features of Batch Input
Processing
l Programming step loop / table control screens in
batch input.
l Programming particular fields in batch input.
l Requirements for batch input capability.
l RSBDCSUB: Utility program for automatic session
processing.
l Batch input authorization.
l Overview of utility programs for batch input.
SAP AG
Chapter 3 Objectives
SAP AG
Example: Display and Change Flights
Flight
Flight model
model // BC_TRAVEL
BC_TRAVEL
Display
Display and
and Change
Change Flights
Flights
(Transaction
(Transaction TCF2
TCF2 ))
Display
Airline carrier AA
Connection number 0064
Airline carrier AA
Connection number 0064
Date Price Curr. Plane Cap. Occup.
Save
Save
SAP AG
n In this example, Transaction TCF2 is used to change the database table SFLIGHT by adding new new
flight data (new plane type, field SFLIGHT-PLANETYPE).
Preparations for BDC Program - SFLIGHT
Table
Table SFLIGHT
SFLIGHT Table
Table SFLIGHT
SFLIGHT
Field
Field PLANETYPE
PLANETYPE Field
Field PLANETYPE
PLANETYPE
Program
Program SAPMTCF2
SAPMTCF2
Screen
Screen number
number 0200
0200
Technical
Technical info
info Help
Help
F1
F1
System
Help Status
Help
F1
F1 Date Price Curr. Plane Cap. Occup.
Function
Function SAVE/11
SAVE/11
SAP AG BC420 / 3 - 1
PROGRAM
PROGRAM SCREEN
SCREEN SCRBEGIN
SCRBEGIN FNAM
FNAM FVAL
FVAL
SAPMTCF2 0100 X
SFLIGHT-CARRID CARRID
SFLIGHT-CONNID CONNID
BDC_OKCODE /5 or UPDA
SAPMTFC2 0200 X
SFLIGHT-PLANETYPE(3) PLANE
BDC_CURSOR SFLIGHT-SEATSMAX(4)
BDC_OKCODE /11 or SAVE
SAP AG
n You enter the information found with the help function in the BDC table.
n For fields of a table control screen, you must also specify the number of the table control line in
parentheses, as a suffix to the field name, e.g. SFLIGHT-PLANETYPE(3) for the aircraft type in line
3. Lines of a step loop screens are addressed in exactly the same way.
n You can also set the cursor. To do this, you use the field name 'BDC_CURSOR'. For the field value,
specify the name of the field on which the cursor is to be positioned.
n For command field input, you can use the function code instead of the number of the function key. To
find out the function code of a function key, use the online help (F1). Place the cursor on the function
key field, hold down the mouse button and press F1. If you choose Extras, you get technical information
which gives the function code.
Creating Sessions - Declaration Part
REPORT RSFFF03A.
PARAMETERS:
NAME LIKE APQI-GROUPID DEFAULT SY-UNAME,
CARRID LIKE SFLIGHT-CARRID DEFAULT 'AA',
CONNID LIKE SFLIGHT-CONNID DEFAULT '0064',
PLANE LIKE SFLIGHT-PLANETYPE DEFAULT 'A310-200'.
SAP AG
n In the declaration part of the BDC program, you define the BDC table.
n Enter the session name in the NAME parameter.
n Enter the flight ID, flight number and aircraft type in the other parameters.
Creating Sessions
START-OF-SELECTION.
WRITE: / 'Start creation of BDC session',
SY-MANDT, NAME, SY-UZEIT.
PERFORM GENERATE_BDC_DATA.
SAP AG BC420 / 3 - 1
n You require the function modules for opening and closing sessions.
n To insert the data in the session, you set up the BDC table in a subroutine and call the function module
BDC_INSERT.
BDC Program: Filling the BDC Table
FORM GENERATE_BDC_DATA.
REFRESH BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-PROGRAM = 'SAPMTCF2'.
BDC_TAB-DYNPRO = '0100'.
BDC_TAB-DYNBEGIN = 'X'.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = 'SFLIGHT-CARRID'.
BDC_TAB-FVAL = CARRID.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = 'SFLIGHT-CONNID'.
BDC_TAB-FVAL = CONNID.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = 'BDC_OKCODE'.
BDC_TAB-FVAL = '/5'.
APPEND BDC_TAB.
SAP AG
n For the first screen of Transaction TCF2, three fields are transferred.
Filling the BDC Table 5
CLEAR BDC_TAB.
BDC_TAB-PROGRAM = 'SAPMTCF2'.
BDC_TAB-DYNPRO = '0200'.
BDC_TAB-DYNBEGIN = 'X'.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = 'SFLIGHT-PLANETYPE(3)'.
BDC_TAB-FVAL = PLANE.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = 'BDC_CURSOR'.
BDC_TAB-FVAL = 'SFLIGHT-SEATSMAX(4)'.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = 'BDC_OKCODE'.
BDC_TAB-FVAL = '/11'.
APPEND BDC_TAB.
ENDFORM.
SAP AG
n The table control fields are transferred for the second screen of Transaction TCF2.
n The data is updated when you choose Save. This completes the batch input processing for this
transaction.
Special Fields
OK
OK code:
code:
<BDC
<BDC tablle> FNAM == ’B
tablle> -- FNAM ’B DC_OKCODE’
DC_OKCODE’
<BDC
<BDC table> FVAL == ’/
table> -- FVAL ’/nn’
nn’
Set
Set cursor:
cursor:
<BDC
<BDC table> FNAM == ’B
table> -- FNAM ’B DC_CURSOR’
DC_CURSOR’
<BDC
<BDC table>
table> -- FVAL
FVAL == <field
<field name>(line
name>(line number)
number)
SAP AG
n In a batch input program, you can address the OK code, table control / step loop fields and cursor.
n The following rules apply when filling the BDC table:
Ÿ The field name for the OK code is always 'BDC_OKCODE'
Ÿ A table control / step loop field must have a valid line number
Ÿ The field name for the cursor is 'BDC_CURSOR'.
Transaction End in Batch Input
Batch
Batch input
input capability
capability
Update
No
No batch
batch input
input capability
capability
SAP AG
n In batch input processing, you can exit a transaction in one of two ways - either through an update or by
returning to the SAP main menu.
n A transaction does not support batch input if it is started by LEAVE TO TRANSACTION <transaction
code>, CALL TRANSACTION <transaction code> or by the command field entry '/n<transaction
code>'.
n The Delete mode function is not supported in batch input.
Report RSBDCSUB
ABAP/4
ABAP/4 development/reporting
development/reporting
Report RSBDCSUB
Execute
Session name
Created on
From____ to
Session status
To be processed
Incorrect
Variant
x Edit
Save
Save
Background
Background job
job
SAP AG
2. Create a background job for the report RSBDCSUB with the variant you have defined.
Processing Batch Input Sessions
Queue
SAP
SAP
Dialog
Dialog Background
Background
process
process process
process
SAP AG
Object
Object Fields
Fields Values
Values Meaning
Meaning
S_BDC_MONI Session name <session names> Specifies session names
for which a user is
authorized
DELE Delete
LOCK Sessions/logs
Lock date, Change
SAP AG
n The authorization object S_BDC_MONI is used for authorization checks in batch input processing.
n You can use this authorization object to restrict processing to particular sessions (specifying the session
name, or make a generic entry). You can also protect specific activities in batch input processing (by
making an entry in the ‘Activities’ field).
Standard Utility Reports for Batch Input
l RSBDCREO
n deletes all sessions which are flagged as successful and still in the
system, together with their logs
n physically deletes all logs for which there are no sessions
n reorganizes the log file (file is reduced if logs have been deleted)
n function integrated in SM35
l RSBDCLOG
n generates a list of batch input logs, selected by session name
n can display or delete logs and, if sessions exist, activate the analysis
n function integrated in SM35
l RSBDCDRU
n allows you to print out the contents of selected sessions
n function integrated in SM35
SAP AG
Chapter 3 Summary
SAP AG
Exercise for Chapter 3: Special Features of Batch Input
Processing
SAP AG
Chapter 4 Objectives
SAP AG
Overview
Customer system
Customer DB/
sequential file
Sequential
file SAP system
Customer
Customer
transfer
transfer
program
program Batch
Batch input
input
program
program
Queue
file
SAP AG
n When the batch input procedure is used to import data from a customer system, the batch input program
generally transfers the data from a sequential file.
n You create the sequential file with a customer transfer program. You then use a batch input program
(the SAP transfer program) to transfer the data from the sequential file to the SAP queue file.
n The SAP System offers standard batch input programs for many standard data transfer cases. This
means you do not have to write you own batch input program. However, the data you provide must be
in a predefined SAP format.
Sequential Dataset in SAP Format
0
1
2
2
1
...
...
0
1
2
1
SAP AG
n The data records of a sequential file must have a format that can be read by a standard SAP batch input
program.
n The applications provide structure descriptions for the standard SAP batch input programs in the
ABAP/4 Dictionary.
n The structure descriptions and the structure of the sequential file depend on the application. They are
described in the documentation for the standard SAP batch input programs.
n Example: In Financial Accounting, there are three different types of data records:
Ÿ Type 0: Session header data (e.g. session name).
Ÿ Type 1: Transaction header data (e.g. transaction code).
Ÿ Type 2: SAP table data (e.g. table name, field name, field contents etc.)
Data Analysis
?
Fields and structures
in the SAP system
SAP AG
Sequential file 1
Customer
transfer program
Structure in old format
Sequential file 2
SAP AG
n The task of a customer transfer program is to create data records in SAP format and transfer them to a
sequential file. The data can then be read by a standard SAP batch input program.
Importing SAP Structures
Transfer program
ABAP/4
ABAP/4 program
program Transfer program
SAP
SAP
Dict. structure
structure <old structure definitions> C
C
definitions
definitions
COBOL
COBOL
<Import SAP structure
definitions> PL/1
PL/1
SAP AG
n You require the SAP structure descriptions for the transfer program. If you write the transfer program
in ABAP/4, you use the TABLES statement to transfer the structure descriptions directly from the
ABAP/4 Dictionary.
n The SAP system also supports the creation of transfer programs in other programming languages
(COBOL, C, PL/1): You generate the structure descriptions in the respective programming language
using the ABAP/4 program RDDSRCG0. These structure descriptions are then available in a sequential
file and you can include them in your transfer program.
Initializing and Converting
.....
Converting fields
Type C Type C
Type P Type C
SAP AG
n For every field passed in the batch input structure, a decision must be made as to whether the value of
the field is initial (e.g. field should be reset to initial value) or whether batch input is not necessary for
this field.
n If batch input data is not to be assigned to particular fields in the SAP System, the standard batch input
programs expect a special character (NODATA flag). The default special character is '/', but you can
define your own character with the field BGR00-NODATA. You must then initialize the SAP batch
input structures with this special character.
n If the fields with the old structures are of a different length or type to the fields with the SAP structures,
the transfer program must perform the conversions. The fields with the SAP batch input structures are
always type C.
Other Tasks of a Transfer Program
Customer
check tables Transfer program
Customer
<Check data> error tables
SAP AG
n There are other tasks that customer transfer programs can perform. Examples: Individual customer data
checks can be made (to see if data should in fact be transferred, for example). Data can be converted
according to defined rules (new numbers in the SAP System are to be assigned to particular numbers in
the legacy system, for example). Incorrect data can be written in a customer error table after the data
checks.
SAP
SAP R/3
R/3 main
main menu
menu
Menu Paths Tools
Tools
Business
Business Engineering
Engineering
Customizing
Customizing
Implement.
Implement. projects
projects
Display
Display SAP
SAP Ref.
Ref. IMG
IMG
Financial
Financial accounting
accounting Treasury
Treasury ...
Financial
Financial accounting
accounting Accounts
Accounts receivable
receivable and
and Consolidation
Consolidation ...
global
global settings
settings accounts
accounts payable
payable
Document
Document Vendor
Vendor accounts
accounts Business
Business transactions
transactions ...
Document
Document data
data transfer
transfer Vendor
Vendor master
master records
records Vendor
Vendor single
single items
items
Create
Create variant
variant for
for Create
Create vendor
vendor master
master ...
document
document data
data transfer
transfer records
records
Generate
Generate record
record layout
layout Copy
Copy vendor
vendor master
master data
data
SAP AG
n The menu paths for finding the data transfer programs are shown for selected applications in the above
diagram. In Release 3.0, you access the Customizing functions via the installation guide.
n For detailed documentation on the individual functions, press F1 and/or the extended help function.
Example: Transfer Program 1
REPORT YSFFF04A.
*E SAP structures for BDC:
TABLES: BGR00, BLF00, BLFA1.
*E Old structures:
DATA: BEGIN OF OLDREC,
TELF1(10) TYPE C,
LIFNR(8) TYPE C,
ANRED(2) TYPE C,
NAME1(30) TYPE C,
END OF OLDREC.
*E Help structure for record layout initialization:
DATA: BEGIN OF AUXREC.
INCLUDE STRUCTURE BLFA1.
DATA: END OF AUXREC.
*E Target fields for conversions:
DATA: LIFNR LIKE BLF00-LIFNR,
NAME1 LIKE BLFA1-NAME1,
TELF1 LIKE BLFA1-TELF1.
*E Only for record layout initialization:
DATA: N TYPE I.
FIELD-SYMBOLS <F>.
*E File and session names, nodata flag:
PARAMETERS:
OLDFILE(20) DEFAULT '/tmp/OLD' LOWER CASE,
SAPFILE(20) DEFAULT '/tmp/SAP' LOWER CASE,
ERRFILE(20) DEFAULT '/tmp/ERROR' LOWER CASE,
SESSION(20) DEFAULT 'B420SES041' LOWER CASE,
NODATA DEFAULT '/' LOWER CASE.
SAP AG
n The program in the above example transfers telephone numbers from a sequential file. The data records
have the following format: Telephone number (10), vendor number (8), form of address (2), name (30).
n The data is checked, converted and formatted so that it can be processed by the standard SAP batch
input program RFBIKR00.
n This is a general example. All processing takes places in the same system and in ABAP/4. It would of
course be possible to simplify the data transfer in this particular case.
Example: Transfer Program 2
START-OF-SELECTION.
OPEN DATASET: OLDFILE FOR INPUT IN TEXT MODE,
SAPFILE FOR OUTPUT IN TEXT MODE,
ERRFILE FOR OUTPUT IN TEXT MODE.
*E Open session:
MOVE: '0' TO BGR00-STYPE,
SESSION TO BGR00-GROUP,
SY-MANDT TO BGR00-MANDT,
SY-UNAME TO BGR00-USNAM,
NODATA TO BGR00-NODATA.
TRANSFER BGR00 TO SAPFILE.
*E Initialize record layout:
DO.
ADD 1 TO N.
ASSIGN COMPONENT N OF STRUCTURE AUXREC TO <F>.
IF SY-SUBRC NE 0. EXIT. ENDIF.
MOVE BGR00-NODATA TO <F>.
ENDDO.
MOVE AUXREC TO BLFA1.
SAP AG
n Session data (such as session name, client, user name and the special character for ‘no batch input for
this field’) is passed in table structure BGR00.
n The structure BLFA1 is initialized using the ASSIGN statement. Some applications (e.g.MM) also
provide special initialization routines (e.g. INIT_STRUKTUREN_ERZEUGEN in program
RMMMBIMI). For more details, refer to the online documentation for the particular batch input
program.
Example: Transfer Program 3
DO.
*E Read in data record
READ DATASET OLDFILE INTO OLDREC.
IF SY-SUBRC NE 0. EXIT. ENDIF.
*E Check: Transfer only certain data records
IF OLDREC-LIFNR(5) NE 'BC420'
OR OLDREC-LIFNR(6) EQ 'BC420B'
OR OLDREC-TELF1 EQ SPACE.
TRANSFER OLDREC TO ERRFILE.
*E TEXT-001:'Data not transferred for vendor:'
WRITE: / TEXT-001, OLDREC-LIFNR.
ELSE.
*E Convert: Other vendor numbers in SAP system
IF OLDREC-LIFNR+5(1) = 'A'.
OLDREC-LIFNR+5(1) = 'B'.
ENDIF.
*E Convert: Write out abbreviations in full
CASE OLDREC-ANRED.
WHEN 'Co'. BLFA1-ANRED = 'Company'.
WHEN OTHERS. BLFA1-ANRED = NODATA.
ENDCASE.
SAP AG
n When a data record has been read, a check is made to see if the data record should in fact be
transferred. In general, extensive checks are run using a customer check table.
n If the check proves negative, the data record is placed in a customer error file.
n Some data is then converted. In general, a customer table is also used here.
Example: Transfer Program 4
*E Convert old format to SAP format
MOVE: OLDREC-LIFNR TO LIFNR,
OLDREC-NAME1 TO NAME1,
OLDREC-TELF1 TO TELF1.
*E Fill SAP structures
MOVE: '1' TO BLF00-STYPE,
'XK02' TO BLF00-TCODE,
LIFNR TO BLF00-LIFNR.
External data
ABAP/4
program
R/3 database
SAP AG
n As an alternative to batch input, there are application-specific programs that use the direct input
technique. When transferring large volumes of data (more than 10000 transactions), you can achieve
considerable improvements in performance with direct input. Like CALL TRANSACTION USING,
direct input is a means of updating data immediately (no sessions are generated). However, unlike
CALL TRANSACTION USING or batch input, no screens are involved. Instead, the data is imported
by calling function modules which check the data and then transfer it directly to the database tables.
Since direct input offers a restart mechanism in the case of an error, the programs can only run as
background jobs. You manage and start these jobs with the report RBMVSHOW or Transaction
BMV0.
n Examples:
RFBIBL00 FI Can be switched between direct input, batch input and CALL
TRANSACTION. Posts documents.
Define
Define old
old structures
structures
Import
Import SAP
SAP structures
structures
Initialize
Initialize SAP
SAP structures
structures
Check
Check data
data
Convert
Convert data
data
Place
Place data
data in
in SAP
SAP structure
structure
Transfer
Transfer data
data record
record to
to sequential
sequential file
file
SAP AG
n The above diagram gives an overview of the tasks of a transfer program (required and optional).
Data Transfer with Batch Input
Analyze
Analyze data
data
Generate
Generate SAP
SAP structures
structures
Design
Design transfer
transfer program
program
Create
Create batch
batch input
input program
program
Create
Create batch
batch input
input session
session
Analyze
Analyze results
results
Evaluate
Evaluate errors
errors
SAP AG
n The above diagram gives an overview of the activities required for a data transfer.
Chapter 4 Summary
SAP AG
Chapter 5 CALL TRANSACTION
SAP AG
Chapter 5 Objectives
SAP AG
Overview
Batch input: CALL TRANSACTION:
Sequential Sequential
file file
BDC
BDC table
table BDC
BDC table
table
Queue file
CALL
TRANSACTION
Batch
Batch input
input function
function
Application
Application function
function Application
Application function
function
SAP SAP
database database
SAP AG
n In contrast to batch input, the CALL TRANSACTION statement allows you to pass data directly to the
dialog interface (without using the queue file). To store screen data temporarily, you use an internal
table (a BDC table which has the same structure as with batch input). Then, you call the desired
transaction in your program and the system copies the data temporarily stored the BDC table to the
screens of the transaction.
The CALL TRANSACTION Statement
CALL
CALL TRANSACTION
TRANSACTION <transaction
<transaction code>
code>
USING
USING <BDC
<BDC table>
table>
MODE
MODE <display
<display mode>
mode>
UPDATE
UPDATE <update
<update mode>
mode>
MESSAGES
MESSAGES INTO
INTO <messtab>
<messtab>
<display
<display mode>:
mode>:
AA Display
Display all
all
EE Display
Display only
only ifif there
there are
are errors
errors
N
N Display
Display nothing
nothing
<update
<update mode>:
mode>:
SS Do
Do not
not continue
continue processing
processing until
until
update
update has
has finished
finished (synchronous)
(synchronous)
A
A Continue
Continue processing
processing immediately
immediately
SAP AG
n As with batch input, you can choose a particular display mode for processing the transaction.
n Unlike batch input, you can also specify an update mode. In asynchronous update processes, the called
transaction does not wait until the database updates have been performed, but passes the update to the
update task. In synchronous update processes, it waits until the update has been completed. Although
synchronous update is slower than asynchronous update, it is also more secure because the called
transaction can then report any errors to the calling program. In batch imput, the update mode is always
'S' (synchronous).
n The MODE and UPDATE parameters are optional. The default for both is ‘A’ (asynchronous).
n The MESSAGES INTO <messtab> option allows you to store any messages output by the called
transaction in an internal table. The internal table <messtab> must have the structure BDCMSGCOLL.
Technical Implementation
SAP AG
n The system opens a second roll area for the called transaction. There, it processes the individual screens
and copies the data from the table. When the transaction has finished, the second roll area is released
and the processing continues in the first roll area.
Notes:
In contrast to batch input, there is no error logging. Whether the called transaction is processed depends
on the authorizations of the calling user. The BDC table can only accept data for a single transaction.
This means that before the next transaction call, you must perform a REFRESH on the BDC table and
refill it with data.
Example Program - Define BDC Table
REPORT RSFFF05A.
PARAMETERS:
DISMODE DEFAULT 'A',
UPDMODE DEFAULT 'S',
ID LIKE SCUSTOM-ID DEFAULT '00000001',
CUSTNAME LIKE SCUSTOM-NAME DEFAULT 'SCHMIDT',
POSTCODE LIKE SCUSTOM-POSTCODE DEFAULT '6900',
CITY LIKE SCUSTOM-CITY DEFAULT 'HEIDELBERG',
CUSTTYPE LIKE SCUSTOM-CUSTTYPE DEFAULT 'B',
DISCOUNT LIKE SCUSTOM-DISCOUNT DEFAULT '10',
TELEFON LIKE SCUSTOM-TELEPHONE DEFAULT '24567'.
SAP AG
n You define the BDC table in the declaration part of the program.
n This CALL TRANSACTION program corresponds to the BDC program example RSFFF02A.
Example Program - Fill BDC Table
START-OF-SELECTION.
WRITE: / 'Start CALL TRANSACTION', SY-UZEIT.
PERFORM GENERATE_BDC_DATA.
IF SY-SUBRC = 0.
WRITE: / 'Transaction successfully
processed'.
ELSE.
WRITE: / 'Error when processing'.
ENDIF.
SAP AG
n You fill the BDC table as in batch input (in this case with a subroutine - see BDC program
RSFFF02A).
n Then, you call the desired transaction.
Return Codes and System Fields
Return codes:
Value Meaning
0 Successful
System fields:
Field name Meaning
SY-MSGID
SY-MSGID Message
Message ID
ID
SY-MSGTY
SY-MSGTY Message
Message type
type (E,I,W,S,A)
(E,I,W,S,A)
SY-MSGNO
SY-MSGNO Message
Message number
number
SY-MSGV1
SY-MSGV1 Message
Message variable
variable 11
SY-MSGV2
SY-MSGV2 Message
Message variable
variable 22
SY-MSGV3
SY-MSGV3 Message
Message variable
variable 33
SY-MSGV4
SY-MSGV4 Message
Message variable
variable 44
SAP AG
n To find out whether the processing of the called transaction was successful or not, you can read the
return code value. There are also other system fields which contain the number, ID, type and variable of
the dialog message output by the called transaction. You can use this information to display the message
text (see following page).
n If you want to see all the messages output by the transaction, you should use the MESSAGES INTO
<messtab> option and then evaluate the contents of <messtab>.
Message Output
REPORT RSFFF05B.
...
MESSAGE ID SY-MSGID
TYPE SY-MSGTY
NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2
SY-MSGV3 SY-MSGV4.
...
SAP AG
n The MESSAGE statement allows you to output dialog messages of the called transaction through the
calling program.
n However, the message which reports the success or failure of the processing is output automatically.
You are recommended to use the MESSAGE statement as above if you are running the program in the
background. In this case, the message is held in the log.
Batch Input / CALL TRANSACTION - Summary
SAP AG
n Batch input and the CALL TRANSACTION statement are two different options for copying data to
screens in an application transaction.
n The above table sets out the various features of these options.
Chapter 5 Summary
SAP AG
Exercise for Chapter 5: CALL TRANSACTION
Screens Fields
0100 SCUSTOM-ID
BDC_OKCODE
0200 SCUSTOM-TELEPHONE
BDC_OKCODE
Model solution for Chapter 5: CALL TRANSACTION
REPORT RSFFF051.
* messages
ID LIKE SCUSTOM-ID,
END OF REC.
PARAMETERS:
START-OF-SELECTION.
START-OF-SELECTION.
* Accessing data
DO.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
PERFORM GENERATE_BDC_DATA.
USING BDC_TAB
MODE DISMODE
UPDATE UPDMODE.
WRITE: TEXT-002.
ELSE.
WRITE: TEXT-003.
ENDIF.
MESSAGE ID SY-MSGID
TYPE SY-MSGTY
NUMBER SY-MSGNO
ENDDO.
END-OF-SELECTION.
*-----------------------------------------------------------------
*
* FORM GENERATE_BDC_DATA
*
*-----------------------------------------------------------------
*
* ........
*
*-----------------------------------------------------------------
*
FORM GENERATE_BDC_DATA.
REFRESH BDC_TAB.
ENDFORM.
*-----------------------------------------------------------------
*
* FORM DYNPRO
*
*-----------------------------------------------------------------
*
* ........
*
*-----------------------------------------------------------------
*
* --> DYNBEGIN
*
* --> NAME
*
* --> VALUE
*
*-----------------------------------------------------------------
*
IF DYNBEGIN = 'X'.
CLEAR BDC_TAB.
VALUE TO BDC_TAB-DYNPRO,
'X' TO BDC_TAB-DYNBEGIN.
APPEND BDC_TAB.
ELSE.
CLEAR BDC_TAB.
VALUE TO BDC_TAB-FVAL.
APPEND BDC_TAB.
ENDIF.
ENDFORM.
Chapter 6 Local Files
SAP AG
Chapter 6 Objectives
SAP AG
Overview
Application
server
88MHz
Presentation
server
88MHz
SAP AG
n ABAP/4 programs run on the application server and have access to its sequential files.
n You can also use an ABAP/4 program to process local files (which belong to the presentation server).
Overview
READ DATASET
TRANSFER
UPLOAD
DOWNLOAD
Presentation server
files
SAP AG
n You process sequential files on the application server in ABAP/4 programs with the READ DATASET
and TRANSFER statements which allow you to copy data from/to a field string.
n You process local sequential files on the presentation server with (UPLOAD and DOWNLOAD)
function modules. These copy data from/to an internal table.
DOWNLOAD and UPLOAD
Convert
Convert Convert
Convert
according
according to
to according
according to
to
file
file type
type file
file type
type
SAP AG
n The function module DOWNLOAD downloads the contents of an internal table to a local sequential
file.
n The function module UPLOAD uploads the contents of a local sequential file to an internal table.
n For the local file, you specify the absolute file name (meaning the complete path, e.g.
'/tmp/bc180/myfile' for the UNIX file myfile in the directory /tmp/bc180 or 'C: BC180 MYFILE.ABA'
for the OS/2 file MYFILE.ABA in the directory BC180 on disk drive C).
The directory must be known to the presentation server.
The choice of suitable file names is the reponsibility of the customer.
n The system requests the file name and the file type interaktively.
n The data is converted according to the file type.
Function Module DOWNLOAD
CALL FUNCTION ’D
CALL FUNCTION ’D OWNLOAD’
OWNLOAD’
EXPORTING
BIN_FILESIZE = <File length for binary files>
CODEPAGE = <Do not use>
FILENAME = <File name - default value>
FILETYPE = <File type - default value>
ITEM = <Header for file dialog>
MODE = <Write mode>
WK1_N_FORMAT = <Value column format for WK1 file type>
WK1_N_SIZE = <Value column width for WK1 file type>
WK1_T_FORMAT = <Text column format for WK1 file type>
WK1_T_SIZE = <Text column width for WK1 file type>
IMPORTING
ACT_FILENAME = <File name - entered value>
ACT_FILETYPE = <File type - entered value>
FILESIZE = <Number of bytes downloaded>
TABLES
DATA_TAB = <Transfer file>
SAP AG
n For the function module DOWNLOAD, you need an internal table for the data transfer. You define this
table according to your data structure at the beginning of the program and then fill it with data.
n You use the MODE parameter to define the write mode ('A' to extend a file, ' ' to create a new file).
n The specification of default values for the file name, file type and a header for the file dialog is optional.
n The IMPORT parameters specify the values actually entered by the user for the file name, file type and
the number of downloaded bytes.
n You only specify a value for the export parameter CODEPAGE when performing a DOWNLOAD to
DOS (the only possible value is 'IBM'). Otherwise, this parameter is not used.
n All EXPORTING parameters are optional.
n If you want to generate a binary file, you must specify the file length. In this case, the transfer table
must consist of a column of type X.
Formats
Internal
Internal table
table (ABAP/4)
(ABAP/4) Internal
Internal table
table (ABAP/4)
(ABAP/4)
F1 F2 F3 F1 F2 F3 ...
A B C A B C ...
D E F D E F ...
. . . G H I ...
. . . . . .
Format
Format DAT
DAT Format
Format WK1
WK1
Spreadsheet
Spreadsheet Spreadsheet
Spreadsheet
SAP AG
n With UPLOAD and DOWNLOAD, another format available for conversions apart from ASC (ASCII)
and BIN (binary) is DAT for Excel. With DOWNLOAD, WK1 is also available for Excel and Lotus.
n For the format DAT, table columns are divided by a tabulator character and the table lines by carriage
return and line feed.
n For the format WK1, the data of a table is entered in a WK1-specific spreadsheet.
Function Module UPLOAD
CALL FUNCTION ’U
CALL FUNCTION ’U PLOAD’
PLOAD’
EXPORTING
CODEPAGE = <Do not use>
FILENAME = <File name - default value>
FILETYP = <File type - default value>
ITEM = <Header for file dialog>
IMPORTING
FILESIZE = = <File length>
TABLES
DATA_TAB = <Transfer table for file contents>
SAP AG
n For the function module UPLOAD, you need an internal table for the data transfer. You define this
table according to your data structure at the beginning of the program.
n The specification of default values for the file name, file type and a header for the file dialog is optional.
n You only specify a value for the export parameter CODEPAGE when performing a DOWNLOAD to
DOS (the only possible value is 'IBM'). Otherwise, this parameter is not used.
Example Program: DOWNLOAD
REPORT RSFFF06A.
TABLES SFLIGHT.
DATA: BEGIN OF TAB OCCURS 20.
INCLUDE STRUCTURE SBC420A.
DATA: END OF TAB.
* DATA: FILE LIKE RLGRAP-FILENAME
* VALUE '....',
* TYPE LIKE RLGRAP-FILETYPE
* VALUE 'ASC',
* LENGTH(5).
* PARAMETERS:
* MODE DEFAULT 'A'.
GET SFLIGHT.
MOVE-CORRESPONDING SFLIGHT TO TAB. CALL
CALL FUNCTION
FUNCTION 'DOWNLOAD'
'DOWNLOAD'
APPEND TAB. ** EXPORTING
EXPORTING
WRITE: / TAB-CARRID, TAB-CONNID, ** FILENAME
FILENAME == FILE
FILE
/ TAB-FLDATE UNDER TAB-CARRID, ** FILETYPE
FILETYPE == TYPE
TYPE
/ TAB-PLANETYPE UNDER TAB-FLDATE. ** ITEM
ITEM == 'SFLIGHT data'
'SFLIGHT data'
END-OF-SELECTION. ** MODE
MODE = MODE
= MODE
** IMPORTING
IMPORTING
** ACT_FILENAME
ACT_FILENAME == FILE
FILE
** ACT_FILETYPE
ACT_FILETYPE == TYPE
TYPE
** FILESIZE
FILESIZE = LENGTH
= LENGTH
TABLES
TABLES
DATA_TAB
DATA_TAB == TAB.
TAB.
** WRITE:
WRITE: // LENGTH,
LENGTH, 'bytes
'bytes downloaded
downloaded to
to file
file ''
** FILE,
FILE, 'format',
'format', TYPE.
TYPE.
SAP AG
REPORT RSFFF06B.
TABLES SFLIGHT.
DATA: BEGIN OF TAB OCCURS 20.
INCLUDE STRUCTURE SBC420A.
DATA: END OF TAB,
START-OF-SELECTION.
CALL FUNCTION 'UPLOAD'
TABLES
DATA_TAB = TAB.
LOOP AT TAB.
WRITE: / TAB-CARRID, TAB-CONNID,
/ TAB-FLDATE UNDER TAB-CARRID,
/ TAB-PLANETYPE UNDER TAB-FLDATE.
ENDLOOP.
SAP AG
List
List ABAP/4
ABAP/4 Editor
Editor
00001
00002
00003
. .
. .
. .
Function
Function UPLOAD
UPLOAD
Function
Function DOWNLOAD
DOWNLOAD DOWNLOAD
DOWNLOAD
SAP AG
n You can call the function DOWNLOAD from a list (choose System -> List -> Save -> Local file) or
from the ABAP/4 Editor to download a list or an ABAP/4 program to a local file
This process supports certain formats.
n You can call the function UPLOAD from the ABAP/4 Editor to upload an ABAP/4 program from a
local file to the ABAP/4 Editor.
Sequential File and Local File
TRANSFER
TRANSFER CALLFUNCTION
CALLFUNCTION
’D
’D OWNLOAD’
OWNLOAD’
READ
READ DATASET
DATASET CALLFUNCTION
CALLFUNCTION
’U
’U PLOAD’
PLOAD’
SAP AG
n You can use READ DATASET and DOWNLOAD to copy the contents of a sequential file to a local
sequential file via an internal table.
n Conversely, you can use UPLOAD and TRANSFER to transfer data from a local sequential file to a
sequential file.
UPLOAD / DOWNLOAD - Summary
WS_DOWNLOAD
WS_DOWNLOAD WS_UPLOAD
WS_UPLOAD
Download data Read data
DOWNLOAD
DOWNLOAD UPLOAD
UPLOAD
Download data Read data
Physical Get
file name file size
WS_FILENAME_GET
WS_FILENAME_GET WS_QUERY
WS_QUERY
Execute
program
WS_EXECUTE
WS_EXECUTE
SAP AG
n The function modules UPLOAD and DOWNLOAD are a convenient way of processing local files
because they perform all the necessary activities automatically. The user is requested to specify the file
name and type interactively.
n There are also other function modules you can use for file processing. These include the following:
Ÿ WS_DOWNLOAD and WS_UPLOAD:
Like DOWNLOAD, except that the file name and type are not specified interactively and exceptions
must be handled by the calling program.
Ÿ WS_QUERY:
checks the existence and size of a file, as well as other environment variables.
Ÿ WS_EXECUTE:
SAP AG
Exercises for Chapter 6: Local Files
1.
REPORT RSFFF061.
* or include report
* STRUCTURE SBC420C:
* Alternative:
* INCLUDE RSFFF01L.
LENGTH(5).
PARAMETERS:
START-OF-SELECTION.
* internal table
DO.
CLEAR TAB.
APPEND TAB.
ULINE.
ENDDO.
* internal table TAB together with the file name and file type
EXPORTING
FILENAME = LOCLFILE
FILETYPE = TYPE
MODE = MODE
IMPORTING
* ACT_FILENAME = FILE
* ACT_FILETYPE = TYPE
FILESIZE = LENGTH
TABLES
DATA_TAB = TAB.
*E Text-001: 'In file:'
*E Text-002: 'Format'
LENGTH, TEXT-003.
2.
REPORT RSFFF062.
* or include report
* STRUCTURE SBC420C:
* Alternative:
* INCLUDE RSFFF01L.
LENGTH(5).
PARAMETERS:
START-OF-SELECTION.
* Call the function module UPLOAD. Pass the name of the file to be
EXPORTING
FILENAME = LOCLFILE
FILETYPE = TYPE
IMPORTING
FILESIZE = LENGTH
TABLES
DATA_TAB = TAB.
LOOP AT TAB.
ULINE.
ENDLOOP.
*D Text-002: 'Format'
LENGTH, TEXT-003.
Appendix IV
SAP AG
Batch Input
Input
Input file
file
RFBIDE00
RFBIKR00
RFBISA00
RFBIBL00
Post
Buchen Batch
document
Beleg input
session XX
DIALOG
DIALOG interface
interface
SAP AG
n The reports RFBIDE00, RFBIKR00, RFBISA00 and RFBIBL00 support automatic import of data
from external or legacy systems.
n RFBIDE00 transfers customer master data and creates bank master data and credit limits.
n RFBIKR00 transfers vendor master data and creates bank master data.
n RFBISA00 transfers G/L account master data creates bank master data.
n RFBIBL00 transfers documents (posting and settlement).
n For further online documentation, choose Help -> R/3 library -> Financial Accounting -> Automatic
Procedures -> Batch Input
Batch Input Flow
SAP –– unknown
SAP unknown data
data SAP –– known
SAP known data
data
BI Format
SAP
SAP transfer
transfer programs
programs SAP
SAP transfer
transfer programs
programs
BI
BI interface
interface
SAP AG
n You must create an interface program to convert non-SAP data to a format recognized by SAP.
n The required record structures are defined in the ABAP/4 Dictionaryt (e.g. BBKPF, BBSEG). By using
a Customizing function, you can format the record layout in the Cobol, PL1, and C programming
languages.
Batch Input Structures
Examples
Typ BGR00
Typ 00 Session
Session data
data
Typ BLF00
Typ 11 Transaction
Transaction code
code and
and header
header data
data
BBKPF
BLFA1
Typ
Typ 22 Batch
Batch input
input data
data per
per table
table BBSEG
Naming convention: B T T T T
Batch
Batch input
input Table
Table name
name
SAP AG
n For each supported database table, there is an associated batch input structure.
n Batch input structures are stored in the ABAP/4 Dictionary.
n A batch input structure begins with the letter 'B' followed by the name of the table for which batch input
data is determined.
n For each input field on a screen, there is a batch input field in the batch input structure.
n The special character "/" means:
BLF00
BLF00 Type
Type 11 Transaction
Transaction code,
code,
key
key fields
fields
BLFA1
BLFA1 Type
Type 22 General
General data
data
BLFBK
BLFBK Type
Type 22 Bank
Bank connections
connections
BLFB1
BLFB1 Type
Type 22 Company
Company code
code data
data
BLFB5
BLFB5 Type
Type 22 Dunning
Dunning data
data
BLFM1
BLFM1 Type
Type 22 Purchasing
Purchasing data
data
SAP AG
n The central transactions listed above are supported for customers and vendors.
n Depending on what is specified in the key fields of the type 1 record, the type 2 records are expected.
n The structures of type 2 records do not contain the key fields of the underlying database table.
n The key fields are obtained from the structures of the type 0 and type 1 records.
Example of Batch Input 1
BGR00 00 session
session -- XX
XX 001
001 ...
BLF00 11 XK02
XK02 0000004711
0000004711 // // //
BLFA1 22 BLFA1
BLFA1 // New
New name
name // ...
BLF00 11 XK02
XK02 0000004712
0000004712 0001
0001 // //
BLFA1 22 BLFA1
BLFA1 // ... New
New city
city // ...
BLFB1 22 BLFB1
BLFB1 // ... ZB00
ZB00 // ...
BLF00
SAP AG
n Since there are several type 2 structures, the table name must also be passed.
n The bank connections are stored in a multiple case table. For this reason, there may be several records
with the structure BLFBK (BKNBK) for each transaction.
n To delete a bank connection, you must set the delete flag in the structure BLFBK (BKNBK).
Documents
Transaction
Transaction
FB01
FB01 Post
Post document
document
FB05
FB05 Post
Post with
with clearing
clearing
Structures
Structures
BGR00
BGR00 Type
Type 00 Session
Session data
data
BBKPF
BBKPF Type
Type 11 Transaction
Transaction code
code
and
and header
header data
data
BBSEG
BBSEG Type
Type 22 Document
Document segment
segment data
data
BSELK
BSELK Type
Type 22 Selection
Selection header
header data
data
BSELP
BSELP Type
Type 22 Selection
Selection item
item data
data
SAP AG
BGR00 00 Session
Session -- XX
XX 001
001 ...
BBKPF 11 FB01
FB01 TTMMJJJJ
TTMMJJJJ DR
DR 0001
0001 . . .
BBSEG 22 BBSEG
BBSEG 01
01 0000004711
0000004711 // // 1000
1000 ...
BBKPF 11 FB01
FB01 TTMMJJJJ
TTMMJJJJ KR
KR 0001
0001 . . .
BBSEG 22 BBSEG
BBSEG 31
31 0000004712
0000004712 // // 2000
2000 ...
BBSEG 22 BBSEG
BBSEG 40
40 Expenses
Expenses // // 2000
2000 ...
BBKPF
:
SAP AG
n The structure BBSEG contains all the fields of the structure BSEG and also includes the CPD data or
the data of the differing payment recipient and the data for additional screens.
n You can pass amount fields with a decimal comma.
Transfer Options per Company Code
Determine
Determine
for
for each
each
company
company code
code
Transfer
Transfer date
date
Status
Residual
Residual value
value
Calculate
Calculate cum.
cum. insurable
insurable value
value
Sequence
Sequence ofof depreciation
depreciation areas
areas
for
for transfer
transfer of
of legacy
legacy data
data
SAP AG
Replacement
Replacement value
value
Cum.
Cum. depreciation
depreciation
Transfer
Transfer ofof legacy
legacy data
data less
less than
than aa
year old - last depreciation posting
year old - last depreciation posting
period
period of
of legacy
legacy system
system
SAP AG
Legacy
Legacy system
system
Interface
Interface program
program
Legacy data in transfer format
BALTD and BALTB
Transfer
Transfer program
program RAALTD01
RAALTD01
error-free
error-free records
records records
records with
with errors
errors
Batch
input
D
D II A
A LL O
OGG II N
N TT EE R
R FF A
ACC EE
ANLH
ANLA
ANLB
ANLC
..
.
SAP AG
n An interface program is used to convert data from a legacy system to the format of the Dictionary tables
BALTD (master data) and BALTB (transaction data) and copy it to a sequential file.
n The legacy data transfer program RAALTD01 starts a legacy data transfer transaction in the
background for error-free records. Records containgin errors are stored in the form of a batch input
session and must be processed again later.
n The documentation of the program RAALTD01 contains precise instructions
Ÿ for setting up the sequential transfer file with the interface program,
Ÿ test options,
Ÿ avoiding errors and interpreting those which occur,
Ÿ procedure in the case of a program termination.
Transferring Assets
Account
Account control
control in
in production
production FI
FI
Before AM import
(RACKONT2)
After AM import
Vendor Asset
1000 1000
1000
SAP AG
n After import, the G/L accounts must be changed from “directly postable” to “reconciliation account
only”.
Data Transfer
SAP
SAP data
data transfer
transfer
program
... ...
Screen 1 Screen 2 Screen 1 Screen 2
SAP
condition records
SAP AG
n SAP provides transfer programs (batch input) for transferring data from legacy systems.
n Data to be transferred to the R/3 System must be placed in a sequential file and the records must have
SAP structure and format. The data is transferred from the legacy system to the sequential file by a
subroutine created by the customer. Using an SAP program, you can generate data declarations in
different programming languages for SAP tables and make use of these for your conversion program.
n The SAP transfer program (batch input) reads the data from the sequential file, retrieves it for transfer
to the R/3 System and uses it to create a batch input session.
n When the session is processed, the data is transferred to the R/3 System. Here, a user dialog is
simulated so that the same checks are performed as in a dialog.
There are data transfer programs for
Features
Execution of ABAP/4 programs without dialog or
operating sytem-specific Job Control Language
Easy to use
Distributed processing
SAP AG
n If an ABAP/4 report has to process large volumes of data and long, complex lists, you should execute it
as a background job.
Phases of Background Job Processing
SAP AG
Print specifications
Start time
Period
Save
SAP AG