0% found this document useful (0 votes)
5 views

BDC in ABAP for Data Migration

BDC (Batch Data Communication) in ABAP is a method for transferring data from non-SAP systems to SAP systems, utilizing screen recording for implementation steps. It includes various methods such as Call Transaction, Session, and Direct Input, with specific precautions during recording. The document provides detailed steps for creating a BDC program, including syntax, implementation, and sample code for material migration.

Uploaded by

Ashrar Ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

BDC in ABAP for Data Migration

BDC (Batch Data Communication) in ABAP is a method for transferring data from non-SAP systems to SAP systems, utilizing screen recording for implementation steps. It includes various methods such as Call Transaction, Session, and Direct Input, with specific precautions during recording. The document provides detailed steps for creating a BDC program, including syntax, implementation, and sample code for material migration.

Uploaded by

Ashrar Ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

2️⃣

BDC( Batch Data Communication )


in ABAP
1. Introduction
BDC stands for Batch Data Communication

The purpose of BDC is to transfer data from Non-SAP( Legacy ) system to SAP system.

BDC works on the principle of Screen recording, i.e. We can record the steps of
Implementation and then we can reuse it in the program for large scale migration.

The transaction code for Recording is SHDB.

Precaution for Recording


1. Never Use F4 and F1 Help.

2. Do not pass wrong values.

BDC Methods
1. Call Transaction Method

2. Session Method

BDC( Batch Data Communication ) in ABAP 1


Mob No :- +916261538504
3. Direct Input Method

Note :-
Call transaction method and session method are called as Batch Input Methods.

2. Screen Recording for Creating Material


Step 1 :- Go to transaction code SHDB.

Step 2 :- Click on new Recording.

BDC( Batch Data Communication ) in ABAP 2


Mob No :- +916261538504
Provide the name of your recording and give the transaction code.

BDC( Batch Data Communication ) in ABAP 3


Mob No :- +916261538504
Step 3 :- Click on start recording and you will navigate to mm01.

Press Enter and select Basic data 1 and click on Okay button.

Provide the short description and basic unit of measurement as EU and click on save
button.

Click on back button and we will see our recording is ready.

BDC( Batch Data Communication ) in ABAP 4


Mob No :- +916261538504
Step 4 :- Select the recording.

Click on Program and a pop up screen will appear.

Give a program name and Select Transfer from recording radio button.

BDC( Batch Data Communication ) in ABAP 5


Mob No :- +916261538504
Step 5 :- Click on Okay button and provide a title for our program.

Click on source code and assign the package and transport request.

BDC( Batch Data Communication ) in ABAP 6


Mob No :- +916261538504
Our program is ready.

3. Data that we will Migrate

Above is the 5 records that we will migrate, the various columns that we can see here are
Material Number, Industry Sector, Industry Type, Material Description, Basic unit of
measure etc.

BDC( Batch Data Communication ) in ABAP 7


Mob No :- +916261538504
4. Implementing the BDC Program
Step 1 :- First we need to bring the notepad file into our local system so for that purpose we
will create a parameter of type local file and before that we will define a type structure and
internal table and work area for the file as well.

Step 2 :- We will use At Selection Screen on Value Request event to apply a F4 Help and
then we will use F4_FILENAME function module to pick local file from our PC.

Step 3 :- Now to upload this file to SAP System we will use GUI_UPLOAD function
module to upload file into the SAP System which will return the data into our desired
internal table.

BDC( Batch Data Communication ) in ABAP 8


Mob No :- +916261538504
Step 4 :- Then we will un comment the rest of the logic except the start of selection part.

Step 5 :- Now we will use the a loop statement to loop for all our records.

BDC( Batch Data Communication ) in ABAP 9


Mob No :- +916261538504
Step 6 :- We will comment the perform OPEN_GROUP, BDC transaction and perform
CLOSE_GROUP.

Step 7 :- Now, Inside our loop we can see we have two perform BDC_DYNPRO and
BDC_FIELD, so for that we are required to created Form (Subroutines) as well, so for that
purpose, we will go inside this below include.

BDC( Batch Data Communication ) in ABAP 10


Mob No :- +916261538504
Double click on the include and click on display button, and at the end you will be able
to see the below subroutines, so simply copy them and paste in your programs.

Step 8 :- Copy the Subroutines and paste in our programs.

BDC( Batch Data Communication ) in ABAP 11


Mob No :- +916261538504
Step 9 :- Now, in these subroutines we can see that SAP is simply appending data in
BDCDATA, so we will simply check the type and we will create a internal table and work
area accordingly.

Step 10 :- We will comment that include.

Step 11 :- Now we will go to the subroutines and check the internal table and work area
accordingly, and also remove the if statement from the BDC_FIELD subroutine.

BDC( Batch Data Communication ) in ABAP 12


Mob No :- +916261538504
Step 12 :- Then we will pass the data of our work area into the into the perform.

5. Call Transaction Method


Syntax :-
CALL TRANSACTION ‘TRANSACTION CODE’ USING ( BDC Internal Table ) MODE
‘A or N or E’ UPDATE ‘A or S or L’ Messages INTO ( Internal Table ).
Example :- CALL TRANSACTION ‘MM01’ USING LT_BTDCDATA MODE ‘A’
UPDATE ‘S’ Messages INTO LT_MESSTAB.

Processing Nodes
1. A → All Screen ( It will show screen by screen processing )

2. N → No Screen ( It will not show any screen, directly we will get a output ).

BDC( Batch Data Communication ) in ABAP 13


