You are on page 1of 333

Data Interfaces

Application Development in the


ABAP/4 Development Workbench
Week 4

 SAP AG
Contents I / Week 4

Chapter 1 Principles Chapter 4 ABAP/4 Desktop Integration


Components
Chapter 2 Linking Options
Chapter 5 CPI-C Interface
Chapter 3 Remote Function Call

Exercises
Solutions

 SAP AG
Chapter 1 Basic Techniques

l Overview of linking options


l Overview of Basis interfaces
l Overview of basic components

 SAP AG
Chapter 1 Objectives

l Main terms and components for communications


interfaces.
l Basic techniques of direct, cross-system
communication:
CPI-C, RFC and OLE (programming interfaces) and
the relevant system components (SAP gateway, side
information tables, transport logs)

 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

Database Database operations (SQL)


server
ABAP/4 Open SQL, ABAP/4 Native SQL
... Batch input
CALL TRANSACTION ... USING
Application Application
CPI-C
server 1 server 2
RFC
Seq. files (application server files)
... Seq. files (frontend files)

Frontend Frontend OLE


(SAPGUI) (SAPGUI) RFC

 SAP AG

n At different levels in the R/3 System, there are various data communication options. These include the
following:

1) Communication with the database via ABAP/4 Open SQL or DB SQL.


2) Indirect data communication using file transfer.
3) Techniques of direct, cross-system communication in the network.

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:

- Access to sequential files of the application server and the frontend


- CPI-C ---> program-to-program communication
- RFC ---> Remote Function Call
n At frontend level, the following Basis techniques are available:

- Access to sequential files


- RFC
- OLE (Object Linking and Embedding
Indirect Communication I

Data transfer using files


w READ DATASET <path> INTO <rec>
w TRANSFER <rec> TO <path>
w Function module: WS_UPLOAD
w Function module: WS_DOWNLOAD

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

seq. file Read


sequential file R/3 System

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

n Batch input is based on file transfer with additional update.


n With this process, you should note that only one system must be active at any one time. You can transfer
the files to the other system and read in the data at a later stage. Time-critical data should not be
involved here.
Transferring Time-critical Data
Example: Local warehouse

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

Program-to-program communication (CPI-C)

Phase Local warehouse Central


computer system

Set up Connection setup


II
connection accepted
"Goods xyz received"
Data Data received
IIII transfer and updated
ok

III Close Connection closure


III accepted
connection

 SAP AG

n As the name (COMMON PROGRAMMING INTERFACE FOR COMMUNICATIONS) implies, CPI-


C is a general programming interface for communication purposes.
n CPI-C allows two applications or two programs to communicate with each other in much the same way
as two people communicate in an ordinary telephone conversation. One program sets up the connection,
while the partner program accepts the connection. Then, application data can be exchanged until the
communication link is closed by one of the partners. You can use this method to make time-critical data
immediately available in the partner system.
n The concept behind the CPI-C interface was originally developed by IBM within the framework of SAA
(System Application Architecture). Other SAA interfaces include CUA (Common User Access) and
CCS (Common Communication Support). CPI-C was later taken over by the X/OPEN group.
n SAP has implemented the CPI-C interface. The CPI-C starter set is also supported.
Direct Communication II

Remote call to a routine (RFC)

Local warehouse Central


computer system
System XYZ
Call function Call
ABC in Function ABC
system XYZ
with the Process
parameters parameter values
Result 1, 2, 3 and
1,2,3.
return result

 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

TCP/IP SNA LU6.2


- R/2 TCP/IP - R/2
- External systems - External systems
SNI (BS2000) IBM
Windows NT R/3 Host systems
UNIX

 SAP AG

n Communication is possible between SAP applications and with external systems.


n Data exchange is based on different transport protocols which are specific to a particular platform or
manufacturer.
n Communication with an R/3 System is always via the TCP/IP protocol.
n IBM platforms communicate via the SNA protocol LU6.2.
n All other platforms support TCP/IP.
ISO-OSI 7-Layer Model

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

n The SAP gateway is used for every CPI-C or RFC communication.


n The SAP gateway consists of several programs. At runtime, these can be identified as the "gw*"
processes.
n If you wish, the CPI-C handler can perform a protocol conversion. You need this if, for example, you
want to set up a connection to an IBM host system.
n Every application server has a gateway.
n It is also possible to install an SAP gateway as a standalone instance.
n The SAP gateway is ported for SNI BS2000.
Side Information Tables
Contents:
Symbolic destination ---> addressed in the program
Partner LU ---> target machine or Logical Unit (SNA)
Partner program ---> name of partner program
...

Side information tables

R/3 TXCOM --> CPI-C connection setup


RFCDES --> RFC connection setup
R/2 XCOM --> CPI-C, RFC connection setup
RFCD --> RFC connection setup
UNIX side info
WINDOWS NT side info
WINDOWS 3.1 side info For SAP gateways and libraries
WINDOWS 95 side info on external platforms
OS/2 side info

 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

l The R/3 System supports various techniques for direct


online communication between programs in different
systems and on different machines in a network.
l Connections can be set up both from and to R/3.

 SAP AG
Chapter 2 Linking Options

l Communication between R/3 Systems


l Communication between R/3 and R/2 Systems
l Communication between R/3 and external systems

 SAP AG
Chapter 2 Objectives

l The different linking options between R/3, R/2 and


external systems.
l Terms such as SAP gateway, side info tables, and
RFC tables, as well as the underlying concepts.

 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 (the R/3 Systems can be different releases)

R/3 - R/2 (R/2 can be running on an IBM or an SNI platform)


n The question of which system sets up the connection will also be discussed in more detail.
Communication: R/3 – External Programs

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

Functionality of the SAP gateway


R/3 R/3

gwrd gwrd

dispatcher gwwp dispatcher

gwhost
LU6.2

TCP/IP R/2 (IBM)

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 ...

TGB LU1 CP1C2

R/3: TXCOM TXCOM


DEST LU TP Prot ...

ABC LU2 CPIC2 E

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)

Table RFCDES (R/3)


RFC destination: BC415
Connection type: 3
Target machine: hs5001 System number: 00
Description: Demo RFC connection
Language: D User: Miller
Client: 000 Password: Demo

Table RFCD (R/2)


DEST MAN User name Password S Argument of table XCOM

BC415 000 Miller Demo D TGB

 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

System T01 System T02

TCP/IP

Table TXCOM (T01)

Dest LU TP Prot Gateway host Gateway service

BC415A hs5101 sapgw01 I


BC415B hs5101 sapgw01 I hs5101 sapgw01

 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:

- Is R/2 running on IBM or SNI?

- Which transaction monitor is running on the host?

For IBM: CICS or IMS?


For SNI: DCAM or UTM?

- 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

TCP/IP (remote) LU6.2


shared memory (local)

Table RFCDES (T01) Gateway options


RFC destination K50 Gateway host: hs5002

Connection type 2 Gateway service: sapgw00

Table TXCOM (T01) Side info SAPgateway

Dest LU TP Prot Gateway host Gateway service DEST = K50


LU = K50T00
K50 C hs5002 sapgw00 TP = X1SA

 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:

- The destination Dest can be any name you choose


- LU and TP are dummy entries and can be left blank
- Prot (protocol) must be C
n In the case of an RFC 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 the R/3 table RFCDES and an entry in the gateway table
sideinfo.
R/2 à R/3 Communication (IBM)
Connection setup from R/2
hs5000 hs5001, sapgw00

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)

Table XCOM (K50) Side info from gwhost

Dest LU TP DEST = T01


T01 MP30 T01 LU = hs5001
(hs5000) TP = sapgw00
GWHOST = hs5001
GWSERV = sapgw00
Protocol = I

 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

UNIX, NT (T01) BS2000 (K50)

R/3 SAP gateway


ABAP/4
R/2
TCP/IP
ABAP/4

Table RFCDES Gateway options


RFC destination K50 Gateway host: BS2GW

Connection type 2 Gateway service: sapgw00

Table TXCOM (T01)

Dest LU TP PROT Gateway host Gateway service

BS2000 C BS2GW sapgw00

 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:

BS2000 version 11, DCAM version 11 (BCAM V.11 with TCP/IP)


n On BS2000 machines, the SAP gateway can communicate with an UTM application or a DCAM
application.
n Table TXCOM of the R/3 System:

Dest LU TP Prot Gateway host Gateway service


S50 C host name sapgwXX
n The entries for LU and TP are dummy entries. For the gateway the following applies:

LU=DEST and TP=X1SA


n host name is the name derived from the BCAM generation of the BS2000 host where the gateway is
running. The gateway can function with or without side information.

(Parameter: bs2/use_sideinfo [0,1]).


R/2 à R/3 Communication (SNI)
Connection setup from R/2
hs5001, sapgw00

BS2000 (K50) UNIX, NT (T01)


SAP gateway
R/2
ABAP/4
R/3
Progr: gwhost TCP/IP ABAP/4

Table XCOM (K50) Side info from gwhost

Dest LU TP Comm. type Dest = T01


LU = hs5001
BS2R3 T01 H TP = sapgw00
GWHOST = hs5001
GWSERV = sapgw00
Protocol = I

 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:

Table XCOM of the R/2 System:

Symbolic dest. LU (logical unit) TP (transaction prog.) Comm. type


R2R301 (gwhost) H

Table sideinfo for gwhost:

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

R/3 SAP gateway External program


ABAP/4

TCP/IP (remote) TCP/IP


shared Memory (local)
Table RFCDES (T01) Gateway options
RFC destination R3EXT Gateway host: hs5002
Connection type T
Program Path name Gateway service: sapgw01

Table TXCOM (T01)

Dest LU TP Prot Gateway host Gateway service

R3EXT hs5002 path name E hs5002 sapgw01

 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.

SAP gateway and target machine identical:

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

SAP gateway and target machine different:

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

n Windows NT supports the CPI-C and RFC interfaces.


n Under Windows NT, you can start an external program in either of the following ways:

1) Directly from the SAPgui.


Entry in TXCOM:

Dest LU TP Prot
R3FE Dummy Ext. prog. F

Entry in RFCDES with Transaction SM59:


Connection type: T
Program location: User
Program: /tmp/extpgm

2) From the SAP gateway.


Entry in TXCOM:

Dest LU TP Prot Gateway host Gateway


service
R3EX host name Ext. prog. E host name sapgwXX

Entry in RFCDES with Transaction SM59:


Connection type: T
Program location: Explicit
Target machine: Host name
Gateway options: Gateway host: Host name
Gateway service: sapgwXX
Program: /tmp/extpgm
R/3 à External Program (WfW , Windows 3.1)

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:

Dest LU TP Prot Gateway host Gateway


service
R3FE host name Ext. prog. E
n The external program is started from a remote SAP gateway:

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

IBM host AS400

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:

Dest LU TP Prot Gateway host Gateway


service
R3EX host name Ext. prog. C

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

External program SAP gateway

R/3
ABAP/4
TCP/IP

Side info of the external program

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:

Table "sideinfo" for external program and SAP gateway:

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)

Side info from gwhost

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

Gateway connection table (SAP system)


LU name TP name User Status Symb.dest Conv ID ...

hs1234 sapgw01 BC415-01 CONNECTED X50 12345678


hs2345 sapgw01 LOTZ CONNECTED X50 12345679
hs2345 sapgw01 TILLINGER CONNECTED X50 12345680
...

Gateway connection table (operating system)


No. CLIENT (LU/TP) USER STATE SDEST CONNID ...

000 hs1234 sapgw01 BC415-01 CONNECTED X50 12345678


001 hs2345 sapgw01 LOTZ CONNECTED X50 12345679
002 hs2345 sapgw01 TILLINGER CONNECTED X50 12345680
...

 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:

Displays a list of active CPIC connections


Displays a list of gateway work processes
Displays the parameters of a CPIC connection
Deletes CPIC connections
Displays memory occupancy
Displays memory contents
Manages gateway statistics
Resets the error counter
Displays gateway parameters and attributes
Provides a gateway trace facility
Security display and refresh
n In R/3, you can call the gateway monitor with the Transaction SMGW, or start it at operating system
level with the executable program gwmon. When you make the call, the system provides the name of the
profile file. With UNIX, for example, the procedure is as follows:

