Vous êtes sur la page 1sur 19

BDC Batch Data Communication

By-Sneha Sawardekar, Techvantage IT Solutions, Pvt Ltd.

Batch Data Communication or BDC is a batch interfacing technique that SAP


developed. It is mainly used for uploading data into the SAP R/3 system. BDC
works by simulating the user input from transactional screen via an ABAP
program

BDC Reports are used to transfer data from legacy system into SAP system
during SAP Implementation.

If the old system is replaced by SAP, such a transfer is called Conversion.


If the old system runs along with SAP, in that case the transfer is called
an Interface.

Based on the functional requirements you have to now write a BDC report to
upload the legacy data into SAP system.

Allows database updates in the background using standard SAP transactions.

Before Data transfer, the non SAP data has to be analysed and extracted from
the non SAP system. It is then mapped into the SAP format. Then only it is
transferred to SAP system. Finally transferred data is checked in the SAP
database.

Tcode SHDB is used to record transaction code the user requires. This will create
a simulation using which the developer will create a program and modify it. This
is a easy method for developer.

There are two methods to implement BDC


1. Session Method
2. Call Transaction Method

Following is the difference between two methods.


Session Method
Synchronous Processing

Call Transaction
Asynchronous Processing

Large data can be transferred

Small data can be transferred

Speed of processing slow

Speed of processing - faster

Data updated after session is processed


separately using SM35.
Error log is created during processing of
batch input session

Data updated automatically during


execution of batch input program
Needs explicit handling of errors in batch
input program.

To use BDC, first upload data to an internal table. This data cannot be passed
directly to DB. These source fields are passed through corresponding screen
fields which are used in the recording. For this transfer we need a batch input
structure.

This batch input structure is used by all batch input methods regardless we
are using session method or call transaction method.

We need to create a structure called BDCDATA. The fields are as shown below.

1. PROGRAM - name of the module pool program associated with the screen. Set

this only for first record.


2. DYNPRO screen number
3. DYNBEGIN BDC screen start, set to X only in the start, or else it is for all

other records.
4. FNAM Field name. Not case sensitive
5. FVAL BDC field value of the given field name. It contains data that is entered

into screen fields, Function codes that are entered into the command field. Such
function codes execute functions in a transaction, such as Save or Enter.

BDCMSGCOLL is a structure used for collecting messages in SAP. This structure


is used for error processing.

Using fields MSGV1, MSGV2, MSGV3, MSGV4 we can view the messages
generated by BDC program.
Example

CALL TRANSACTION 'MM01'


USING ITBDCDATA
MODE 'E'
UPDATE 'S'
MESSAGES INTO ITMESSTAB.
BDCMSGCOLL.

ITMESSTAB has structure

There are two ways to process the BDC sessions:


1) Using Transaction SM35.
2) Use program RSBDCSUB - RSBDCSUB schedules the session to be processed
in background. Use the program "RSBDCSUB" in the batch input program itself
so that the session is processed as soon as it is created.
Session Method

If we are using Session Method we use the following functions 1) BDC_OPEN_GROUP for opening the Batch Input Session
2) BDC_INSERT for inserting the transactional data into SAP
3) BDC_CLOSE_GROUP for closing the Batch Input Session
General Information about a session is stored in table APQI.
Transaction data for a session is stored in table APQD.

Three modes to process the batch input sessions are


1. Foreground
2. Display errors only
3. Background

Call Transaction Method


The CALL TRANSACTION method allows only a single transaction to be
processed by SAP.
If we are using Call transaction method we use following functions
1) Open_group
2) Bdc_dynpro
3) Bdc_field
4) Bdc_transaction
5) Close_group

These functions are generated automatically when we create new program after
recording is done using transaction SHDB.
Example Upload Material Master Data using BDC. Tcode MM01 using Call
Transaction
Step 1: Record the transaction
Tcode SHDB is used to record transaction.
Press New Recording, enter recording name, enter Tcode, press Start Recording

Create New recording

Press Start Recording


Here we are taking an example for Material Creation. So the user will be taken to
screen MM01

Fill all desired entries required for upload.

After Save is pressed, following screen is displayed.

BDC_OKCODE: is used for storing commands during the recording for eg. '/00' is the
command for 'ENTER' Key.
BDC_CURSOR: contains the cursor position. it contains the field in which cursor will
be.
Go Back.
Now create a New Program.

Enter Program Name.


Select Option Transfer from recording depending on your requirement.

Enter title for program. Press Source code

Save the program in the desired package, create TR.

ABAP editor screen is displayed with the code generated after recording the Tcode.

Now create a excel sheet as source file with all the fields required for upload.

Using Format Cells option for each cell, convert each cell as Text

Depending the field length for each field, change the column width for each cell.
For example for material number, make column width as 18 which is same as the field
length of matnr.

Accordingly make changes for all other fields depending on their length in DB tables.

Now, the progam create an internal table with same fields are required for upload. Keep
the sequence same as in the recording.

Call function Upload just after start-of-selection

In the above example function Upload is use to read data from file into internal table.

To read files from Application Server use following functions OPEN DATASET ---> opens the file(dataset) either in read /write mode.
READ DATASET ---> Read the file
CLOSE DATASET ---> Close the dataset once the date has been read .
To read files from Presentation Server use following functions GUI_UPLOAD --> To read data from file into an internal table
GUI_DOWNLOAD --> To write data from internal table to a file on presentation server
After perform open_group, insert LOOP statement.

Replace all the values entered during recording with the sames of corresponding
internal table fields. Comment the recording values.

Save and activate Program.


Execute .
Two options will be mentioned.

Generate Session

Call transaction

Here, select Call transaction.


Processing Mode = A
There are following options for processing mode.
A Display all screens
E Display errors
N Background Processing
P Background Processing, debugging possible.
There are following options for Update Mode.
L - Local
S - Synchronous
A Asynchronous

In Synchronous update , the database is updated before the next transaction is


taken for processing in a batch input.
In Asynchronous update , the system doesn't wait for updating the
database before the next transaction is taken for processing in a batch input.

The name and path of the source file is to be given here. Make sure you enter the .prn
format of the file. Press transfer.

All the screen used in the recording will be displayed. Check if all the data mentioned in
the source file is as per given and placed in the correct field on screen. If correct press
Continue.

BDC OK-codes are the commands that we have entered during our recording.
For each step there is a separate OK-Code. For example: for Enter the Ok code is '/00'.
For Save the Ok Code is '/11'. For each recording the last Ok code is always Save.
With other things as usual, there is a special trick that you have to use while doing BDC
for table control.
You need to use the BDC OKCODE '=P+'.

Finally, after all screens are processed, the following screen is displayed which shows
the detailed report of the upload.
Errors if any can be seen here.

Data can be checked in SE11 table if upload is successful.

CTU_PARAMS is a structure which has components used to control processing of

CALL_TRANSACTION. This structure is used to provide display mode, update


mode, default size and more control components to the Call Transaction
statement.

Vous aimerez peut-être aussi