Thursday, August 16, 2007

BDC (Batch Data Communication) Tutorial for Data Transfer

What is BDC
BDC ( Batch Data Communication ) is used for uploading mass data into SAP system. In SAP system BDC also referred to batch input or data tranfer.

Typical Uses
Typical uses of batch input include the one-time import of data from a legacy system into a newly installed R/3 System. Another typical use is for periodic transfers of data from external systems or legacy systems that are still in use into SAP.


Background of BDC
To ensure data consistency in SAP system, we must not update SAP data directly from ABAP program. We must upload data through similar program flow compared to manual input by user. SAP provide this by BDC. BDC works by simulating the user input from transactional screen via an ABAP program. This means that you do not bypass any of the standard SAP consistency checks, authorisations, update conjunction tables, etc.

How it works
Data input entered by user simulated in BDC by data packet. The transaction then started using this internal table as the input and executed in the background.

Data packet is an internal table has a structure of BDCDATA, it has fields:
1. PROGRAM (program name)
2. DYNPRO (screen number)
3. DYNBEGIN (New screen start) X=new screen
4. FNAM (Field name)
5. FVAL (Field value)
Data packet contain of screen by screen packets. One screen packet contain:
1. Screen no
2. Cursor position
3. User command
4. Input fields
It implemented in internal table in this format:

PROGRAMDYNPRODYNBEGINFNAMFVAL
program1screen1X
BDC_CURSORpos1
BDC_OKCODEcomm1
fieldname1fieldvalue1
fieldname2fieldvalue2
program2screen2X
BDC_CURSORpos1
BDC_OKCODEcomm1
fieldname1fieldvalue1
fieldname2fieldvalue2


For example, we want to create a BDC to change ABAP program title.
Here is what we do manually: Go to screen SE38, enter program, select radiobutton "Attributes", then click "Change". After that, change title then press "Save" button.
In BDC, we simulate this by following internal table:
PROGRAMDYNPRODYNBEGINFNAMFVAL
SAPLWBABAP100X
BDC_CURSORRS38M-FUNC_HEAD
BDC_OKCODE=CHAP
RS38M-PROGRAMMZAALTESTBDC
RS38M-FUNC_EDIT
RS38M-FUNC_HEADX
SAPLSEDTATTR200X
BDC_CURSORRS38M-REPTI
BDC_OKCODE=CONT
RS38M-REPTITest change title BDC
TRDIR-SUBC1
TRDIR-FIXPTX
SAPLWBABAP100X
BDC_CURSORRS38M-PROGRAMM
BDC_OKCODE=BACK
RS38M-PROGRAMMZAALTESTBDC
RS38M-FUNC_HEADX


To accomodate you to build data packet, SAP provide BDC recording in tcode SHDB.
Do following action:
1. Go to tcode SHDB
2. click "New recording", enter recording name to identified your record, and TCode to be recorded.
3. You will enter recording mode of the transaction, simulate action you want to perform in this transaction
4. At the end it will result internal table ready to upload to data transfer methods (Call transaction or BDC sessions).

After internal table created then we pass this to data transfer methods. There are two alternatives of data transfer methods, using Call Transaction or BDC session.
Call transaction performed by calling command ‘Call Transaction’. ABAP program must do the error handling based on returning table from call transaction command. It is used for real-time interfaces and custom error handling & logging features. This is suitable when processing sequential update, it means, next data will depend on previous data.
In BDC Sessions, the ABAP program creates a session with all the transactional data, and this session can be viewed, scheduled and processed (using Transaction SM35) at a later time. The latter technique has a built-in error processing mechanism too.

Other useful article:
BDC Tutorial in SAP-Img

3 komentar:

Anonymous said...

thx yach atas info - info yang penting ini semoga sukses slalu. ini sangat amat berguna buat saya yg pemula

suwardi said...

Mas, ayo post2 another tips2 lain..
Blog ini guna banget buat saya belajar nih.. :D

Raju said...

how to write a proram for BDC skipping the first record alone from flat file.