Mob No :- +916261538504
3. E → Error ( If there is a error in BDC - It will show the screen where the error is, If there is
no error - It will not show any screen ).

Update Nodes
1. A → Asynchronous( COMMIT WORK )

The called transaction does not wait for any updates to be completed.

Results in faster execution of the data transfer program.

2. S → Synchronous( Sync between the sender and receiver, COMMIT WORK and WAIT)

This called transaction waits for any updates than it produces to be completed.

Execution is slower than with asynchronous updating because called transactions wait
for updating to be completed.

3. L → Local Update

If the data is updated locally, the update of the database will not be processed in a
separate process, the update functions are run in the same dialog process.

Implementation
Step 1 :- Just before the end of loop we will call the Call transaction method using the
internal table of BDCDATA.

Step 2 :- We will use the processing node, update nodes and message internal table to
process all the data.

For the message tab we will go again to the include to fetch its type.

BDC( Batch Data Communication ) in ABAP 14


Mob No :- +916261538504
After Call transaction don’t forget to refresh the internal table of BDCDATA.

Step 3 :- Now to see the contents of messages we will call the MESSAGE_TEXT_BUILD
function module to display the messages.

Code
REPORT ZAR_BDC
NO STANDARD PAGE HEADING LINE-SIZE 255.

TYPES : BEGIN OF TY_MARA,


MATNR TYPE MATNR,
MBRSH TYPE MBRSH,
MTART TYPE MTART,
MAKTX TYPE MAKTX,
MEINS TYPE MEINS,

BDC( Batch Data Communication ) in ABAP 15


Mob No :- +916261538504
END OF TY_MARA.

DATA : LT_MARA TYPE TABLE OF TY_MARA,


LS_MARA TYPE TY_MARA.

DATA : LT_BDCDATA type table of BDCDATA,


LS_BDCDATA type BDCDATA.

DATA : LT_MESSAGE type table of BDCMSGCOLL,


LS_MESSAGE type BDCMSGCOLL.

DATA : LV_MESSAGE TYPE STRING.

DATA : LO_FILE TYPE STRING.


PARAMETERS : P_FILE TYPE LOCALFILE.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.


CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = P_FILE.

START-OF-SELECTION.
LO_FILE = P_FILE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = LO_FILE
* FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = LT_MARA

BDC( Batch Data Communication ) in ABAP 16


Mob No :- +916261538504
* CHANGING
* ISSCANPERFORMED = ' '
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17.

* INCLUDE BDCRECX1.
*
*start-of-selection.
*

LOOP AT LT_MARA INTO LS_MARA.


* PERFORM OPEN_GROUP.
PERFORM BDC_DYNPRO USING 'SAPLMGMM' '0060'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RMMG1-MTART'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'

BDC( Batch Data Communication ) in ABAP 17


Mob No :- +916261538504
'=ENTR'.
PERFORM BDC_FIELD USING 'RMMG1-MATNR'
LS_MARA-MATNR.
PERFORM BDC_FIELD USING 'RMMG1-MBRSH'
LS_MARA-MBRSH.
PERFORM BDC_FIELD USING 'RMMG1-MTART'
LS_MARA-MTART.
PERFORM BDC_DYNPRO USING 'SAPLMGMM' '0070'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=ENTR'.
PERFORM BDC_FIELD USING 'MSICHTAUSW-KZSEL(01)'
'X'.
PERFORM BDC_DYNPRO USING 'SAPLMGMM' '4004'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=BU'.
PERFORM BDC_FIELD USING 'MAKT-MAKTX'
LS_MARA-MAKTX.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'MARA-MEINS'.
PERFORM BDC_FIELD USING 'MARA-MEINS'
LS_MARA-MEINS.
* PERFORM BDC_TRANSACTION USING 'MM01'.
* PERFORM CLOSE_GROUP.

CALL TRANSACTION 'MM01' USING LT_BDCDATA MODE 'A' UPDATE 'S


REFRESH : LT_BDCDATA.
ENDLOOP.

LOOP at LT_MESSAGE into LS_MESSAGE.


CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
MSGID = LS_MESSAGE-MSGID
MSGNR = LS_MESSAGE-MSGNR

BDC( Batch Data Communication ) in ABAP 18


Mob No :- +916261538504
MSGV1 = LS_MESSAGE-MSGV1
MSGV2 = LS_MESSAGE-MSGV2
MSGV3 = LS_MESSAGE-MSGV3
MSGV4 = LS_MESSAGE-MSGV4
IMPORTING
MESSAGE_TEXT_OUTPUT = LV_MESSAGE
.

WRITE :/ LV_MESSAGE.

ENDLOOP.

FORM BDC_DYNPRO USING PROGRAM DYNPRO.


CLEAR LS_BDCDATA.
LS_BDCDATA-PROGRAM = PROGRAM.
LS_BDCDATA-DYNPRO = DYNPRO.
LS_BDCDATA-DYNBEGIN = 'X'.
APPEND LS_BDCDATA to LT_BDCDATA.
ENDFORM.

*---------------------------------------------------------------
* Insert field
*---------------------------------------------------------------
FORM BDC_FIELD USING FNAM FVAL.
CLEAR LS_BDCDATA.
LS_BDCDATA-FNAM = FNAM.
LS_BDCDATA-FVAL = FVAL.
APPEND LS_BDCDATA to LT_BDCDATA.
ENDFORM.

Output

BDC( Batch Data Communication ) in ABAP 19


Mob No :- +916261538504
BDC( Batch Data Communication ) in ABAP 20
Mob No :- +916261538504

You might also like