ps -ef | grep gw --> gwrd pf=/usr/sap/<SID>/SYS/profile/<SID_instance>


gwmon pf= /usr/sap/<SID>/SYS/profile/<SID_instance> .
Chapter 2 Summary

l The SAP gateway (CPI-C handler) is used for all


communications with SAP R/3 Systems.
l SAP side information tables are configuration tables
where you define the necessary connection parameters
for a communication.
l To implement a communication via Remote Function Call
(RFC), you make control entries in the appropriate tables
(RFCDES, RFCD).
l Communications are possible between R/3 Systems,
between R/3 and R/2 Systems, as well as between R/3
Systems and external programs.

 SAP AG
Chapter 3 Remote Function Call

l Synchronous RFC
l Asynchronous RFC
l Transactional RFC

 SAP AG
Chapter 3 Objectives

l How to communicate with other SAP or external


systems using RFC (Remote Function Call).
l Different RFC call variants.
l How to maintain table RFCDES for the various
linking options.
l Development tools for RFC programs.

 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

n RFC for R/2 systems is available from Release 5.0E.


n RFC for R/3 systems is available from Release 2.0.
n RFC is also supported for systems on which no SAP system is installed. For information on which
platforms SAP supports, please refer to the document SAP Supported Network Products. SAP provides
an RFC SDK (Software Development Kit) for these platforms (executable only in R/3 from Release
2.1).
RFC Features

Automatic data conversion

Automatic logon to the SAP partner system

Automatic conversion of all RFC data types

Automatic communication flow control

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

ABAP/4 function module ...


Import parameter Reference field Ref. type Proposal Optional Reference
f1 ...
Export parameter Reference field Ref. type Reference
f2 ...
Changing parameter Reference field Ref. type Proposal Optional Reference
f3 ...
Tables parameter Reference field Optional
t1 ...

ABAP/4 program ABAP/4 function module


...
CALL FUNCTION 'TEST' FUNCTION TEST.
EXPORTING ...
f1 = a1 The function
IMPORTING module is
ENDFUNCTION.
f2 = a2 executed locally
in the same
CHANGING R/3 System.
f3 = a3
TABLES
t1 = tab
 SAP AG

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

ABAP/4 program SAP system B


...
CALL FUNCTION 'FUNC' ABAP/4 function module

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

Remote Function Call supported

Update with immediate start


.
.
. Gener
ation
Import stub

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

Maintaining RFCDES with Transaction SM59

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

n You edit the table RFCDES with transaction SM59.


n The following connection types (partner system/program) are possible:

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
...

CALL FUNCTION 'B' FUNCTION B.


DESTINATION 'B'

...
...

CALL FUNCTION 'A'


FUNCTION A. DESTINATION 'BACK'
...

...
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

REPORT CUGE. FUNCTION RFC_CUSTOMER_GET.


PARAMETERS ... DATA ...
DATA ...
CALL FUNCTION SELECT * FROM KNA1 ...
'RFC_CUSTOMER_GET' ...
DESTINATION 'B'
... ENDFUNCTION.

...

 SAP AG

n Remote debugging is possible between two R/3 systems.


n If you run the calling program in debugging mode, the code of the remote function module is transported
to and displayed in the calling system. All the usual debugging options such as Single step and Execute
are also supported in the ABAP/4 code of the function module.
Asynchronous RFC: STARTING NEW TASK ...
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' ...
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 ...
...

FORM FUNC1_RETURN USING TASK. ENDFUNCTION.


...
RECEIVE RESULTS FROM FUNCTION FUNC1
IMPORTING ...
TABLES ...
EXCEPTIONS ...
...
SET USER-COMMAND '...'.
ENDFORM.
...

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.

2) Asynchronous RFC (STARTING NEW TASK ):

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:

--> suppress background job if communication error occurs


--> attempt to set up until system instructs otherwise
--> break between two attempts
tRFC Syntax

PROGRAM ASYN01.
.
.
.
CALL FUNCTION 'A'
DESTINATION '1'
IN BACKGROUND TASK
EXPORTING ...
TABLES ...
...

CALL FUNCTION 'B'


DESTINATION '1'
IN BACKGROUND TASK
EXPORTING ...
TABLES ...

COMMIT WORK.

 SAP AG

n In contrast to synchronous RFC, there is an additional parameter sequence called IN BACKGROUND


TASK
n All RFC calls which contain this sequence and the same DESTINATION are stored in the database
using COMMIT WORK. These RFC calls form a Logical Unit of Work (LUW). The function
modules are executed in the target system in the same sequence in which they are submitted in the source
system.
This means that, for each target system, the RFCs submitted in a LUW form a Logical Unit of Work.
n The called RFC-enabled function is executed once and only once.

Exactly Once!

This guarantees transaction integrity.


n You cannot specify IMPORTING parameters with CALL.
n External systems can benefit from the tRFC guarantee that a function module is executed once by using
the RFC API call RfcIndirectCall.
tRFC: Tables and Scheduling
ABAP/4 progam
CALL FUNCTION ... ARFCSSTATE
IN BACKGROUND TASK
EXPORTING ...
TABLES ... ARFCSDATA

CALL FUNCTION ...


IN BACKGROUND TASK
EXPORTING ...
TABLES ...
DB

COMMIT WORK.

Transaction Transactional RFC Log file


SM58
Caller FM Target system Date Time Status
PAUL xyz R3B 06.07.95 14.00 --
 SAP AG

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

R/3 System External system

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(...)
}
...

static RFC_RC rfcfunc(...)


...
Data processing
{ RfcGetData(...)

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.

In addition, RfcInstallFunction automatically declares the following standard library functions:

RFC_SYSTEM_INFO: Returns system information to the calling system.


RFC_DOCU: Documents which RFC functions can be called in the program.
RFC_PING: Checks that the communication path to the program is correct.
RFC_START_GUI: Starts SAPGUI on the frontend.
ARFC_DEST_SHIP,
ARFC_DEST_CONFIRM: Used internally with transactional RFC.

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

RFC Logon Manager ( VRFC )


Documentation (RFC generator etc.)

 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

l RFC generator generates C programs


w Client C program
w Server C program

l RFC generator generates Visual Basic programs


w Client Visual Basic program
w Server Visual Basic program

 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 C RFC program


MM
MM
PP
PP
SD

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 Visual Basic RFC program


MM
MM
PP
PP
SD

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

l RFC allows you to implement program-to-program


communication between R/3 systems, R/2 systems, and
external systems. In SAP systems, you set up the connection
with ABAP/4. For external programs, you use the relevant
RFC libraries.
l There are several RFC variants (synchronous, asynchronous,
and transactional).
l In R/3, you maintain connection parameters in the table
RFCDES.
l From R/3, you can generate external RFC programs.

 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:

1. Create a function group (see above) in a server system to be


specified by the instructor.

2. Program a function module assigned to this function group


(see above) and including the following functionality:
• Import parameter for the airline carrier
• Table parameter for selected records of table SCARR
• Exception for an invalid key evaluation
Use the following program fragment to allow generic
selection in table SCARR:
IF <import parameter> NE SPACE.
TRANSLATE <import parameter > USING '+_*%'.
ELSE.
<import parameter> = '%'.
ENDIF.
• Read the table SCARR and transfer the valid records to the
internal table.
3. Maintain a logical destination (see above) for an R/3-to-R/3
connection in the client system using Transaction SM59. The
target machine will be named by the instructor.

4. Write a report (see above) in the client system with the


following functionality:
• Parameter for airline carrier (generic entry possible)
Logical destination
Function module
• Call function module and pass relevant parameters
• Exception handling
• Output result data
Exercise 2 for Chapter 3
Report name: ZBCE##C2
Function module: TRAIN415_RFC_CALLTRANSACTION
Logical destination: BC415_##
##: group number
Realize a report to call function module
'TRAIN415_RFC_CALLTRANSACTION' using the transaction
created in the first exercise. The function module calls
transaction 'TFBA' to change customer data with modified
telephone numbers.
Proceed as follows:

1. Create the report (s.a.) in a R/3 system to be specified by the


instructor.

2. Use the customer number ( = group number), the telephone


number and the destination as report parameters.

3. Use the ‘A’ mode for the transaction to be called during the
function module call.

4. In the remote system, check which telephone data is


maintained for the customer with your group number. To do
so, use transaction TFBA in the remote R/3 System. Test your
report using another telephone number for the customer.
Exercise 3 for Chapter 3
Report name: ZBCE##C3
Function module: TRAIN415_RFC_CALLTRANSACTION
Logical destination: BC415_##
##: group number
Realize a report to call the above mentioned function module
which is to change customer data in your own system and in a
remote system using transactional RFCs.
Proceed as follows:

1. Copy the report ZBCE##C2 you have created in Exercise 2 to


report ZBCE##C3.

2. Modify the report in accordance with the description above,


that is, the function module is to be called in the own system
and in the remote system specifed by your own destination
using CALL FUNCTION ... IN BACKGROUND TASK. Use at
least the ‘N’ mode for the transactional RFC to execute
transaction TFBA in the background.

3. Use transaction SM58 to check scheduling and execution of


your function module call. If you can’t display any data, use
the explicit scheduling function module
START_OF_BACKGROUNDTASK in your program with a
later time.
Solution for Chapter 3
*&----------------------------------------------------------------
*
*& Report RS415031
*
*&
*
*&----------------------------------------------------------------
*
REPORT RS415031 .

PARAMETERS: CARRID LIKE SPFLI-CARRID,


DEST LIKE RFCDES-RFCDEST DEFAULT 'NONE',
RFC(30) DEFAULT 'TRAIN415_RFC_GET_CARRIER'.

DATA: CARRITAB LIKE SCARR OCCURS 0 WITH HEADER LINE,


MESS(80).

CALL FUNCTION RFC


DESTINATION DEST
EXPORTING
CARRID = CARRID
TABLES
CARRIER = CARRITAB
EXCEPTIONS
NO_CARRIER_FOUND = 1
COMMUNICATION_FAILURE = 2 MESSAGE MESS
SYSTEM_FAILURE = 3 MESSAGE MESS.

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.

SELECT * FROM SCARR INTO TABLE CARRIER


WHERE CARRID LIKE CARRID.

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.

PARAMETERS: CUSTID LIKE SCUSTOM-ID,


PHONE LIKE SCUSTOM-TELEPHONE,
DEST LIKE RFCDES-RFCDEST DEFAULT 'NONE'.

DATA: CUSTITAB LIKE CUST415 OCCURS 0 WITH HEADER LINE,


TAMESS LIKE T100 OCCURS 0 WITH HEADER LINE,
SYS LIKE SY-SYSID,
MESS(80).

CUSTITAB-TELEPHONE = PHONE.
CUSTITAB-ID = CUSTID.
APPEND CUSTITAB.

CALL FUNCTION 'TRAIN415_RFC_CALLTRANSACTION'


DESTINATION DEST
EXPORTING
TAMODE = 'A'
IMPORTING
SYSID = SYS
TABLES
CUSTTAB = CUSTITAB
MESSTABLE = TAMESS
EXCEPTIONS
COMMUNICATION_FAILURE = 1 MESSAGE MESS
SYSTEM_FAILURE = 2 MESSAGE MESS.
CASE SY-SUBRC.
WHEN 1.
WRITE: / MESS.
EXIT.
WHEN 2.
WRITE: / MESS.
EXIT.
WHEN OTHERS.
LOOP AT TAMESS.
WRITE: / TAMESS.
ENDLOOP.
ENDCASE.
Solution 3 for Chapter 3
*&----------------------------------------------------------------
*
*& Report RS415033
*
*&
*
*&----------------------------------------------------------------
*
REPORT RS415033 .

PARAMETERS: CUSTID LIKE SCUSTOM-ID,


PHONE LIKE SCUSTOM-TELEPHONE,
DEST LIKE RFCDES-RFCDEST DEFAULT 'NONE',
TIME LIKE SY-UZEIT DEFAULT SY-UZEIT.

DATA: CUSTITAB LIKE CUST415 OCCURS 0 WITH HEADER LINE,


TAMESS LIKE T100 OCCURS 0 WITH HEADER LINE,
SYS LIKE SY-SYSID,
MESS(80).

CUSTITAB-TELEPHONE = PHONE.
CUSTITAB-ID = CUSTID.
APPEND CUSTITAB.

CALL FUNCTION 'TRAIN415_RFC_CALLTRANSACTION'


IN BACKGROUND TASK
DESTINATION DEST
EXPORTING
TAMODE = 'N'
TABLES
CUSTTAB = CUSTITAB.

CALL FUNCTION 'START_OF_BACKGROUNDTASK'


EXPORTING
STARTDATE = SY-DATUM
STARTTIME = TIME
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC <> 0.
WRITE: / 'Error.'.
ENDIF.

CALL FUNCTION 'TRAIN415_RFC_CALLTRANSACTION'


EXPORTING
TAMODE = 'A'
TABLES
CUSTTAB = CUSTITAB.

IF SY-SUBRC <> 0.
EXIT.
ELSE.
COMMIT WORK.
ENDIF.
Chapter 4 ABAP/4 Desktop Integration
Components

l Introduction to desktop integration


l Basic principles of OLE 2.0
l Architecture of ABAP/4 desktop integration
components

 SAP AG
Chapter 4 Objectives

l Central terms and components in SAP desktop


integration.
l Basic techniques for handling SAP RFC objects in
the context of Object Linking and Embedding (OLE)
Automation.

 SAP AG
Why Desktop Integration?

l Development of user-specific frontend applications.


l Development of solutions for communication with other
machines and integration with R/3 using Visual Basic or C.
l Analysis and processing of data with Excel within an R/3
transaction.
l Use of MS Word or Word Perfect as R/3 word processing
program.

 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

l Based on standards (TCP/IP, CPI-C, OLE 2.0).


l Similar handling in different operating systems (RFCs in
Windows 3.1, Windows NT, Windows95, Unix, OS/2).
l Allow developers to use their "own" programming language
(Visual Basic, C, C++).
l OLE objects and the RFC development environment conceal
the underlying complexity.

 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.

Expenses - Sales conference


Description Amount
Flight $1.200
Hotel $350
Entertainm e n t $150
Meals $200
Overall total $1.900

 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 Allows an application to control the behavior of another


application in an object-oriented manner.

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

Excel Third-party Word Project


objects objects objects objects
Office components

 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

Application server Workstation

ABAP/4 program SAPGUI


C
RF
actual OLE
Control
statements for
program-specific OLE2-capable
objects application

 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

l Facilitates the communication between application server


and frontend via the RFC interface.
l SpeciaI functions for OLE are implemented in the SAPGUI.
l Collected calls
n When the ABAP/4 processor encounters the first non-OLE
statement, OLE 2.0 commands are sent to SAPGUI.
l Language independence
n The ABAP/4 processor uses the OLE object ID instead of the
text names for properties and methods.

 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

l Maintenance Transaction SOLE for all desktop applications


that can be controlled from ABAP/4.
l Automatic identification of desktop objects:
R/3 report RSOLEINT (Transaction SOLI)
w reads the OLE object register on the desktop
w loads objects, methods and properties into R/3
l Object Browser:
R/3 report RSOLETI1 (Transaction SOLO)
w Browser for OLE objects, properties and methods
l Special OLE include for ABAP/4 programs
OLE2INCL

 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

Five new ABAP/4 statements:


DATA: object TYPE OLE2_OBJECT.
w CREATE OBJECT object class

w GET PROPERTY OF object property = field

w SET PROPERTY OF object property = field

w CALL METHOD OF object method


§ EXPORTING prop1 = field1 ... propN = fieldN

w FREE OBJECT object

 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.

DATA: EXCEL TYPE OLE2_OBJECT.


DATA: BOOKS TYPE OLE2_OBJECT.
DATA: CELL TYPE OLE2_OBJECT.
DATA: FILENAME(50) = 'C:\TEMP\OLE1.XLS'.
DATA: VALUE(10).

CREATE OBJECT EXCEL 'EXCEL.APPLICATION'.


SET PROPERTY OF EXCEL 'VISIBLE' = 1.
CALL METHOD OF EXCEL 'WORKBOOKS' = BOOKS.
CALL METHOD OF BOOKS 'OPEN' EXPORTING #1 = FILENAME #2 = 1.
GET PROPERTY OF EXCEL 'ACTIVECELL' = CELL.
GET PROPERTY OF CELL 'VALUE' = VALUE.
WRITE: / 'Value:', VALUE.
CALL METHOD OF EXCEL 'QUIT'.

FREE OBJECT CELL.


FREE OBJECT BOOKS.
FREE OBJECT EXCEL.

 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

The Automation server has two service levels:


n A local server for client applications that access SAP functions
n The Automation Assistant (a graphical tool that allows the user
to execute functions and transactions online).

SAP Automation Assistant

Function Import Export Table

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

With "server object"


Server collection
Set RFCServer = CreateObject ("RFC.ServerObject")

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

Logon using the method "Logon"


Set RFCConnection = RFCServer.Connection
If RFCConnection.Logon <> True Then
RFCServer.Application.Quit Application
Exit
End If Server collection

ODER
Server

Logon using the method "Open"


RFCConnection.User= “U ser1”
Connection
RFCConnection.System= “D 22”
...
RFCConnection.Open

 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)

