What Is BDC in SAP ? Types of BDC ?
What Is BDC in SAP ? Types of BDC ?
What Is BDC in SAP ? Types of BDC ?
Batch Data Conversion, this can be called even as Batch Data Communication.
BDC can transfer data from non-sap to sap system and even across sap system.
Using Mapping logic validations can be done in BDC. Mapping logic can transfer data from Internal Table
through application to do validations.
In BDC out bound system (sender) is Flat file and Inbound system (receiver) is SAP
BDCDATA is a structure defined with below fields in data dictionary, it holds the information
related to each screen field .
Use of BDCDATA
It is a structure which holds the information related to each screen i.e. program name, screen no,
field name, field values, information of that particular screen to be transferred into the SAP.
In simple words, it holds all the screen related information and field information to be transferred into
corresponding SAP transaction. Program Dynpro Dynbegin Fnam Fval
SAPLGMM 0060
RMMG1-MATNR "1011"
RMMG1-MBRSH "FOOD"
RMMG1-MTART "FERT"
To find the above information for each field, press F1 on particular field It will display help
information.
Click on the button "technical information".
It will show the entire technical information of a screen.
Please note down the program name, screen number, screen field name.
This procedure has to be repeated for each field on a SAP screen. Since, it is very difficult to
note down the technical information for each field, we have an alternate and easy method called
as "RECORDING METHOD”
BDCDATA is a predefined structure for validations in BDC. Fields for this structure are:
PROGRAM
DYNPRO
DYNBEGIN
FNAM
FVAL
Program: Program means module pool program of application using for validations
Dynpro: provides screen number where data transferring currently
Dynbegin: Means first screen number from application.
Fnam: Means fields from application to do validations
Fval: Means data having in Internal table
BDC(Batch Data Communication) is a batch interfacing technique which is used to insert mass data
into SAP R/3 system, in BDC the data will be loaded into R/3 using SAP Screen which we use to
create a record (Example: Material in MM01).In simple BDC is a technique in SAP, which is used to
upload mass data into R/3 server from a flat file( .txt, Excel etc).
In BDC the data will be flowing in SAP R/3 through screens (Ex: MM01), BDC is a inbound process.
i. This method is compatible to transfer small amount of data and even large amount of
data.
ii. This method is compatible to process data in fore ground and even back ground.
iii. Through this method sap provided log file to store error records.
iv. This method is compatible to handle multiple applications for validations. (for example:
MM01,XK01,XD01 etc..)
v. This method can process data asynchronously and update Database Synchronously.
Note: Asynchronous is faster than synchronous. Process means Transferring the data from Internal
table to Application.
BDC_OPEN_GROUP
BDC_CLOSE_GROUP
BDC_INSERT
BDC_OPEN_GROUP: It maintain sap information to transfer data from Flat file to SAP
Parameters are:
GROUP - it maintains an identity to monitor data uploading. (we can pass our own name and it will
display at sm35 while process)
BDC_INSERT: This provides validations logic based on structure BDCDATA. Parameters are:
Requirement: Upload the flat file data into sap through MM01
MM01.txt
REPORT ZBDC_SESSION_FRG2. Or ZBDC_SESSION_FRG1.
TYPES : BEGIN OF BDC,
MBRSH TYPE RMMG1-MBRSH,
MTART TYPE RMMG1-MTART,
MAKTX TYPE MAKT-MAKTX,
MEINS TYPE MARA-MEINS,
END OF BDC.
DATA : BDCDATA type TABLE OF BDCDATA WITH HEADER LINE.
Or DATA: BDCDATA type TABLE OF BDCDATA,
WA1 like LINE OF BDCDATA.
DATA :IT_BDC type table of BDC,
WA type BDC.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME ='C:\Users\ARSUSER\Desktop\MM01.TXT'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = IT_BDC.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = 'ADIL'
* KEEP = 'X'
USER = SY-UNAME.
LOOP AT IT_BDC INTO WA.
CLEAR BDCDATA.
REFRESH BDCDATA[].
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RMMG1-MBRSH'
wa-MBRSH.
perform bdc_field using 'RMMG1-MTART'
wa-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'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
wa-MAKTX.
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
wa-MEINS.
perform bdc_field using 'MARA-MTPOS_MARA'
'NORM'.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'MM01'
TABLES
DYNPROTAB = BDCDATA.
ENDLOOP.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA. “CLEAR WA1.
BDCDATA-PROGRAM = PROGRAM. “WA1-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO. “WA1-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'. “WA1-DYNBEGIN = 'X'.
APPEND BDCDATA. “APPEND WA1 to BDCDATA.
ENDFORM.
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL IS NOT INITIAL.
CLEAR BDCDATA. “CLEAR WA1.
BDCDATA-FNAM = FNAM. “WA1-FNAM = FNAM.
BDCDATA-FVAL = FVAL. “WA1-FVAL = FVAL.
APPEND BDCDATA. “APPEND WA1 to BDCDATA.
ENDIF.
ENDFORM.
SYNTAX :
CALL TRANSACTION 'TCODE'
USING bdcdata
UPDATE 'A/S'
MODE 'A/E/N'
MESSAGES INTO BDCMSGCOLL .
*T CODE, is a transaction to which we are loading data ex:MM01
*bdcdata is a table which contains data related to each screen
*A/S asynchronous or synchronous method.
*A/E/N Append mode or error screen mode or NO screen mode.
*MESSTAB is a message table to store messages (success, error, warning etc)
UPDATE WORK PROCESS: This work process is responsible for updating the data into the
database.
ASYNCHRONOUS UPDATE (COMMIT):
In this type the call transaction screens will communicate with the update work process to
update the data into database.
It doesn’t wait for the update to be finished.
It immediately starts to process the next record without waiting for the update to be finished.
That’s why this process is very fast.
It is generally not recommended for the large amount of data, because the called transaction
does not return any success or error messages.
In this mode, the called transaction communicates with the update work process to update the
data into database.
It will wait for the update to be finished.
Once the update is finished, then it continues to process the next record.
It is generally recommended for large amount of data because it returns success and error
messages.
MODE:
KNA1.txt
REPORT ZBDC_CALL_TRANSACTION.
Types : BEGIN OF TY_ITAB,
kunnr TYPE KUNNR,
ktokd TYPE KTOKD,
bukrs TYPE BUKRS,
vkorg TYPE VKORG,
vtweg TYPE VTWEG,
spart TYPE SPART,
name1 TYPE NAME1,
land1 TYPE LAND1_gp,
spras TYPE SPRAS,
SORTL type SORTL,
ort01 type ort01,
PSTLZ type PSTLZ,
END OF TY_ITAB.
data: ITAB type TABLE OF ty_itab,
wa type ty_itab.
DATA : BDCDATA TYPE TABLE OF BDCDATA,
wa1 LIKE LINE OF bdcdata.
data: ktab type TABLE OF bdcmsgcoll,
wa_ktab type bdcmsgcoll.
*to download successfull and error records
data: wa_stab type ty_itab,
I_stab type TABLE OF ty_itab,
wa_etab type ty_itab,
i_etab type TABLE OF ty_itab.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\Users\ARSUSER\Desktop\KNA1.txt'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = ITAB.
LOOP AT ITAB INTO wa.
REFRESH BDCDATA.
PERFORM BDC_DYNPRO USING 'SAPMF02D' '0100'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RF02D-REF_KUNNR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
PERFORM BDC_FIELD USING 'RF02D-KUNNR' wa-kunnr.
***PERFORM BDC_DYNPRO USING 'SAPMF02D' '7100'.
PERFORM BDC_FIELD USING 'RF02D-KTOKD' wa-ktokd.
*PERFORM BDC_FIELD USING 'RF02D-KUNNR' ''.
PERFORM BDC_FIELD USING 'RF02D-BUKRS' wa-bukrs.
PERFORM BDC_FIELD USING 'RF02D-VKORG' wa-vkorg.
PERFORM BDC_FIELD USING 'RF02D-VTWEG' wa-vtweg.
PERFORM BDC_FIELD USING 'RF02D-SPART' wa-spart.
PERFORM BDC_DYNPRO USING 'SAPMF02D' '0110'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'KNA1-SPRAS'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=UPDA'.
PERFORM BDC_FIELD USING 'KNA1-NAME1' wa-name1.
PERFORM BDC_FIELD USING 'KNA1-LAND1' wa-land1.
PERFORM BDC_FIELD USING 'KNA1-SPRAS' wa-spras.
PERFORM BDC_FIELD USING 'KNA1-SORTL' wa-sortl.
PERFORM BDC_FIELD USING 'KNA1-ORT01' wa-ort01.
PERFORM BDC_FIELD USING 'KNA1-PSTLZ' wa-pstlz.
CALL TRANSACTION 'XD01' USING BDCDATA MODE 'A' MESSAGES INTO KTAB.
loop at ktab into wa_ktab.
if wa_ktab-msgtyp = 'I' or wa_ktab-msgnr = '000'.
MOVE-CORRESPONDING wa to wa_stab.
append wa_stab to I_stab. " success records
elseif wa_ktab-msgtyp = 'E' or wa_ktab-msgnr = '001'.
MOVE-CORRESPONDING wa to wa_etab.
append wa_etab to I_etab. " error records
endif.
endloop.
ENDLOOP.
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR wa1.
wa1-PROGRAM = PROGRAM.
wa1-DYNPRO = DYNPRO.
wa1-DYNBEGIN = 'X'.
APPEND wa1 to BDCDATA.
ENDFORM.
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> SPACE.
CLEAR wa1.
wa1-FNAM = FNAM.
wa1-FVAL = FVAL.
APPEND wa1 to BDCDATA.
ENDIF.
ENDFORM.
RECORDING METHOD:
Since, it is very difficult to find technical information of each field on the screen; we go for a
method called as "Recording method".
The recording method is going to record all the fields in the transaction and it generated the
technical information such as program name, screen no, field name, field value for each field on
the SAP screen.
By using the recording method, it is very easy to create a BDC program.
A pop up will open, provide a recording name ZSAPN_MM01, provide transaction code as MM01
and click recording.
It will go to material creation screen, provide values for material creation.
A pop up will open, select basic data1 and enter
Click Save, go back, you will go to recording overview screen and click on program button to create
a program for this.
Provide a program name and enter.
report ZSAPN_MM01
no standard page heading line-size 255.
include bdcrecx1.
start-of-selection.
do.
perform close_group.
perform close_dataset using dataset.
Requirement: Create a BDC program with Call Transaction method to migrate (create) material master
basic data using a flat file (.txt with tab delimited).
Requirement analysis: To fulfil the above requirement we need to create recording for MM01 t-
code using SHDB transaction, upload flat file data to a internal table, process using BDC.
Flat file format.
Note:For better understanding, create a material in MM01 with basic data(basic view1 only),
refer Creating material in SAP
Follow the below steps to create a BDC form Material
FILE = P_FILE.
CALL FUNCTION 'GUI_UPLOAD' "upload flat file
EXPORTING
FILENAME = FILE "file name
FILETYPE = 'ASC' "file type
HAS_FIELD_SEPARATOR = 'X' "is tab delimited
TABLES
DATA_TAB = IT_MARA.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
LOOP AT IT_MARA INTO WA_MARA. "loop all 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 material no
PERFORM BDC_FIELD USING 'RMMG1-MBRSH'
WA_MARA-MBRSH. "pass indistry sector
PERFORM BDC_FIELD USING 'RMMG1-MTART'
WA_MARA-MTART. "pass material 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)' "select basic view1
'X'.
PERFORM BDC_DYNPRO USING 'SAPLMGMM' '4004'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=BU'.
PERFORM BDC_FIELD USING 'MAKT-MAKTX'
WA_MARA-MAKTX. "pass material description
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'MARA-MEINS'.
PERFORM BDC_FIELD USING 'MARA-MEINS'
WA_MARA-MEINS. "pass base unit oe meassure
ENDLOOP.
The filnal BDC for migrating Material Master basic data is below
REPORT ZSAPN_BDC
NO STANDARD PAGE HEADING LINE-SIZE 255.
START-OF-SELECTION.
IF P_FILE IS NOT INITIAL.
FILE = P_FILE.
CALL FUNCTION 'GUI_UPLOAD' "upload flat file
EXPORTING
FILENAME = FILE "file name
FILETYPE = 'ASC' "file type
HAS_FIELD_SEPARATOR = 'X' "is tab delimited
TABLES
DATA_TAB = IT_MARA.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.
LOOP AT IT_MARA INTO WA_MARA. "loop all 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 material no
PERFORM BDC_FIELD USING 'RMMG1-MBRSH'
WA_MARA-MBRSH. "pass indistry sector
PERFORM BDC_FIELD USING 'RMMG1-MTART'
WA_MARA-MTART. "pass material 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)' "select basic view1
'X'.
PERFORM BDC_DYNPRO USING 'SAPLMGMM' '4004'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=BU'.
PERFORM BDC_FIELD USING 'MAKT-MAKTX'
WA_MARA-MAKTX. "pass material description
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'MARA-MEINS'.
PERFORM BDC_FIELD USING 'MARA-MEINS'
WA_MARA-MEINS. "pass base unit oe meassure
ENDLOOP.
report ZSAP_MM01
no standard page heading line-size 255.
include bdcrecx1.
TYPES: BEGIN OF TY_MARA, "user defined types as per flat file
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 internal table
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 table
DATA:FILE TYPE STRING. "file name
PARAMETERS : P_FILE TYPE RLGRAP-FILENAME.
*parameters: dataset(132) lower case.
*** DO NOT CHANGE - the generated data section - DO NOT CHANGE ***
*
* If it is nessesary to change the data section use the rules:
* 1.) Each definition of a field exists of two lines
* 2.) The first line shows exactly the comment
* '* data element: ' followed with the data element
* which describes the field.
* If you don't have a data element use the
* comment without a data element name
* 3.) The second line shows the fieldname of the
* structure, the fieldname must consist of
* a fieldname and optional the character '_' and
* three numbers and the field length in brackets
* 4.) Each field must be type C.
*
*** Generated data section with specific formatting - DO NOT CHANGE ***
data: begin of record,
** data element: MATNR
* MATNR_001(018),
** data element: MBRSH
* MBRSH_002(001),
** data element: MTART
* MTART_003(004),
* data element: XFELD
KZSEL_01_004(001),
** data element: MAKTX
* MAKTX_005(040),
** data element: MEINS
* MEINS_006(003),
** data element: MTPOS_MARA
MTPOS_MARA_007(004),
end of record.
*** End generated data section ***
AT SELECTION-SCREEN on VALUE-REQUEST FOR P_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
FIELD_NAME = 'P_FILE'
IMPORTING
FILE_NAME = P_FILE.
start-of-selection.
IF P_FILE IS NOT INITIAL.
FILE = P_FILE.
CALL FUNCTION 'GUI_UPLOAD' "upload flat file
EXPORTING
FILENAME = FILE "file name
FILETYPE = 'ASC' "file type
HAS_FIELD_SEPARATOR = 'X' "is tab delimited
TABLES
DATA_TAB = IT_MARA.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.
*perform open_dataset using dataset.
*perform open_group.
*do.
*read dataset dataset into record.
*if sy-subrc <> 0. exit. endif.
LOOP AT IT_MARA INTO WA_MARA. "loop all 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.
perform bdc_field using 'RMMG1-MBRSH'
wa_mara-MBRSH.
perform bdc_field using 'RMMG1-MTART'
wa_mara-MTART.
perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(02)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
record-KZSEL_01_004.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
wa_mara-MAKTX.
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
wa_mara-MEINS.
perform bdc_field using 'MARA-MTPOS_MARA'
record-MTPOS_MARA_007.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_transaction using 'MM01'.
*enddo.
CALL TRANSACTION 'MM01' USING IT_BDCDATA "call transaction
MODE 'N' "N-no screen mode, A-all screen mode, E-
error screen mode
UPDATE 'A' "A-assynchronous, S-synchronous
MESSAGES INTO BDCMSG. "messages
IF SY-SUBRC EQ 0.
WRITE :/ WA_MARA-MATNR, 'submitted to BDC'.
ENDIF.
endloop.
*perform close_group.
*perform close_dataset using dataset.
DATA : WA_BDCMSG LIKE LINE OF BDCMSG.
IF BDCMSG IS NOT INITIAL. "display 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.
To read data from a file on the application server, use the READ DATASET statement:
Syntax
READ DATASET <dsn> INTO <f> [LENGTH <len>].
like, u get 5 records in table control in one screen, and some other records in other screen, to avoid
this screen resolution problem we use CTU-PARAMS Structure.
In our program we have to set CTU_PARAMS-defsize = 'X' (‘X’ is a Standard size, ‘ ‘ space is
current size)
Then we will be free of screen resolution problem.
Data: wa_opt type CTU_PARAMS. ( work area is defined to screen resolution)
----
Wa_opt-DEFSIZE = ‘X’
Call transaction 'MM01' using t_bdcdata option from wa_opt.
In case of Session Method, need to tick the check box ‘Dynpro Standard size’ in Recording
LSMW : stands for Legacy System Migration Workbench. Legacy system means Non-sap system.
This is data migration tool, designed by sap for Functional consultants.