You are on page 1of 19

BDC

BDC(Batch Data Communcaton) s a batch nterfacng technque whch s used to nsert


mass data nto SAP R/3 system, n BDC the data w be oded nto R/3 usng SAP Screen
whch we use to create a record(Exampe: Matera n MM01).In smpe BDC s a
technque n SAP, whch s used to upoad mass data nto R/3 server from a at e( .txt,
Exce etc).
In BDC the data w be owng n SAP R/3 through screens (Ex: MM01), BDC s a nbound
process.
The BDC can be performed n two methods:
Ca Transacton.
Sesson Method.
Ca Transacton and Sesson Method dherances.
+ -
CALL TRANSACTION METHOD:
It s the process of transferrng the data from at e nto SAP by cang a transacton
through a seres of sequence of steps.
Propertes of ca transacton method
Ths method s used for transferrng ess amount of data(<10,000 records).
Ths method uses Synchronous and Asynchronous updates.
Ths method w update the DB mmedatey.
We need to hande the errors and the success messages by decarng an nterna
tabe of type BDCMSGCOLL.
Ths method s very fast.
CALL TRANSACTION '<T CODE>'
USING <bdcdata>
UPDATE '<A/S>'
MODE '<A/E/N>'
MESSAGES INTO <MESSTAB> .
*T CODE, s a transacton to whch we are oadng data ex:MM01
*bdcdata s a tabe whch contans data reated to each screen
*A/S asynchronous or synchronous method.
*A/E/N a screen mode or error screen mode or no screen mode.
*MESSTAB s a message tabe to store messages (success, error, warnng etc)
BDCDATA s a structure dened wth beow eds n data dctonary, t hods the
nformaton reated to each screen ed .
Program - Name of the program.
Dynpro - Screen Number.
Dynbegn - Start the process.
Fnam - Fed name on the SAP screen.
Fva - Fed vaue on to the ed name of SAP screen.
Use of BDCDATA
It s a structure whch hods the nformaton reated to each screen .e. program name,
screen no, ed name, ed vaues, nformaton of that partcuar screen to be
transferred nto the SAP.
In smpe words, t hods a the screen reated nformaton and ed nformaton to be
transferred nto correspondng SAP transacton. Program Dynpro Dynbegn Fnam Fva
SAPLGMM 0060 CXC
RMMG1-MATNR C1011C
RMMG1-MBRSH CFOODC
RMMG1-MTART CFERTC
SAPLGMM 0070 CXC RZSEL CXC
To nd the above nformaton for each ed, press F1 on partcuar ed It w dspay
hep nformaton.
Cck on the button Cotechnca nformatonC .
It w show the entre technca nformaton of a screen.
Pease note down the program name, screen number, screen ed name.
Ths procedure has to be repeated for each ed on a SAP screen.Snce, t s very dmcut
to note down the technca nformaton for each ed, we have an aternate and easy
method caed as CoRECORDING METHODC .
Update: There are two types of updates are avaabe.
Asynchronous update (COMMIT).
Synchronous update (COMMIT & WAIT).
DIALO WO!" #!OC$SS: A work process whch s dedcated to process screen
nformaton s caed CoDaog work processC .
There w be 6 to 7 daog work processes.
These daog work processes are dened by bass consutant.
U#DAT$ WO!" #!OC$SS: Ths work process s responsbe for updatng the data nto
the database.
There w be aways ony C1C update work process.
ASYNCHRONOUS UPDATE (COMMIT):
In ths type the ca transacton screens w communcate wth the update work
process to update the data nto database.
It doesnCt wat for the update to be nshed.
It mmedatey starts to process the next record wthout watng for the update to
be nshed.
ThatCs why ths process s very fast.
It s generay not recommended for the arge amount of data, because the caed
transacton doesnCt return any success or error messages.
SYNCHRONOUS UPDATE (COMMIT & WAIT):
In ths mode, the caed transacton communcates wth the update work process
to update the data nto database.
It w wat for the update to be nshed.
Once the update s nshed, then t contnues to process the next record.
ThatCs why ths process s very sow.
It s generay recommended for arge amount of data because t returns success
and error messages.
MODE:
It speces the type of the mode to execute the transacton.
There are 3 optons for mode
A A screen mode(Foreground).
E Error screen mode (ony error screens w be dspayed).
N No screen mode (Background).
RECORDING METHOD:
Snce, t s very dmcut to nd technca nformaton of each ed on the screen, we go
for a method caed as CoRecordng methodC .
The recordng method s gong to record a the eds n the transacton and t generated
the technca nformaton such as program name, screen no, ed name, ed vaue for
each ed on the SAP screen.
By usng the recordng method, t s very easy to create a BDC program.
+ -
RECORDING METHOD:
Snce, t s very dmcut to nd technca nformaton of each ed on the screen, we go
for a method caed as CoRecordng methodC .
The recordng method s gong to record a the eds n the transacton and t generated
the technca nformaton such as program name, screen no, ed name, ed vaue for
each ed on the SAP screen.
By usng the recordng method, t s very easy to create a BDC program.
Steps for recordng a transacton.
SHDB s the T-code for recordng method, go to SHDB, st of recordngs w be
dspayed( f any), cck on New Recordng to create new recordng.
A pop up w open, provde a recordng name ZSAPN_MM01, provde transacton code as
MM01 and cck recordng.
It w go to matera creaton screen, provde vaues for matera creaton.
A pop up w open, seect basc data1 and enter
Enter beow detas.
Cck Save( Ctr S), t w go to a screen wth recordng code.
Cck Save, go back, you w go to recordng overvew screen and cck on program
button to create a program for ths.
Provde a program name and enter.
Provde tte, type and cck on source code.
Save t n a oca ob|ect, you w nd the beow code n the program
report ZSAPN_MM01
no standard page headng ne-sze 255.
ncude bdcrecx1.
parameters: dataset(132) ower case.
*** DO NOT CHANGE - the generated data secton - DO NOT CHANGE ***
*
* If t s nessesary to change the data secton use the rues:
* 1.) Each denton of a ed exsts of two nes
* 2.) The rst ne shows exacty the comment
* '* data eement: ' foowed wth the data eement
* whch descrbes the ed.
* If you don't have a data eement use the
* comment wthout a data eement name
* 3.) The second ne shows the edname of the
* structure, the edname must consst of
* a edname and optona the character '_' and
* three numbers and the ed ength n brackets
* 4.) Each ed must be type C.
*
*** Generated data secton wth specc formattng - DO NOT CHANGE ***
data: begn of record,
* data eement: MATNR
MATNR_001(018),
* data eement: MBRSH
MBRSH_002(001),
* data eement: MTART
MTART_003(004),
* data eement: XFELD
KZSEL_01_004(001),
* data eement: MATNR
MATNR_005(018),
* data eement: MBRSH
MBRSH_006(001),
* data eement: MTART
MTART_007(004),
* data eement: XFELD
KZSEL_01_008(001),
* data eement: MAKTX
MAKTX_009(040),
* data eement: MEINS
MEINS_010(003),
end of record.
*** End generated data secton ***
start-of-seecton.
perform open_dataset usng dataset.
perform open_group.
do.
read dataset dataset nto record.
f sy-subrc <> 0. ext. endf.
perform bdc_dynpro usng 'SAPLMGMM' '0060'.
perform bdc_ed usng 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_ed usng 'BDC_OKCODE'
'=ENTR'.
perform bdc_ed usng 'RMMG1-MATNR'
record-MATNR_001.
perform bdc_ed usng 'RMMG1-MBRSH'
record-MBRSH_002.
perform bdc_ed usng 'RMMG1-MTART'
record-MTART_003.
perform bdc_dynpro usng 'SAPLMGMM' '0070'.
perform bdc_ed usng 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_ed usng 'BDC_OKCODE'
'=ENTR'.
perform bdc_ed usng 'MSICHTAUSW-KZSEL(01)'
record-KZSEL_01_004.
perform bdc_dynpro usng 'SAPLMGMM' '0060'.
perform bdc_ed usng 'BDC_CURSOR'
'RMMG1-MATNR'.
perform bdc_ed usng 'BDC_OKCODE'
'=ENTR'.
perform bdc_ed usng 'RMMG1-MATNR'
record-MATNR_005.
perform bdc_ed usng 'RMMG1-MBRSH'
record-MBRSH_006.
perform bdc_ed usng 'RMMG1-MTART'
record-MTART_007.
perform bdc_dynpro usng 'SAPLMGMM' '0070'.
perform bdc_ed usng 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_ed usng 'BDC_OKCODE'
'=ENTR'.
perform bdc_ed usng 'MSICHTAUSW-KZSEL(01)'
record-KZSEL_01_008.
perform bdc_dynpro usng 'SAPLMGMM' '4004'.
perform bdc_ed usng 'BDC_OKCODE'
'/00'.
perform bdc_ed usng 'MAKT-MAKTX'
record-MAKTX_009.
perform bdc_ed usng 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_ed usng 'MARA-MEINS'
record-MEINS_010.
perform bdc_dynpro usng 'SAPLSPO1' '0300'.
perform bdc_ed usng 'BDC_OKCODE'
'=YES'.
perform bdc_transacton usng 'MM01'.
enddo.
perform cose_group.
perform cose_dataset usng dataset.
In next essons we w earn how to use recordng for BDC.
+ -
Requrement: Create a BDC program wth Ca Transacton method to mgrate(create)
matera master basc data usng a at e(.txt wth tab demted).
!e%u&re'ent ana(ys&s: To fu the above requrement we need to create recordng for
MM01 t-code usng SHDB transacton, upoad at e data to a nterna tabe, process
usng BDC.
Fat e format.
)ote:For better understandng, create a matera n MM01 wth basc data(basc vew1
ony), refer Creatng matera n SAP
Foow the beow steps to create a BDC form Matera
Create recordng for MM01 transacton
Create recordng for matera master MM01 wth matera basc data :e basc vew1,
copy the code to create a new program MM01 recordng wth matera basc data , the
beow code w be generated.Try to understand the beow code (expaned)
perform bdc_dynpro usng 'SAPLMGMM' '0060'.
perform bdc_ed usng 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_ed usng 'BDC_OKCODE'
'ENTR'.
perform bdc_ed usng 'RMMG1-MATNR'
record-MATNR_001. "pass matera no
perform bdc_ed usng 'RMMG1-MBRSH'
record-MBRSH_002. "pass ndustry sector
perform bdc_ed usng 'RMMG1-MTART'
record-MTART_003. "pass matera type
perform bdc_dynpro usng 'SAPLMGMM' '0070'.
perform bdc_ed usng 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_ed usng 'BDC_OKCODE' "enter
'=ENTR'.
perform bdc_ed usng 'MSICHTAUSW-KZSEL(01)'
record-KZSEL_01_004. "basc vew1 pass 'X'
perform bdc_dynpro usng 'SAPLMGMM' '4004'. "cang second screen (basc vew1)
perform bdc_ed usng 'BDC_OKCODE'
'=BU'.
perform bdc_ed usng 'MAKT-MAKTX'
record-MAKTX_005. "matera descrpton
perform bdc_ed usng 'BDC_CURSOR'
'MARA-MEINS'. "base unt of meassure
perform bdc_ed usng 'MARA-MEINS'
record-MEINS_006.
perform bdc_transacton usng 'MM01'. "nay cang transacton
Add data deceratons
Add requred data deceratons for matera data as per at e
TYPES: BEGIN OF TY_MARA, "user dened types as per at e
MATNR TYPE MARA-MATNR,
MBRSH TYPE MARA-MBRSH,
MTART TYPE MARA-MTART,
MEINS TYPE MARA-MEINS,
MAKTX TYPE MAKT-MAKTX,
END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA, "mara nterna tabe
WA_MARA TYPE TY_MARA. "mara work area
DATA: IT_BDCDATA TYPE TABLE OF BDCDATA . "BDCDATA
DATA: WA_BDCDATA TYPE BDCDATA . "work area BDCDATA
DATA : BDCMSG TYPE TABLE OF BDCMSGCOLL. "BDC message tabe
DATA:FILE TYPE STRING. "e name
PARAMETERS : P_FILE TYPE RLGRAP-FILENAME. "nput parameter for e upoad
Upoad data from at e
Upoad data nto a nterna tabe from a at e usng GUI_UPLOAD, a BDC performs are
avaabe n standard programs, smpey doube cck on each perform and copy from
standard program, paste at the bottom.
FILE = P_FILE.
CALL FUNCTION 'GUI_UPLOAD' "upoad at e
EXPORTING
FILENAME = FILE "e name
FILETYPE = 'ASC' "e type
HAS_FIELD_SEPARATOR = 'X' "s tab demted
TABLES
DATA_TAB = IT_MARA.
IF SY-SUBRC <> 0.
* Impement sutabe error handng here
ENDIF.
Process records one by one to BDC
Loop through nterna tabe and pass records to BDC ca transacton.
LOOP AT IT_MARA INTO WA_MARA. "oop a records and pass one by one to BDC
PERFORM BDC_DYNPRO USING 'SAPLMGMM' '0060'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RMMG1-MTART'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'ENTR'.
PERFORM BDC_FIELD USING 'RMMG1-MATNR'
WA_MARA-MATNR. "pass matera no
PERFORM BDC_FIELD USING 'RMMG1-MBRSH'
WA_MARA-MBRSH. "pass ndstry sector
PERFORM BDC_FIELD USING 'RMMG1-MTART'
WA_MARA-MTART. "pass matera type
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)' "seect basc vew1
'X'.
PERFORM BDC_DYNPRO USING 'SAPLMGMM' '4004'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=BU'.
PERFORM BDC_FIELD USING 'MAKT-MAKTX'
WA_MARA-MAKTX. "pass matera descrpton
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'MARA-MEINS'.
PERFORM BDC_FIELD USING 'MARA-MEINS'
WA_MARA-MEINS. "pass base unt oe meassure
CALL TRANSACTION 'MM01' USING IT_BDCDATA "ca transacton
MODE 'N' "N-no screen mode, A-a screen mode, E-error screen mode
UPDATE 'A' "A-assynchronous, S-synchronous
MESSAGES INTO BDCMSG. "messages
IF SY-SUBRC EO 0.
WRITE :/ WA_MARA-MATNR, 'submtted to BDC'.
ENDIF.
ENDLOOP.
The na BDC for mgratng Matera Master basc data s beow
REPORT ZSAPN_BDC
NO STANDARD PAGE HEADING LINE-SIZE 255.
TYPES: BEGIN OF TY_MARA, "user dened types as per at e
MATNR TYPE MARA-MATNR,
MBRSH TYPE MARA-MBRSH,
MTART TYPE MARA-MTART,
MEINS TYPE MARA-MEINS,
MAKTX TYPE MAKT-MAKTX,
END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA, "mara nterna tabe
WA_MARA TYPE TY_MARA. "mara work area
DATA: IT_BDCDATA TYPE TABLE OF BDCDATA . "BDCDATA
DATA: WA_BDCDATA TYPE BDCDATA . "work area BDCDATA
DATA : BDCMSG TYPE TABLE OF BDCMSGCOLL. "BDC message tabe
DATA:FILE TYPE STRING. "e name
PARAMETERS : P_FILE TYPE RLGRAP-FILENAME. "nput parameter for e upoad
START-OF-SELECTION.
IF P_FILE IS NOT INITIAL.
FILE = P_FILE.
CALL FUNCTION 'GUI_UPLOAD' "upoad at e
EXPORTING
FILENAME = FILE "e name
FILETYPE = 'ASC' "e type
HAS_FIELD_SEPARATOR = 'X' "s tab demted
TABLES
DATA_TAB = IT_MARA.
IF SY-SUBRC <> 0.
* Impement sutabe error handng here
ENDIF.
ENDIF.
LOOP AT IT_MARA INTO WA_MARA. "oop a records and pass one by one to BDC
PERFORM BDC_DYNPRO USING 'SAPLMGMM' '0060'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RMMG1-MTART'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'ENTR'.
PERFORM BDC_FIELD USING 'RMMG1-MATNR'
WA_MARA-MATNR. "pass matera no
PERFORM BDC_FIELD USING 'RMMG1-MBRSH'
WA_MARA-MBRSH. "pass ndstry sector
PERFORM BDC_FIELD USING 'RMMG1-MTART'
WA_MARA-MTART. "pass matera type
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)' "seect basc vew1
'X'.
PERFORM BDC_DYNPRO USING 'SAPLMGMM' '4004'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=BU'.
PERFORM BDC_FIELD USING 'MAKT-MAKTX'
WA_MARA-MAKTX. "pass matera descrpton
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'MARA-MEINS'.
PERFORM BDC_FIELD USING 'MARA-MEINS'
WA_MARA-MEINS. "pass base unt oe meassure
CALL TRANSACTION 'MM01' USING IT_BDCDATA "ca transacton
MODE 'N' "N-no screen mode, A-a screen mode, E-error screen mode
UPDATE 'A' "A-assynchronous, S-synchronous
MESSAGES INTO BDCMSG. "messages
IF SY-SUBRC EO 0.
WRITE :/ WA_MARA-MATNR, 'submtted to BDC'.
ENDIF.
ENDLOOP.
DATA : WA_BDCMSG LIKE LINE OF BDCMSG.
IF BDCMSG IS NOT INITIAL. "dspay messages
LOOP AT BDCMSG INTO WA_BDCMSG.
WRITE:/ WA_BDCMSG-TCODE, WA_BDCMSG-MSGTYP, WA_BDCMSG-MSGV1, WA_BDCMSG-
FLDNAME .
CLEAR WA_BDCMSG.
ENDLOOP.
ENDIF.
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR WA_BDCDATA.
WA_BDCDATA-PROGRAM = PROGRAM. "program
WA_BDCDATA-DYNPRO = DYNPRO. "screen
WA_BDCDATA-DYNBEGIN = 'X'. "begn
APPEND WA_BDCDATA TO IT_BDCDATA..
ENDFORM.
FORM BDC_FIELD USING FNAM FVAL.
* IF FVAL <> NODATA.
CLEAR WA_BDCDATA.
WA_BDCDATA-FNAM = FNAM. "ed name ex: matnr
WA_BDCDATA-FVAL = FVAL. "ed vaue ex: testmat001
APPEND WA_BDCDATA TO IT_BDCDATA.
* ENDIF.
ENDFORM.

You might also like