With an R/3 function module as Application


"dynamic" method of the server object

RESULT = RFCServer.R3FunctionName( Server collection

EXCEPTIONSTR,
PARAM1:= LocParam1, Server
PARAM2:= LocParam2,
PARAM3:= LocParam3)
Function collection

l Import and export parameters assigned


as "specified arguments" Function
l OLE client application MUST support
conventions for specified arguments
Imports coll. Exports coll.
l Syntax for VB for application code
Parameter

 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)

Create function object that represents the Application


R/3 function module
Server collection
Set RFCFunction =
RFCServer.Functions.Add(“R3FunctionName ”)
Server

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)

Define values for export objects and use Application


"Call" method for function object

Set FunctionExports = RFCFunction.Exports Server collection

FunctionExports.Item( “P ARAM1 ”) = LocParam1


Server
FunctionExports.Item( “P ARAM2 ”) = LocParam2
Result = RFCFunction.Call Function collection

Set local variable to import object to get result Function


of function call
Set LocParam3 = FunctionImports.Item("PARAM3") Imports coll. Exports coll.

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)

Working with the table resulting from a function call

Access table object with Tables Collection


Set TablesColl = RFCFunction.Tables Function
Set TableObj = TablesColl.Item(“R3TableName ”)

Access table data with Rows Collection


Tables coll.

For Each TableRow In TableObj.Rows


Table
Cells(RowIndex, 1) = TableRow(“R3ColName1 ”)
Cells(RowIndex, 2) = TableRow(“R3ColName2 ”)
....
RowIndex=RowIndex+1 Rows coll.

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)

Working with the table resulting from a function call:

Access table data with table object "Cell"


For x = 1 to TableObj.RowCount
Cells(RowIndex, 1) = TableObj.Cell(x, “R 3ColName1 ”)
Cells(RowIndex, 2) = TableObj.Cell(x, “R 3ColName2 ”)
....
Next x

With multiple calls to a function, reset the contents with


the method "FreeTable"

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)

Creating a table object for entry in a function call

Using a function as a dynamic method of the server object

Set TableObj = RFCServer.CreateTable(“R3Tabellenname ”)

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)

Creating a table object for entry in a function call

Using a function that was explicitly added to the collection

Set RFCFunction = RFCServer.Functions.Add(“R3FunctionName ”)


Set TablesColl = RFCFunction.Tables
Set TableObj = TablesColl.Item(“R3TableName ”)

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:

1. Use the Transaction 'SOLI' to view the OLE-related objects in


your R/3 System.

2. Copy the main report RS415047 to your report ZBCE28#D1.


In your program, comment mark the locations where you have
to insert the OLE-specific ABAP/4 key words.

3. Execute the modified report. At the end, it will be necessary to


make an active switch from R/3 to the Excel application.

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.

PARAMETERS: DISCOUNT(3) TYPE N.

*
* 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

l The CPI-C interface and the individual CPI-C calls.


l Basic for programming CPI-C in ABAP/4 and in C.

 SAP AG
CPI-C Implementation

R/3

ABAP/4

R/2 External External


CPI-C libraries CPI-C libraries
ABAP/4 (SAP) (external)

 SAP AG

n CPI-C implementation by SAP:

- R/3 ABAP/4 interface


- R/2 ABAP/4 interface
- External systems CPI-C libraries
cpictlib TCP/IP protocol
cpicslib LU6.2 protocol, APPC
For the currently supported platforms, see the document
"SAP Supported Network Products".

n CPI-C implementation according to X/OPEN Standard

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

Set up connection Accept connection

Send data Receive data

Receive data Send data

Send data Receive data

Close connection Close connection

 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 ...

ABC LU1 CP1C2

R/3: TXCOM XCOM


Dest LU TP Prot ...

ABC LU2 CPIC2 E

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:

- In R/2, the table is XCOM (maintained with Transaction TM31).


- In R/3, the table is TXCOM (maintained with Transaction SM54 or SM31)
- In external systems, the table is always called sideinfo. Under UNIX, you can maintain sideinfo with
the
editor program “vi”
Available CPI-C Functionality

ABAP/4 Function libraries ( SAP )

CPI-C starter set calls CPI-C starter set calls

CPI-C advanced function calls (subset)

CPI-C SAP-specific functions

 SAP AG

n The CPI-C starter set is implemented in ABAP/4 (key word COMMUNICATION).


n SAP provides a number of functions for developing external CPI-C programs (also known as remote
CPI-C) on SAP-supported platforms.
n These functions can be divided into three groups:

CPI-C starter set calls:

This group contains CPI-C starter set calls.

CPI-C advanced function calls:

This group contains a subset of the X/Open advanced function calls.

CPI-C SAP-specific calls:

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

COMMUNICATION INIT ...

COMMUNICATION ALLOCATE ...

COMMUNICATION ACCEPT ...

COMMUNICATION SEND ...

COMMUNICATION RECEIVE ...

COMMUNICATION DEALLOCATE ...

 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

CPI-C starter set calls CMINIT Initialize connection


CMALLC Set up connection
CMACCP Accept connection
CMRCV Receive data
CMSEND Send data
CMDEAL Close connection

CPI-C advanced function calls CMSPLN


(subset) CMSTPN
...

CPI-C SAP-specific functions SAP_CMINIT


SAP_CMLOGON
...

 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:

CMINIT Initialize_Conversation Define communication parameters


CMALLC Allocate_Conversation Set up conversation
CMACCP Accept_Conversation Accept conversation
CMSEND Send Send data
CMRCV Receive Receive data
CMDEAL Deallocate_Conversation Close conversation
Standard Includes (Data Definitions)

ABAP/4 C
REPORT
REPORTXYZ.
XYZ. ...
...
...

INCLUDE RSCPICDF. #include <cpic.h>


INCLUDE RSEBCASC.
oder
...
...

#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: DEST C 8 C: dest PCPIC_CHAR


CONVID C 8 convid PCONVERSATION_ID
RC X 2 rc CM_RETCODE

(Examples: ABAP/4: --> DATA: DEST(8) TYPE C.


C: --> PCPIC_CHAR dest = (PCPIC_CHAR)0;)
n For C data types, you should note the following:

& --> is an address operator and returns a pointer to an object


* --> is a reference operator and returns the address of an object
n Legend: Italics --> denote a variable
Underlined characters --> input variable which must be specified during the call
[ ... ] --> optional specification
Setting Up Connections Actively (ALLOCATE)

ABAP/4 C
...
...

COMMUNICATION
COMMUNICATION ...
ALLOCATE
ALLOCATE
IDIDconvid
convid CMALLC (
[ [RETURNCODE
RETURNCODE rc
rc] ] convid,
&rc );
...
...
...

 SAP AG

n The connection is set up physically to a partner program.


n convid: The value returned by INIT must be specified here.
n You must assign appropriate types and lengths to variables:

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.

return_code: = 0 (CM_OK): Routine executed without error


= error code: An error has occurred
Sending Data (SEND)

ABAP/4 C

... ...

COMMUNICATION SEND CMSEND (


ID convid convid,
BUFFER output output,
[ LENGTH send_length ] &send_length,
[ RETURNCODE rc ] &request_to_send_received,
&rc );
...
...

 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 ... ...

COMMUNICATION RECEIVE CMRCV (


ID convid convid,
BUFFER input input,
[ LENGTH req_length ] &requested_length,
&received_length,
[ RECEIVED rec_length ]
&data_info,
DATAINFO datainfo
&status_info,
STATUSINFO statusinfo
&request_to_send_received,
[ HOLD ]
&rc );
[ RETURNCODE rc ]
... ...

 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:

- CM_NO_STATUS_RECEIVED --> Send direction not switched


- CM_SEND_RECEIVED --> Connection partner surrenders send rights
n If the status information is set to CM_SEND_RECEIVED, the current program has the status SEND.
n The data information returns details about the flow control. The different statuses are as follows:

- CM_NO_DATA_RECEIVED --> No data received


- CM_COMPLETE_DATA_RECEIVED --> All data received
- CM_INCOMPLETE_DATA_RECEIVED --> Not all available data received
Closing Connections (DEALLOCATE)

ABAP/4 C

... ...

COMMUNICATION DEALLOCATE CMDEAL (


ID convid convid,
[ RETURNCODE rc ] &rc );
...
...

 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:

CONVID C 8 convid PCONVERSATION_ID


RC X 2 rc CM_RETCODE
CPI-C Return Codes
ABAP/4: Include report RSCPICDF
DATA: INT2(2) TYPE X.
...
* return code
DATA: CM_OK LIKE INT2 VALUE '0000'.
...
DATA: CM_DEALLOCATED_NORMAL LIKE INT2 VALUE '0012',
DATA: CM_PARAMETER_ERROR LIKE INT2 VALUE '0013',
...

C: Header file cpic.h


typedef
typedef int
int CM_RETCODE;
CM_RETCODE;
......
##returncode
returncode
#define
#defineCM_OK
CM_OK 00
......
#define
#defineCM_DEALLOCATED_NORMAL
CM_DEALLOCATED_NORMAL 18
18
#define
#defineCM_PARAMETER_ERROR
CM_PARAMETER_ERROR 19
19
......

 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

CMSPLN() Sets the partner LU


CMSTPN() Sets the partner transaction program

CMCNVO() Data conversion from ASCII to EBCDIC


CMCNVI() Data conversion from EBCDIC to ASCII

CMFLUS() Immediate transfer of network buffer data


to the partner program

...

 SAP AG

n CPI-C advanced function calls:

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_CMINIT() Specifies SAP gateway (active program)


SAP_CMACCP() Specifies SAP gateway (passive program)

SAP_CMLOGON() Connect string for logon to R/2 or R/3

SAP_CMCERR() Error handling


SAP_CMPERR()

SAP_CMLOADCONVTAB() Data conversion


SAP_CMMODCONVTAB()

...

 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:

R/2: X1SA R/3: sapgwxx


n You must make an appropriate entry in the side information table of the system setting up the
communication.
ABAP/4 Program as Server

REPORT RSCPICSV.
...

FORM FORM1.
...
COMMUNICATION ACCEPT
...
COMMUNICATION RECEIVE
...
ENDFORM.

 SAP AG

n In an ABAP/4 server program, the communication is made in a subroutine (FORM).


n The FORM routine executes an ACCEPT call and then has the status allowing it to receive data.
n The FORM routine can set up further communications as required.
n An ABAP/4 program can contain several subroutines for communication purposes and then call them in
various sequences.
Data Conversion

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:

TRANSLATE field USING ASC_TO_EBC.


TRANSLATE field USING EBC_TO_ASC.
TRANSLATE field FROM CODE PAGE abc
TO CODE PAGE xyz.

C:

CMCNVO ( output, &send_length, &rc );


CMCNVI ( input, &received_length, &rc);
SAP_CMLOADCONVTAB()
SAP_CMMODCONVTAB()

 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

Type Messages from the SAP System


Request ID: APPC, FREE

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'. ......
.
..

CPICCONN-MODN = 'FORM1'. "ABAPPROG",


"ABAPPROG",
"FORM1"
"FORM1" ););
TRANSLATE CPICCONN USING ASC_TO_EBC.
COMMUNICATION SEND ... CMSEND
BUFFER CPICCONN ... CMSEND( (convid,
convid,output,
output,......););
CMRCV
CMRCV ( (convid,
convid,input,
input,...
... ););
COMMUNICATION RECEIVE ...
BUFFER CPICCONN ... ...
...
TRANSLATE CPICCONN USING EBC_TO_ASC.
...

 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

l ABAP/4 Development Workbench


l The SAP CPI-C Software Development Kit (SDK)

 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:

cpicsdk - bin Executable programs


- lib Libraries
- include Header files
- text Source files, help text
SAP CPI-C Programs

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

[1]: ccpict1t -dest R3 -abap -usr ABC -pwd XYZ

 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

n Debugging: Program code, tables, breakpoints, ...


n You can evaluate the system log with Transaction SM21.
n Trace files are generated by external CPI-C programs. You can set the trace level with the environment
variable CPIC_TRACE.
n You start the gateway monitor under UNIX as follows:

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

l SAP provides CPI-C functionality both in ABAP/4


(starter set) and also in libraries for external programs
(starter set, advanced function calls, SAP-specific
functions).
l When communicating with an ABAP/4 server program,
the client program must first logon to the SAP Basis
System.
l In the ABAP/4 server program, a FORM routine is
responsible for communication.
l Data conversions may have to be performed.
l There are programs for performing connection tests with
partner systems.

 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:

1. Create your CPIC destination with Transaction SM54 in R/3


for a server system to be specified by the instructor.

2. Copy the main report RS415057 to your report ZBCE##E1. In


your program, you must fill the places flagged with the
comment *Ad ... . From this active program, you should call
the FORM routine SEND in your passive program ZBCE##E2
which you must also create.

3. Now switch to the specified R/3 server system. There, copy


the main report RD415058 to your report ZBCE##E2. In your
program, you must fill the places flagged with the comment
*Add ... .

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.

PARAMETERS: DEST(8) DEFAULT 'BC415TIL'.


PARAMETERS: CARRID LIKE SPFLI-CARRID DEFAULT 'LH'.

DATA: SBUFFER(5) VALUE 'OK'.


DATA BEGIN OF ISPFLI OCCURS 1.
INCLUDE STRUCTURE SPFLI.
DATA END OF ISPFLI.
DATA: RBUFFER(255).
DATA: DUMMY.

DATA: CONVID(8), "Coversation ID


DI(4) TYPE X, "Data information
SI(4) TYPE X, "Status information
RL(4) TYPE X, "Receive length
CPIC_RC LIKE SY-SUBRC. "Return code
*----------------------------------------------------------------*
* Data for SAP logon *
*----------------------------------------------------------------*
CPICCONN-REQID = 'CONN'. "Request ID
CPICCONN-REQTYPE = 'CPIC'. "Type
CPICCONN-AMODE = '1'. "Mode number
CPICCONN-IMODE = ' '.
CPICCONN-FILL1 = ' '.
CPICCONN-MAND = '000'. "Client
CPICCONN-NAME = 'SAPCPIC'. "User
CPICCONN-CODE = 'ADMIN'. "Password
CPICCONN-LANG = SY-LANGU. "Language
CPICCONN-KORR = ' '. "not used
CPICCONN-PROG = 'RS415052'. "Partner program
CPICCONN-MODN = 'SEND'. "FORM routine

*----------------------------------------------------------------*
* 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.

TRANSLATE CPICCONN USING EBC_TO_ASC.

WRITE: / 'LOGON-DATA'(001), 20 CPICCONN.


IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
*----------------------------------------------------------------*
* CPI-C: CM_RECEIVE Response to SAP logon *
*----------------------------------------------------------------*
SKIP 1.
FORMAT COLOR 1.
WRITE: / 'CM_RCV Response to logon'.
COMMUNICATION RECEIVE ID CONVID BUFFER RBUFFER RETURNCODE CPIC_RC
DATAINFO DI
STATUSINFO SI
RECEIVED RL.
FORMAT COLOR 2.
WRITE: / 'RC:', CPIC_RC.
TRANSLATE RBUFFER USING EBC_TO_ASC.
WRITE: / 'RESPONSE TO LOGON:'(002), RBUFFER(40).
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
*----------------------------------------------------------------*
* Send parameter for selection *
*----------------------------------------------------------------*
FORMAT COLOR 1.
WRITE: / 'CM_SEND'.
*----------------------------------------------------------------*
* CPI-C: CM_SEND Send CARRID to partner program *
*----------------------------------------------------------------*
COMMUNICATION SEND ID CONVID BUFFER CARRID RETURNCODE CPIC_RC.
FORMAT COLOR 2.
WRITE: / 'RC:', CPIC_RC.
*
WHILE CPIC_RC = CM_OK.
FORMAT COLOR 1.
WRITE: / 'CM_RCV'.
*----------------------------------------------------------------*
* CPI-C: CM_RCV Receive data from sending partner program *
*----------------------------------------------------------------*
COMMUNICATION RECEIVE ID CONVID BUFFER ISPFLI RETURNCODE CPIC_RC
DATAINFO DI
STATUSINFO SI
RECEIVED RL.
FORMAT COLOR 2.
WRITE: / 'RC:', CPIC_RC.
WRITE: / 'DI:', DI.
WRITE: / 'SI:', SI.
APPEND ISPFLI.
ENDWHILE.

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.

DATA: CONVID(8), "Coversation ID


DI(4) TYPE X, "Data information
SI(4) TYPE X, "Status information
RL(4) TYPE X, "Receive length
CPIC_RC LIKE SY-SUBRC. "Return code

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

R/3 application server Frontend platform

RFC TCP/IP ( WInSock )


TCP/IP port
gateway

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

l Currently, there Behavior


are about 160 Restrictions
core business Rules Methods
objects Events
 SAP AG

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

Win32 Application server

R/3 Object Broker


OCX RF
C
OLE Auto-
mation

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

n The above object hierarchy shows the available OLE objects.


n The factory object controls the connection to the R/3-System. It is also required to generate business
objects and collections of business objects.
n The business collection object contains the individual business objects.
n Business objects are local instances of R/3 business objects. As soon as an object is generated on the
desktop, the methods and properties of the relevant R/3 business object are made available for further
processing. For this reason, the business objects learn about the interfaces only at runtime.
n For more information on available object methods and object properties, please refer to the online
documentation.
Outlook: Working with Business Objects

Example of processing SAP business objects

Set oBOF = CreateObject("SAP.BusinessObjectFactory")

blnLogged = oBOF.Logon

Set boWhoAmI = oBOF.GetSAPObject("USR01", "MUELLER")


...

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

Application Development in the


ABAP/4 Development Workbench
Week 4

 SAP AG
Contents II / Week 4

Chapter 1 Sequential Files Chapter 4 General Information about


Application-specific Batch
Chapter 2 Introduction to Batch Input Input Programs
Processing
Chapter 5 CALL TRANSACTION
Chapter 3 Special Features of Batch
Input Processing Chapter 6 Local Files

Exercises
Solutions

 SAP AG
Chapter 1 Sequential Files

l The Purpose of Sequential Files.


l Opening, Processing and Closing Files.
l Processing Files with Different Formats.

 SAP AG
Chapter 1 Objectives

l The possible uses of sequential files.


l How to process sequential files and the steps
involved.
l How to process a sequential file containing different
record types.

 SAP AG
Overview

R/3
R/3

ABAP/4 program

TRANSFER READ DATASET

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

n You can choose to open a file in binary mode or in text mode.


n Possible options:
IN BINARY MODE

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

READ DATASET READ DATASET


ABAP/4
ABAP/4 ABAP/4
ABAP/4
program
program A B C program
program A B C
A B A A B
B C D A B C

 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

n The following additions exist for the OPEN statement:


AT POSITION <position>

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

TRANSFER <field> TO <file name>.

Sequential
file
data
record

 SAP AG

n Each TRANSFER statement transfers one data record to a sequential file.


n Before TRANSFER, you place the data record in a field or a structure.
n Possible structures are field strings or table work areas.
n The execution of the TRANSFER statement depends on the mode:

- Binary mode: Writes the length of the field or structure.


- Text mode: Writes a line.
n If the specified file is not open, the TRANSFER statement tries to open the file <file name> FOR
OUTPUT (IN BINARY MODE) or using the additions of the last OPEN DATASET statement for this
file.
n Errors which occur during the TRANSFER statement result in program termination.
n The additional parameter LENGTH <length> of the TRANSFER statement allows you to specify a
length in bytes (in the format TRANSFER <structure> TO <file name> LENGTH <length>). In this
case, the exact number of characters specified in <length> is transferred. If the structure is shorter, the
record is padded (with blanks in text mode and hexadecimal zeros in binary mode). If the structure is
longer, the record is truncated.
Reading Data Records

READ DATASET <file name>INTO <field>.

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:

- Binary mode: Reads the length of the structure.


- Text mode: Reads a line.
n If the specified file is not open, READ DATASET tries to open the file (IN BINARY MODE FOR
INPUT or with the options of the last OPEN DATASET statement for this file).
n If the end of the file is reached, SY-SUBRC is set to 4. Otherwise it is set to 0. If the file cannot be
opened, SY-SUBRC contains the value 8. Errors result in program termination.
n READ DATASET, like TRANSFER, does not perform conversions implicitly. The data is read in as it
was written.
n The additional parameter LENGTH <length> of the READ DATASET statement allows you to specify
a length in bytes (in the format READ DATASET <file name> INTO <structure> LENGTH <length>).
In this case, the exact number of characters specified in <length> is read from the data record into the
structure. If the structure is shorter, the record is padded (with blanks in text mode and with
hexadecimal zeros in binary mode). If the structure is longer, the record is truncated.
Closing/Deleting a Sequential File

CLOSE DATASET <file name>.

DELETE DATASET <file name>.

 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.

WRITE: / REC-CARRID, REC-CONNID,


/ REC-FLDATE, REC-PLANETYPE.
ULINE.

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.

Table structure SBC420A


Dict.
--------------------------------------------------------------------
Name Type Length Meaning
--------------------------------------------------------------------
SBC420A-CARRID CHAR 03 Short description of airline company
SBC420A-CONNID NUMC 04 Code for flight connection
SBC420A-FLDATE DATS 08 Flight date
SBC420A-PLANETYPE CHAR 10 Aircraft type

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.

PARAMETERS FILE(20) DEFAULT


'/tmp/RSFFF01A' LOWER CASE.

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

Fill structure Read data record

Transfer structure Process data record

More data End of


Yes records? file? No

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

l The simplest method of organizing data is through sequential files. In


particular, they provide a convenient way of exchanging data between
systems. The TRANSFER command writes data (record by record) to a
directory on the application server; you specify the path using the notation
appropriate for the operating system. The READ DATASET command allows
the target system to read in the data and you can then continue processing it
if required. You open and close sequential files in the appropriate mode for
whatever processing is required.

 SAP AG
Exercises on Chapter 1: Sequential Files

1. Your program name: ZBCF##A1


Your group number: ##
Your directory name: /tmp
Your file name: BOOK##
Name of the include report: RSFFF01L.

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.

2. Your program name: ZBCF##A2


Your group number: ##
Your directory name: /tmp
Your file name: BOOK##
Name of the include report: RSFFF01L

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 .

* Record for sequential file defined as Dictionary structure or

* include report provided

DATA: BEGIN OF REC.

INCLUDE STRUCTURE SBC420C.

DATA: END OF REC.

* STRUCTURE SBC420C:

* CARRID, CONNID, FLDATE, BOOKID, CUSTOMID.

* Alternative:

* INCLUDE RSFFF01L.

* Create selection screen (manual data input)

PARAMETERS:

FILE(20) DEFAULT '/tmp/BOOKXX' LOWER CASE,

CARRID LIKE SFLIGHT-CARRID DEFAULT 'BA',

CONNID LIKE SFLIGHT-CONNID DEFAULT '0001',

FLDATE LIKE SFLIGHT-FLDATE DEFAULT '19960401',

BOOKID LIKE SBOOK-BOOKID DEFAULT '00000001',

CUSTOMID LIKE SBOOK-CUSTOMID DEFAULT '00000001'.

* Open file for appending in text mode

START-OF-SELECTION.

OPEN DATASET FILE FOR APPENDING IN TEXT MODE.

* Transfer data from selection screen to field string


MOVE: CARRID TO REC-CARRID,

CONNID TO REC-CONNID,

FLDATE TO REC-FLDATE,

BOOKID TO REC-BOOKID,

CUSTOMID TO REC-CUSTOMID.

* Write field string to sequential file

TRANSFER REC TO FILE.

* List output

WRITE: / REC-CARRID,

/ REC-CONNID,

/ REC-FLDATE,

/ REC-BOOKID,

/ REC-CUSTOMID.

ULINE. SKIP.

*D TEXT-001: 'Transfer data record to file:'

WRITE: / TEXT-001, FILE.

* Close the sequential file

CLOSE DATASET FILE.


Model Solution 2 for Chapter 1: Sequential Files
REPORT RSFFF012.

* Record for sequential dataset defined as Dictionary structure or

* include report provided

DATA: BEGIN OF REC.

INCLUDE STRUCTURE SBC420C.

DATA: END OF REC.

* STRUCTURE SBC420C:

* CARRID, CONNID, FLDATE, BOOKID, CUSTOMID.

* Alternative:

* INCLUDE RSFFF01L.

DATA: COUNT LIKE SY-INDEX.

* Create selection screen

PARAMETERS:

FILE(20) DEFAULT '/tmp/BOOKXX' LOWER CASE.

* Open file for reading in text mode

START-OF-SELECTION.

OPEN DATASET FILE FOR INPUT IN TEXT MODE.

DO.

READ DATASET FILE INTO REC.

* Termination condition for reading

IF SY-SUBRC NE 0.
COUNT = SY-INDEX - 1.

EXIT.

ENDIF.

* List output

WRITE: / 'Satz:', SY-INDEX,

/ REC-CARRID,

/ REC-CONNID,

/ REC-FLDATE,

/ REC-BOOKID,

/ REC-CUSTOMID USING NO EDIT MASK.

ULINE.

ENDDO.

SKIP.

*D TEXT-001: 'Data records read from file:'

WRITE: / COUNT, TEXT-001, FILE.

* Close the sequential file

CLOSE DATASET FILE.


Chapter 2 Introduction to Batch Input Processing

l Overview of Batch Input


l Programming techniques for creating batch input
sessions
l Transaction SM35: Batch input administration
transaction

 SAP AG
Chapter 2 Objectives

l The uses of batch input processing.


l Programming technique for creating batch input sessions.
l Processing batch input sessions and administration options.

 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 system (host)

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

n Data is transferred to the queue file by batch input programs.


n These programs perform the following functions:
Ÿ They provide structured work areas in the form of an internal table (BDC table) for the data to be
transferred.
Ÿ They read in the data.
Ÿ They place the data in the BDC table.
Ÿ They transfer the filled BDC table to the queue file.
n The BDC table receives the input for the data transfer transactions.
Batch Input Queue File

Screens Queue SAP


database
file

Batch
Batch input
input

Transaction 1 Transaction 2

Screen 1 Screen 2 Screen 1 Screen 2


Log
file

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

n Every batch input session must be opened and closed.


n The data for the application functions (transactions) is inserted in the batch input session.
n A batch input program can generate several consecutive batch input sessions. Parallel generation is not
possible.
Function Modules for Batch Input Program

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’

EXPORTING TCODE = <transaction code>

TABLES DYNPROTAB = <BDC table>

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

<program name> <number 1> x


<field 11> <value 11>
<field 12> <value 12>
... ...
<program name> <number 2> x
<field 21> <value 21>
<field 22> <value 22>
... ...
... ...

 SAP AG

n The BDC table holds the data for one transaction.


n The contents of the BDC table are then passed to the queue file.
n One table line includes the following information:
Program name, screen number, start ID, field name, field value.
n The start ID 'X' is always at the beginning of a new screen. The input values are now entered for each
field in the table for this screen.
n For reasons of clarity, a table line should only include either program name, screen number and start ID
or field name and field value (as above). In principle, however, all information can be included in a line.
n Only the field names of fields to be changed explicitly are included.
Defining the BDC Table

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>.
...

CLEAR <BDC table>.


MOVE: <program name> TO <BDC table>-PROGRAM,
<number2> TO <BDC table>-DYNPRO,
'X' TO <BDC table>-DYNBEGIN.
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)

Change cust. data

Customer number 1

Cust. name Meier


Postal code 6900
City Heidelberg
G/P cust. B
Discount [%] 10
Tel. no. 06221/66666

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

n First perform (step by step) the application function to be simulated.


n Make a note of:
- the program name and screen number for each screen
- the field and table name for every entry or cursor positioning
- the number for each function key pressed
- the screen program sequence
n To do this, you use the system function Status and the Technical info help function.
Preparations for BDC Program - Screen Painter
Screen
Screen Painter
Painter

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'.

DATA:BEGIN OF BDC_TAB OCCURS 5.


INCLUDE STRUCTURE BDCDATA.
DATA: END OF BDC_TAB.

 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.

CALL FUNCTION 'BDC_OPEN_GROUP'


EXPORTING CLIENT = SY-MANDT
GROUP = NAME
USER = 'BC420BDC'
KEEP = 'X'

PERFORM GENERATE_BDC_DATA.

CALL FUNCTION 'BDC_INSERT'


EXPORTING TCODE = 'TFBA'
TABLES DYNPROTAB = BDC_TAB.

CALL FUNCTION 'BDC_CLOSE_GROUP'.

WRITE: / 'End BDC session creation',


SY-MANDT, NAME, SY-UZEIT.

 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

n On the second screen of Transaction TFBA, the fields 'SCUSTOM-CUSTTYPE', 'SCUSTOM-


DISCOUNT' and 'SCUSTOM-TELEPHONE' are also transferred.
n Finally, the OK code must be passed (choose Customer data -> Save). 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') .
Alternatively, you can use the function code assigned to this function code.
n When you choose Save, the data is updated. This completes batch input processing for this transaction.
Generating a Sequential File for BDC Program 1
REPORT RSFFF02B.
TABLES SCUSTOM.
DATA: BEGIN OF REC,
ID LIKE SCUSTOM-ID,
POSTCODE LIKE SCUSTOM-POSTCODE,
CUSTTYPE LIKE SCUSTOM-CUSTTYPE,
END OF REC.

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.

TRANSFER REC TO FILE.

WRITE: / REC-ID, REC-POSTCODE, REC-CUSTTYPE.


ENDSELECT.

END-OF-SELECTION.
CLOSE DATASET FILE.
ULINE. SKIP.
WRITE: / TEXT-001, FILE.
 SAP AG

n In the example, we use the file created by the above program.


Comment:
This is only a general example. As the data for this example comes from the same SAP system, the
following batch input program could also read in the data directly with ABAP/4 Open SQL or via a
logical database (if available).
Declaration Part 2

REPORT RFFF02C.

PARAMETERS:
FILE(30) DEFAULT '/tmp/RSFFF02B'
LOWER CASE,
NAME LIKE APQI-GROUPID DEFAULT SY-UNAME.

DATA:BEGIN OF BDC_TAB OCCURS 5.


INCLUDE STRUCTURE BDCDATA.
DATA: END OF BDC_TAB.

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.

WRITE: TEXT-001, SY-MANDT, NAME, SY-UZEIT.

 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.

CALL FUNCTION 'BDC_INSERT'


EXPORTING TCODE = 'TFBA'
TABLES DYNPROTAB = BDC_TAB.
ENDDO.

CALL FUNCTION 'BDC_CLOSE_GROUP'.

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

Display session contents


Display batch input data
Analysis
Analysis Logs (extended log)
Statistics

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

Sessions Screens Customer


master recs.

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

Foreground Display all dialog steps

Display errors only Display dialog steps only for error or


termination messages

Background Dialog steps not displayed, processing


takes place in the background

 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

n A session is assigned a status during and after processing.


n Basically, the system identifies transactions that cannot be processed due to errors. These transactions
remain in the session (which becomes an error session). You can then process these sessions again and
correct the errors.
Creating and Processing Sessions

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

n A batch input program must perform the above functions.


Chapter 2 Summary

l Batch input is an automatic procedure suitable for


processing mass data. It is used primarily when installing
the SAP system and when transferring data from a legacy
system (external system). When programming, the data to
be transferred must already exist in the appropriate format
for the screen. Also, you must use the appropriate
function modules to generate an executable session in an
intermediate file (known as a queue file). You run sessions
by calling Transaction SM35 and the data is transferred to
the SAP system. There are several processing and
administration options available to support you.

 SAP AG
Exercises for Chapter 2: Introduction to Batch Input
Processing

1. Your program name: ZBCF##B1


Your group number: ##
Model file name: TELXX
Your directory name: /tmp
Your session name: RSD##021SES
Name of the BDC user: BC420BDC

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:

Program name: SAPMTFBA

Screens Fields

0100 SCUSTOM-ID
BDC_OKCODE

0200 SCUSTOM-TELEPHONE
BDC_OKCODE

2. Your program name: ZBCF###B2


Your group number: ###
Your directory name: /tmp
Name of model file: KUNXX
Session name: RSD###022SES
Name of the BDC user: BC420DC
Task:
File KUNXX contains SCUSTOM data for adding new
SCUSTOM records with transaction TFBB and for changing
existing SCUSTOM records with transaction TFBA. Write a
batch input program which reads in this data and enters it in
the SCUSTOM records.
Programming hint:
The data record structure is as follows:
filled for transaction
Description Name Length TFBA TFBB

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

Trans- Program Screens Fields


action name

TFBA SAPMTFBA 0100 SCUSTOM-ID


BDC_OKCODE
0200 SCUSTOM-NAME
SCUSTOM-POSTCODE
SCUSTOM-CITY
SCUSTOM-CUSTTYPE
SCUSTOM-DISCOUNT
SCUSTOM-TELEPHONE
BDC_OKCODE
Trans- Program Screens Fields
action name

TFBB SAPMTFBB 0100 SCUSTOM-NAME


SCUSTOM-POSTCODE
SCUSTOM-CITY
SCUSTOM-CUSTTYPE
SCUSTOM-DISCOUNT
SCUSTOM-TELEPHONE
BDC_OKCODE
0200 BDC_OKCODE

Include program for task 2

DATA: BEGIN OF REC,


FLAG,
ID LIKE SCUSTOM-ID,
NAME LIKE SCUSTOM-NAME,
POSTCODE LIKE SCUSTOM-POSTCODE,
CITY LIKE SCUSTOM-CITY,
CUSTTYPE LIKE SCUSTOM-CUSTTYPE,
DISCOUNT LIKE SCUSTOM-DISCOUNT,
TELEPHONE LIKE SCUSTOM-TELEPHONE,
END OF REC.
Model solution 1 (Chapter 2): Introduction to Batch Input
Processing
REPORT RSFFF021.

* Internal table for storing the data in screen format

DATA: BEGIN OF BDC_TAB OCCURS 5.

INCLUDE STRUCTURE BDCDATA.

DATA: END OF BDC_TAB.

* Record for the data to be transferred to the SAP System

DATA: BEGIN OF REC,

TELEPHONE LIKE SCUSTOM-TELEPHONE,

ID LIKE SCUSTOM-ID,

NAME LIKE SCUSTOM-NAME,

END OF REC.

PARAMETERS:

* Name of the batch input session

NAME LIKE APQI-GROUPID DEFAULT SY-UNAME,

* Name of the sequential file to be accessed

FILE(30) DEFAULT '/tmp/TELXX' LOWER CASE.

* Open dataset for accessing and in binary mode

START-OF-SELECTION.

OPEN DATASET FILE FOR INPUT IN BINARY MODE.

* Text-001 D: Start creating BDC session


WRITE: / TEXT-001,

SY-MANDT, NAME, SY-UZEIT.

* Create the session header

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

GROUP = NAME

USER = 'BC420BDC'

KEEP = 'X'.

* Access the data

DO.

READ DATASET FILE INTO REC.

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

WRITE: / REC-ID USING NO EDIT MASK, REC-NAME, REC-TELEPHONE.

* Subroutine for transferring the data of one transaction to the

* BDC_TAB (screen format)

PERFORM GENERATE_BDC_DATA.

* Function module for transferring the data of the BDC_TAB to the


queue file

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'TFBA'

TABLES

DYNPROTAB = BDC_TAB.
ENDDO.

* Close the completed session

CALL FUNCTION 'BDC_CLOSE_GROUP'.

* Text-002 D: End of BDC session creation

WRITE: / TEXT-002,

SY-MANDT, NAME, SY-UZEIT.

* Close the fully accessed sequential dataset

END-OF-SELECTION.

CLOSE DATASET FILE.

*-----------------------------------------------------------------
*

* FORM GENERATE_BDC_DATA
*

*-----------------------------------------------------------------
*

* ........
*

*-----------------------------------------------------------------
*

FORM GENERATE_BDC_DATA.

REFRESH BDC_TAB.

PERFORM DYNPRO USING:


'X' 'SAPMTFBA' '0100',

' ' 'SCUSTOM-ID' REC-ID,

' ' 'BDC_OKCODE' '/5',

'X' 'SAPMTFBA' '0200',

' ' 'SCUSTOM-TELEPHONE' REC-TELEPHONE,

' ' 'BDC_OKCODE' '/11'.

ENDFORM.

*-----------------------------------------------------------------
*

* FORM DYNPRO
*

*-----------------------------------------------------------------
*

* ........
*

*-----------------------------------------------------------------
*

* --> DYNBEGIN
*

* --> NAME
*

* --> VALUE
*

*-----------------------------------------------------------------
*

FORM DYNPRO USING DYNBEGIN NAME VALUE.

IF DYNBEGIN = 'X'.

CLEAR BDC_TAB.

MOVE: NAME TO BDC_TAB-PROGRAM,


VALUE TO BDC_TAB-DYNPRO,

'X' TO BDC_TAB-DYNBEGIN.

APPEND BDC_TAB.

ELSE.

CLEAR BDC_TAB.

MOVE: NAME TO BDC_TAB-FNAM,

VALUE TO BDC_TAB-FVAL.

APPEND BDC_TAB.

ENDIF.

ENDFORM.

Model solution 2 (Chapter 2): Introduction to Batch Input


Processing
REPORT RSFFF022.

* Internal table for storing the data in screen format

DATA: BEGIN OF BDC_TAB OCCURS 5.

INCLUDE STRUCTURE BDCDATA.

DATA: END OF BDC_TAB.

* Include Report contains record for the data to be transferred to

* the SAP system

INCLUDE RSFFF02F.

DATA: TCODE LIKE SY-TCODE.

PARAMETERS:

* Name of the batch input session

NAME LIKE APQI-GROUPID DEFAULT SY-UNAME,

* Name of the sequential file to be accessed


FILE(30) DEFAULT '/tmp/KUNXX' LOWER CASE.

START-OF-SELECTION.

* Open dataset for accessing and in binary mode

OPEN DATASET FILE FOR INPUT IN BINARY MODE.

* Text-001 D: Start creating BDC session

WRITE: / TEXT-001,

SY-MANDT, NAME, SY-UZEIT.

* Create the session header

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

GROUP = NAME

USER = 'BC420BDC'

KEEP = 'X'.

* Access the data

DO.

READ DATASET FILE INTO REC.

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

* Subroutines for transferring the data of one transaction to


* the BDC_TAB (screen format), irrespective of whether an SCUSTOM

* record is updated or created

CASE REC-FLAG.

WHEN 'U'.

TCODE = 'TFBA'.

PERFORM GENERATE_BDC_DATA_TFBA.

WHEN 'N'.

TCODE = 'TFBB'.

PERFORM GENERATE_BDC_DATA_TFBB.

WHEN OTHERS.

* Text-003 D: Processing terminated due to incorrect data

WRITE: TEXT-001, REC-FLAG.

EXIT.

ENDCASE.

* Function module for transferring the data of the BDC_TAB to the


queue file

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = TCODE

TABLES

DYNPROTAB = BDC_TAB.

WRITE: / REC-FLAG, REC-ID USING NO EDIT MASK,

/ REC-NAME UNDER REC-FLAG,

/ REC-POSTCODE UNDER REC-NAME, REC-CITY, REC-


TELEPHONE,

REC-CUSTTYPE, REC-DISCOUNT.

ULINE.
ENDDO.

* Close the completed session

CALL FUNCTION 'BDC_CLOSE_GROUP'.

* Text-002 D: End of BDC session creation

WRITE: / TEXT-002,

SY-MANDT, NAME, SY-UZEIT.

* Close the fully accessed sequential dataset

CLOSE DATASET FILE.


*-----------------------------------------------------------------
*

* FORM GENERATE_BDC_DATA_TFBA
*

*-----------------------------------------------------------------
*

* ........
*

*-----------------------------------------------------------------
*

FORM GENERATE_BDC_DATA_TFBA.

REFRESH BDC_TAB.

PERFORM DYNPRO USING:

'X' 'SAPMTFBA' '0100',

' ' 'SCUSTOM-ID' REC-ID,

' ' 'BDC_OKCODE' '/5',

'X' 'SAPMTFBA' '0200',

' ' 'SCUSTOM-NAME' REC-NAME,

' ' 'SCUSTOM-POSTCODE' REC-POSTCODE,

' ' 'SCUSTOM-CITY' REC-CITY,

' ' 'SCUSTOM-CUSTTYPE' REC-CUSTTYPE,

' ' 'SCUSTOM-DISCOUNT' REC-DISCOUNT,

' ' 'SCUSTOM-TELEPHONE' REC-TELEPHONE,

' ' 'BDC_OKCODE' '/11'.

ENDFORM.
*-----------------------------------------------------------------
*

* FORM GENERATE_BDC_DATA_TFBB
*

*-----------------------------------------------------------------
*

* ........
*

*-----------------------------------------------------------------
*

FORM GENERATE_BDC_DATA_TFBB.

REFRESH BDC_TAB.

PERFORM DYNPRO USING:

'X' 'SAPMTFBB' '0100',

' ' 'SCUSTOM-NAME' REC-NAME,

' ' 'SCUSTOM-POSTCODE' REC-POSTCODE,

' ' 'SCUSTOM-CITY' REC-CITY,

' ' 'SCUSTOM-CUSTTYPE' REC-CUSTTYPE,

' ' 'SCUSTOM-DISCOUNT' REC-DISCOUNT,

' ' 'SCUSTOM-TELEPHONE' REC-TELEPHONE,

' ' 'BDC_OKCODE' '/11',

* Display screen. Specification not obligatory here

'X' 'SAPMTFBB' '0200',

' ' 'BDC_OKCODE' '/3'.

ENDFORM.
*-----------------------------------------------------------------
*

* FORM DYNPRO
*

*-----------------------------------------------------------------
*

* ........
*

*-----------------------------------------------------------------
*

* --> DYNBEGIN
*

* --> NAME
*

* --> VALUE
*

*-----------------------------------------------------------------
*

FORM DYNPRO USING DYNBEGIN NAME VALUE.

IF DYNBEGIN = 'X'.

CLEAR BDC_TAB.

MOVE: NAME TO BDC_TAB-PROGRAM,

VALUE TO BDC_TAB-DYNPRO,

'X' TO BDC_TAB-DYNBEGIN.

APPEND BDC_TAB.

ELSE.

CLEAR BDC_TAB.

MOVE: NAME TO BDC_TAB-FNAM,

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

l Accessing specific lines of a step loop / table control


screen or particular fields in batch input reports.
l Conditions which must exist for a transaction to
support batch input, and how to satisfy them.
l The various standard utility programs available for
managing sessions. In particular, how to automate
session processing using RSBDCSUB.

 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.

09.01.1996 2640.66 USD A310-300 280 1


10.01.1996 2220.13 USD A310-300 280 43
11.01.1996 1896.90 USD 727-300 280 96
12.01.1996 2573.94 USD 727-400 280 130
... ... ... ... ... ...

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.

09.01.1996 2640.66 USD A310-300 280 1


10.01.1996 2220.13 USD A310-300 280 43
Technical
Technical info
info 11.01.1996 1896.90 USD 727-300 280 96
12.01.1996 2573.94 USD 727-400 280 130
... ... ... ... ... ...

Function
Function SAVE/11
SAVE/11
 SAP AG BC420 / 3 - 1

n First perform (step by step) the application function to be simulated.


n Make a note of:
- the program name and screen number for every screen
- the field and table name for every entry or cursor positioning
- the number for every function key activated
- the screen sequence
n To do this, you use the Status system function and the Technical info help function.
n The screen for the flight data is a table control screen. That is why the help function displays the same
field name for every field in a column.
Example: Structure of the BDC Table

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.

DATA:BEGIN OF BDC_TAB OCCURS 5.


INCLUDE STRUCTURE BDCDATA.
DATA: END OF BDC_TAB.

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.

CALL FUNCTION 'BDC_OPEN_GROUP'


EXPORTING CLIENT = SY-MANDT
GROUP = NAME
USER = SY-UNAME
KEEP = 'X'.

PERFORM GENERATE_BDC_DATA.

CALL FUNCTION 'BDC_INSERT'


EXPORTING TCODE = 'TCF2'
TABLES DYNPROTAB = BDC_TAB.

CALL FUNCTION 'BDC_CLOSE_GROUP'.

WRITE: / 'End creation of BDC session',


SY-MANDT, NAME, SY-UZEIT.

 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’

Table control field:


<BDC
<BDC table>
table> -- FNAM
FNAM == <field
<field name>(line
name>(line number)
number)
<BDC
<BDC table>
table> -- <field
<field value>
value>

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

Return to SAP main menu

LEAVE TO TRANSACTION ' '

No
No batch
batch input
input capability
capability

Start a new transaction

- CALL TRANSACTION 'xxxx'


- LEAVE TO TRANSACTION 'xxxx'
- '/nxxxx'
- '/i' (exit mode)

 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

n You use the report RSBDCSUB to schedule session processing.


n Proceed as follows:
1. Create a variant. The selection criteria are:

- Session name (generic entries are also possible)


- Creation date
- Session status
- Target host (for the background system)
- Extended log

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

n You can choose to process sessions in online or in the background.


n Starting the session online:
- The authorizations of the user doing the processing are checked.
n Starting the session in the background:
- The authorizations of the batch input user are used.
Authorizations for Batch Input Processing

Object
Object Fields
Fields Values
Values Meaning
Meaning
S_BDC_MONI Session name <session names> Specifies session names
for which a user is
authorized

Activities ABTC Process (submit) in


background
AONL Process online

DELE Delete
LOCK Sessions/logs
Lock date, Change

FREE Release terminated


sessions

ANAL Analyze sessions

 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

l In batch input programming, you can address step loop /


table control screens as well as particular fields, and
change them if required. Batch input capability can only
be guaranteed if the transaction sets an end flag which is
recognized by the batch input system. There are several
standard utility programs available. They support the
processing (RSBDCSUB) and management of batch input
sessions.

 SAP AG
Exercise for Chapter 3: Special Features of Batch Input
Processing

1. Your job name: ZBCF##C1JOB


Your group number: ##
Your session name: ZBCF##C1SES
Your variant names: ZBCF##C1VAR
Task:
Create a job for your batch input program (Exercise 1, Chapter
2). The job should start the batch input program and then
process the generated session.
Programming hints:
a) Define a variant for the SAP program 'RSBDCSUB'.
b) Create a job for your batch input program 'ZBCF17#B1'.
c) Extend this job to include a request to process the variant
you have defined for the SAP program 'RSBDCSUB'.
d) Release the job and start it immediately.
e) Analyze the job log and the job results.
f) Use transaction SM35 to check that the sessions were
processed correctly. Your session directory should be
empty (successfully processed sessions are normally
deleted immediately).
Chapter 4 General Information on Application-
specific Batch Input Programs
l Transferring data from external Systems to the SAP
system.
l Principles and examples of application-specific
standard transfer programs for batch input.
l Principles and examples of direct input.

 SAP AG
Chapter 4 Objectives

l Transferring data from external systems.


l Standard application-specific transfer programs to
support data transfer.
l The requirements for using these programs and how
to get information on them.

 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 legacy system

?
Fields and structures
in the SAP system

 SAP AG

n There is a data analysis at the start of every data transfer.


n In the data analysis, you decide which data can be transferred and how. Proceed as follows:
Ÿ Compare your old data with the data fields in the SAP System.
Ÿ Define which fields from the old data can be transferred directly to the SAP System.
Ÿ Draw up rules for filling data fields in the SAP System where old data cannot be directly used.
Transfer Program

Sequential file 1

Read data records

Customer
transfer program
Structure in old format

Structure in SAP format

Write data records

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

<old structure definitions>


Dict.
ABAP/4
ABAP/4
TABLES

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

Initializing SAP structures

.....

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

Customer <Convert data>


conversion 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.

MOVE: '2' TO BLFA1-STYPE,


'BLFA1' TO BLFA1-TBNAM,
TELF1 TO BLFA1-TELF1,
NODATA TO BLFA1-SENDE.
*E Transfer data
TRANSFER: BLF00 TO SAPFILE,
BLFA1 TO SAPFILE.
*E TEXT-002: 'Data transferred for vendor
WRITE: / TEXT-002, OLDREC-LIFNR.
ENDIF.
ENDDO.

CLOSE DATASET: OLDFILE, SAPFILE, ERRFILE.


 SAP AG

n As the length of the old data is different, it must be converted.


n The converted data can then be placed in the SAP structures.
n Finally, the SAP structures can be transferred to a sequential file. They can then be analyzed by the
standard batch input program RFBIKR00.
n Note: In ABAP/4, a single MOVE is sufficient to convert and fill the SAP structure (every MOVE
statement automatically performs a conversion).
Batch Input, CALL TRANSACTION and Direct
Input

External data

ABAP/4
program

Batch input queue


Direct input:
CALL TRANSACTION/ Function modules
USING BDCDATA instead of screens
Batch input
sessions Table

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.

RMDATIND MM Direct input. Imports material master records.

RVAFSS00 SD Direct input. Generates SD billing documents and FI follow-on


documents from an external file.

RKEVEXT0CO-PA Direct input. Transfers external data to Profitability Analysis.

RAALTD11 AM Direct input. Creates asset master records.


Tasks of a Transfer Program

Define
Define old
old structures
structures

Import
Import SAP
SAP structures
structures

Initialize
Initialize SAP
SAP structures
structures

Read data record

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 sequential file

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

l Interface programs are often required to peform fast,


correct mass data processing, in particular the transfer of
data from external systems to the SAP System. This
chapter discussed the problems of this type of data
transfer. Standard application-related transfer programs
have been created for this purpose. The principles and
scope of these programs were explained.

 SAP AG
Chapter 5 CALL TRANSACTION

l CALL TRANSACTION USING ... vs. batch input.


l The statement CALL TRANSACTION USING ... .
l Technical implementation.

 SAP AG
Chapter 5 Objectives

l The difference between CALL TRANSACTION


USING ... and batch input, and the advantages and
disadvantages of the two processes.
l The scope of the CALL TRANSACTION USING ...
statement and the different processing and update
modes.
l The technical features of the CALL TRANSACTION
USING ... statement.

 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

Roll area 1 Roll area 2


REPORT ... .
DATA: BEGIN OF <BDC table> OCCURS ... .
INCLUDE STRUCTURE BDC_DATA.
DATA: END OF <BDC table>.
:
:
PERFORM GENERATE_BDC_DATA.

CALL TRANSACTION <transaction code>


USING <BDC table>
MODE <display mode>
UPDATE <update mode>
:
:
CASE SY-SUBRC.
:
:

 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.

DATA:BEGIN OF BDC_TAB OCCURS 5.


INCLUDE STRUCTURE BDCDATA.
DATA: END OF BDC_TAB.

DATA: BEGIN OF MESSTAB OCCURS 5.


INCLUDE STRUCTURE BDCMSGCOLL.
DATA: END OF MESSTAB

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.

CALL TRANSACTION 'TFBA'


USING BDC_TAB
MODE DISMODE
UPDATE UPDMODE
MESSAGES INTO MESSTAB.

IF SY-SUBRC = 0.
WRITE: / 'Transaction successfully
processed'.
ELSE.
WRITE: / 'Error when processing'.
ENDIF.

WRITE: / 'Ende CALL TRANSACTION ', SY-UZEIT.

 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

< 1000 Error in dialog program

> 1000 Error in batch input processing


(see system fields)

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.
...

CALL TRANSACTION 'TFBA'


USING BDC_TAB
MODE DISMODE
UPDATE UPMODE
MESSAGES INTO MESSTAB.
...

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

Batch input CALL TRANSACTION

Return code No Yes

Error logging Yes No

Processing Time-delayed Immediately

 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

l CALL TRANSACTION USING ... is an alternative to the


conventional batch input process. Direct transfer of data
is particularly fast since the queue file is avoided (i.e. no
sessions are generated).
As with batch input, there is a high degree of data
integrity since the data is imported using transactions.
CALL TRANSACTION has certain advantages over batch
input (e.g. when you chooseupdate mode), but it does not
offer the same correction and administration options as
batch input.

 SAP AG
Exercise for Chapter 5: CALL TRANSACTION

1. Name of your job: ZBCF##E1


Name of your directory: /tmp
Your group number: ##
Name of a model file: TELXX
Task:
Write a CALL TRANSACTION program for your file TEL## or
for the model file TELXX. The program should enter the
telephone numbers in the relevant SCUSTOM records using
the Transaction TFBA.
Programming hints:
Convert your batch input program ZBCF##B1 to a CALL
TRANSACTION program. For the Transaction TFBA, use the
following screens in the specified order:

Program name: SAPMTFBA

Screens Fields

0100 SCUSTOM-ID
BDC_OKCODE

0200 SCUSTOM-TELEPHONE
BDC_OKCODE
Model solution for Chapter 5: CALL TRANSACTION
REPORT RSFFF051.

* Internal table to store the data in screen format

DATA: BEGIN OF BDC_TAB OCCURS 5.

INCLUDE STRUCTURE BDCDATA.

DATA: END OF BDC_TAB.

* Internal Table of format BDCMSGCOLL to store the transaction

* messages

DATA: BEGIN OF MESSTAB OCCURS 5.

INCLUDE STRUCTURE BDCMSGCOLL.

DATA: END OF MESSTAB.

* Record for the data to be transferred to the SAP System

DATA: BEGIN OF REC,

TELEPHONE LIKE SCUSTOM-TELEPHONE,

ID LIKE SCUSTOM-ID,

NAME LIKE SCUSTOM-NAME,

END OF REC.

PARAMETERS:

* Name of the sequential file to be accessed

FILE(30) DEFAULT '/tmp/TELXX' LOWER CASE,

* Processing and update mode

DISMODE DEFAULT 'A',


UPDMODE DEFAULT 'S'.

START-OF-SELECTION.

* File opened for reading and in binary mode

START-OF-SELECTION.

OPEN DATASET FILE FOR INPUT IN BINARY MODE.

* Text-001 E: Start CALL TRANSACTION

WRITE: / TEXT-001, SY-UZEIT.

* Accessing data

DO.

READ DATASET FILE INTO REC.

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

WRITE: / REC-ID USING NO EDIT MASK, REC-NAME, REC-TELEPHONE.

* Subroutine in order to tranfer the data of one transaction to

* the BDC_TAB (screen format)

PERFORM GENERATE_BDC_DATA.

* Transaction called together with data in screen format

CALL TRANSACTION 'TFBA'

USING BDC_TAB

MODE DISMODE

UPDATE UPDMODE.

* MESSAGES INTO MESSTAB.


IF SY-SUBRC = 0.

* Text-002 E: Transaction successfully processed

WRITE: TEXT-002.

ELSE.

* Text-003 E: Error in processing

WRITE: TEXT-003.

ENDIF.

MESSAGE ID SY-MSGID

TYPE SY-MSGTY

NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDDO.

* Text-004 D: End of CALL TRANSACTION

WRITE: / TEXT-004, SY-UZEIT.

* Close the fully accessed sequential dataset

END-OF-SELECTION.

CLOSE DATASET FILE.

*-----------------------------------------------------------------
*
* FORM GENERATE_BDC_DATA
*

*-----------------------------------------------------------------
*

* ........
*

*-----------------------------------------------------------------
*

FORM GENERATE_BDC_DATA.

REFRESH BDC_TAB.

PERFORM DYNPRO USING:

'X' 'SAPMTFBA' '0100',

' ' 'SCUSTOM-ID' REC-ID,

' ' 'BDC_OKCODE' '/5',

'X' 'SAPMTFBA' '0200',

' ' 'SCUSTOM-TELEPHONE' REC-TELEPHONE,

' ' 'BDC_OKCODE' '/11'.

ENDFORM.

*-----------------------------------------------------------------
*

* FORM DYNPRO
*

*-----------------------------------------------------------------
*
* ........
*

*-----------------------------------------------------------------
*

* --> DYNBEGIN
*

* --> NAME
*

* --> VALUE
*

*-----------------------------------------------------------------
*

FORM DYNPRO USING DYNBEGIN NAME VALUE.

IF DYNBEGIN = 'X'.

CLEAR BDC_TAB.

MOVE: NAME TO BDC_TAB-PROGRAM,

VALUE TO BDC_TAB-DYNPRO,

'X' TO BDC_TAB-DYNBEGIN.

APPEND BDC_TAB.

ELSE.

CLEAR BDC_TAB.

MOVE: NAME TO BDC_TAB-FNAM,

VALUE TO BDC_TAB-FVAL.

APPEND BDC_TAB.

ENDIF.

ENDFORM.
Chapter 6 Local Files

l Local files vs. files on the application server.


l Standard function modules for generating and
reading local files.
l Linking options between local files and files stored
on the application server.
l Overview: Function modules for working with local
files.

 SAP AG
Chapter 6 Objectives

l The differences between local files and files stored


on the application server and their various uses.
l The different function modules available for
processing local files.

 SAP AG
Overview

Application
server
88MHz

Application server files

Presentation
server
88MHz

Presentation server files

 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

Application server ABAP/4


ABAP/4 program
program
files

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

CALL FUNCTION CALL FUNCTION


’D OWNLOAD’ ’U PLOAD’

File name: File name:


File type: File type:

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

A<tab> B<tab> C<CRLF>


D<tab> E<tab> F<CRLF>
. . . . . .
. . . . . .

 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

n This example program generates a local file with SFLIGHT data.


n When calling DOWNLOAD, it is enough to download the table with the data for the file. However, you
can also specify default values for the file dialog name, type and header. If you make no specification
about the mode, the file is always recreated (parameter MODE = ' ').
Example Program: UPLOAD

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

n This example program reads a local file with SFLIGHT data.


UPLOAD and DOWNLOAD as Standard
Functions

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’

Sequential Local sequential


file file

 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

Get file name Get file name

Physical Get
file name file size
WS_FILENAME_GET
WS_FILENAME_GET WS_QUERY
WS_QUERY

Logical file name Environment variables

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:

starts a program on the presentation server.


Chapter 6 Summary

l The R/3 System allows you to generate local files on the


frontend or the presentation server and process them
further. It provides several standard function modules
which are especially suited to this purpose. You can also
exchange data between frontend files and application
server files.

 SAP AG
Exercises for Chapter 6: Local Files

1. Name of your job: ZBCF##F1


Your group number: ##
Name of your host directory: /tmp
Name of a host model file: BOOKXX
Name of your local directory: /tmp
Name of your local file: LOC##
Task:
Write a program which downloads your file BOOK## to the
local file LOC##.

2. Name of your program: ZBCF##F2


Your group number: ##
Name of your local directory: /tmp
Name of your local file: LOC##
Task:
Write a program which reads your local file LOC## and
displays it on the screen.
Model solutions for Chapter 6: Local Files

1.
REPORT RSFFF061.

* Internal table for local dataset defined as Dictionary structure

* or include report

DATA: BEGIN OF TAB OCCURS 20.

INCLUDE STRUCTURE SBC420C.

DATA: END OF TAB.

* STRUCTURE SBC420C:

* CARRID, CONNID, FLDATE, BOOKID, CUSTOMID.

* Alternative:

* INCLUDE RSFFF01L.

DATA: TYPE LIKE RLGRAP-FILETYPE VALUE 'ASC',

LENGTH(5).

* Create the selection screen

PARAMETERS:

HOSTFILE LIKE RLGRAP-FILENAME DEFAULT '/tmp/BOOKXX',

* LOCLFILE LIKE RLGRAP-FILENAME DEFAULT '/tmp/BC420LOCXX', "UNIX

LOCLFILE LIKE RLGRAP-FILENAME DEFAULT 'C:BC420LOCXX.ABA',


"NT/OS2

MODE DEFAULT 'A'.

START-OF-SELECTION.

* Text mode because /tmp/BOOKXX was created in text mode

OPEN DATASET: HOSTFILE FOR INPUT IN TEXT MODE,


LOCLFILE FOR OUTPUT IN TEXT MODE.

* Access data in application server file and store in an

* internal table

DO.

CLEAR TAB.

READ DATASET HOSTFILE INTO TAB.

IF SY-SUBRC NE 0. EXIT. ENDIF.

APPEND TAB.

WRITE: / TAB-CARRID, TAB-CONNID,

/ TAB-FLDATE, TAB-BOOKID, TAB-CUSTOMID.

ULINE.

ENDDO.

* Call function module DOWNLOAD. Data is downloaded using an

* internal table TAB together with the file name and file type

* The length of the file generated in this way is returned.

CALL FUNCTION 'DOWNLOAD'

EXPORTING

FILENAME = LOCLFILE

FILETYPE = TYPE

* ITEM = 'SFLIGHT data'

MODE = MODE

IMPORTING

* ACT_FILENAME = FILE

* ACT_FILETYPE = TYPE

FILESIZE = LENGTH

TABLES

DATA_TAB = TAB.
*E Text-001: 'In file:'

*E Text-002: 'Format'

*E Text-003: 'bytes were downloaded'

WRITE: / TEXT-001, LOCLFILE, TEXT-002, TYPE,

LENGTH, TEXT-003.

2.
REPORT RSFFF062.

* Internal table for local dataset defined as Dictionary structure

* or include report

DATA: BEGIN OF TAB OCCURS 20.

INCLUDE STRUCTURE SBC420C.

DATA: END OF TAB.

* STRUCTURE SBC420C:

* CARRID, CONNID, FLDATE, BOOKID, CUSTOMID.

* Alternative:

* INCLUDE RSFFF01L.

DATA: TYPE LIKE RLGRAP-FILETYPE VALUE 'ASC',

LENGTH(5).

* Create the selection screen

PARAMETERS:

* LOCLFILE LIKE RLGRAP-FILENAME DEFAULT '/tmp/BC420LOCXX', "UNIX

LOCLFILE LIKE RLGRAP-FILENAME DEFAULT 'C:BC420LOCXX.ABA'.


"NT/OS2

START-OF-SELECTION.
* Call the function module UPLOAD. Pass the name of the file to be

* accessed and its type. Returns the data in form of an internal

* table with the length of the file accessed.

CALL FUNCTION 'UPLOAD'

EXPORTING

FILENAME = LOCLFILE

FILETYPE = TYPE

* ITEM = 'SFLIGHT data'

IMPORTING

FILESIZE = LENGTH

TABLES

DATA_TAB = TAB.

* Output the internal table

LOOP AT TAB.

WRITE: / TAB-CARRID, TAB-CONNID,

/ TAB-FLDATE, TAB-BOOKID, TAB-CUSTOMID.

ULINE.

ENDLOOP.

*D Text-001: 'From file:'

*D Text-002: 'Format'

*D Text-003: 'bytes were read'

WRITE: / TEXT-001, LOCLFILE, TEXT-002, TYPE,

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

e.g. - recurring entries


- cashed checks
Interface
Interface program
program

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:

'No batch input for this field'.


Master Data
Transaction ffüürr
Transaction
Create
Create XK01
XK01 // XD01
XD01
Change
Change XK02
XK02 // XD02
XD02
Lock
Lock XK05
XK05 // XD05
XD05
Flag
Flag for
for deletion
deletion XK06
XK06 // XD06
XD06

Structures ( using vendor as an example )


BGR00 Type 0 Session data

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

n The general posting and clearing transactions are supported.


Example of Batch Input 2

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 ...

BBSEG 2 BBSEG 50 Revenues / / 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

n For each company code, you define the following:


- Transfer date
- Status
- Residual value
- "Calculate cum. insurable value" option
- Sequence of depreciation areas for transfer of legacy data
n You can transfer assets from the old system starting at any point in the past. When transferring legacy
data less than a year old, it is possible to list the transactions from the last fiscal year closing up to the
time of the transfer at the time of the transfer.
n If you did not maintain insurable values in your legacy system, you can calculate them when
transferring the data. When determining the sequence, the depreciation areas should first appear on the
screen with values which have for the most part been entered manually. Explicit values must be entered
both in the area of book depreciation and in investment areas. In the remaining areas, you can transfer
values from external areas and excude the option to change values.
n For further online documentation, choose Help -> R/3 library -> Financial Accounting -> Asset
Accounting - System Administration -> Organizational Elements.
Transfer Options per Depreciation Area
Determine
Determine
for
for each
each
depreciation
depreciation
area
area

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

n For each depreciation area, you define the following options:


Ÿ “Calculate cum. replacement value"
Ÿ “Recalculate cum. depreciation"
Ÿ With legacy data less than one year old, the date of the last depreciation posting run in the legacy
system
n If you did not maintain replacement values in your legacy system, you can calculate them when
transferring the legacy data, provided the depreciation area allows this.
n You can use the option "Recalculate cum. depreciation" for test purposes.
n When listing cum. values, you can enter the residual value instead of the cum. depreciation. The system
then determines the cum. depreciation at the time of transfer from the difference between the acquisition
value and the net book value.
n If the depreciation has already been posted in the legacy system for legacy data less than one year old,
you can store the last posting period in the depreciation area.
Automatic Transfer of Legacy Data

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

Vendor Asset bal. (can be directly posted)

”T ools à Business Engineering à Customizing à


Implement. projects à SAP Reference IMG à ... ”
1000 1000

(RACKONT2)
After AM import

Vendor Asset

1000 1000

Asset bal. (recon. account only)

1000

 SAP AG

n After import, the G/L accounts must be changed from “directly postable” to “reconciliation account
only”.
Data Transfer

External system Prices/


conditions
Customer-specific
Customer-specific
conversion program

Sequential file SAP data structure


SAP format

SAP
SAP data
data transfer
transfer
program

R/3 System Batch input


session
Process
Process session
session
Transaction 1 Transaction 2

... ...
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

- Customer master records


- Vendor master records
- Material master records
- Condition records
- Open orders
Overview of Background Processing

Features
Execution of ABAP/4 programs without dialog or
operating sytem-specific Job Control Language

Complete integration into the R/3 System

Parallel running of background and online processing

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

Job Job Job


scheduling running overview

 SAP AG

n To execute a program in the background, you must first include it in a job.


n When scheduling jobs, you define which reports you want to run. You can specify when the job is to be
executed and the print parameters.
n The job can only be executed when it has been released by the administrator.
n You can display jobs and manage them in the overview facility. You can display and maintain logs
generated by background processing.
n Jobs are executed in special work processes.
Scheduling Background Jobs
Job definition

Job name ......................


.
. Steps
.

Print specifications

Start time

Period

Save

 SAP AG

n You create a job with the Job definition function.


n To proceed, choose System -> Services -> Jobs or System -> Services -> Reporting -> Program ->
Background, or call Transaction SM36.
n To make the request, you need to specify a job name (any name you like), the name of the program to be
started and a variant, as well as the name of a user for authorization checking purposes.
n The scheduling part ends when you Save. Before doing this, you can specify the start time, how often
the job is to be repeated and the print parameters.
n You can extend an existing job to include more steps. When doing this, you get a step list which you can
edit to suit your requirements.
n In distributed environments, you can specify a target machine where the processing is to take place
(choose this by pressing F4).
n By specifying a job class, you can determine the priority and type of a job.

You might also like