15-Batch Data Communication
description
Transcript of 15-Batch Data Communication
Batch Data CommunicationData migration using BDC (Batch Data Communication) using recording method, call transaction, session method
BDC and Methods of BDCBatch Data Communication(BDC) in SAP, transfer data to SAP using BDC methods
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 loded 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.
The BDC can be performed in two methods:
Call Transaction. Session Method.
Call Transaction and Session Method differences.
Call Transaction method in BDCCALL TRANSACTION METHOD:
It is the process of transferring the data from flat file into SAP by calling a transaction through a series of sequence of steps.
Properties of call transaction method
This method is used for transferring less amount of data(<10,000 records). This method uses Synchronous and Asynchronous updates.
This method will update the DB immediately.
We need to handle the errors and the success messages by declaring an internal table of type BDCMSGCOLL.
This method is very fast.
CALL TRANSACTION '<T CODE>'
USING <bdcdata>
UPDATE '<A/S>'
MODE '<A/E/N>'
MESSAGES INTO <MESSTAB> .
*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 all screen mode or error screen mode or no screen mode.
*MESSTAB is a message table to store messages (success, error, warning etc)
BDCDATA is a structure defined with below fields in data dictionary, it holds the information related to each screen field .
Program - Name of the program. Dynpro - Screen Number.
Dynbegin - Start the process.
Fnam - Field name on the SAP screen.
Fval - Field value on to the field name of SAP screen.
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 "X"
RMMG1-MATNR "1011"
RMMG1-MBRSH "FOOD"
RMMG1-MTART "FERT"
SAPLGMM 0070 "X" RZSEL "X"
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"Â.
Update: There are two types of updates are available.
Asynchronous update (COMMIT).Synchronous update (COMMIT & WAIT).
DIALOG WORK PROCESS: A work process which is dedicated to process screen information is called "Dialog work process"Â.There will be 6 to 7 dialog work processes.
These dialog work processes are defined by basis consultant.
UPDATE WORK PROCESS: This work process is responsible for updating the data into the database.
There will be always only "1" update work process.
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.
SYNCHRONOUS UPDATE (COMMIT & WAIT):
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.
That’s why this process is very slow.
It is generally recommended for large amount of data because it returns success and error messages.
MODE:
It specifies the type of the mode to execute the transaction.
There are 3 options for mode
A All screen mode(Foreground). E Error screen mode (only error screens will be displayed).
N No screen mode (Background).
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.
Recording a transaction using SHDBRECORDING 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.
Steps for recording a transaction.
SHDB is the T-code for recording method, go to SHDB, list of recordings will be displayed( if any), click on New Recording to create new recording.
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
Enter below details.
Click Save( Ctrl S), it will go to a screen with recording code.
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.
Provide title, type and click on source code.
Save it in a local object, you will find the below code in the program
report ZSAPN_MM01
no standard page heading line-size 255.
include bdcrecx1.
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: MATNR
MATNR_005(018),
* data element: MBRSH
MBRSH_006(001),
* data element: MTART
MTART_007(004),
* data element: XFELD
KZSEL_01_008(001),
* data element: MAKTX
MAKTX_009(040),
* data element: MEINS
MEINS_010(003),
end of record.
*** End generated data section ***
start-of-selection.
perform open_dataset using dataset.
perform open_group.
do.
read dataset dataset into record.
if sy-subrc <> 0. exit. endif.
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'
record-MATNR_001.
perform bdc_field using 'RMMG1-MBRSH'
record-MBRSH_002.
perform bdc_field using 'RMMG1-MTART'
record-MTART_003.
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)'
record-KZSEL_01_004.
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MATNR'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'RMMG1-MATNR'
record-MATNR_005.
perform bdc_field using 'RMMG1-MBRSH'
record-MBRSH_006.
perform bdc_field using 'RMMG1-MTART'
record-MTART_007.
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)'
record-KZSEL_01_008.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_009.
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
record-MEINS_010.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_transaction using 'MM01'.
enddo.
perform close_group.
perform close_dataset using dataset.
BDC call transaction for Material Master MM01BDC call transaction method for migrating Material Master data using MM01 transaction
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
Create recording for MM01 transaction
Create recording for material master MM01 with material basic data i:e basic view1, copy the code to create a new programMM01 recording with material basic data , the below code will be generated.Try to understand the below code (explained)
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'
record-MATNR_001. "pass material no
perform bdc_field using 'RMMG1-MBRSH'
record-MBRSH_002. "pass industry sector
perform bdc_field using 'RMMG1-MTART'
record-MTART_003. "pass material type
perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_field using 'BDC_OKCODE' "enter
'=ENTR'.
perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
record-KZSEL_01_004. "basic view1 pass 'X'
perform bdc_dynpro using 'SAPLMGMM' '4004'. "calling second screen (basic view1)
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_005. "material description
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'. "base unit of meassure
perform bdc_field using 'MARA-MEINS'
record-MEINS_006.
perform bdc_transaction using 'MM01'. "finally calling transaction
Add data declerations
Add required data declerations for material data as per flat file
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. "input parameter for file upload
Upload data from flat file
Upload data into a internal table from a flat file using GUI_UPLOAD, all BDC performs are available in standard programs, simply double click on each perform and copy from standard program, paste at the bottom.
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.
Process records one by one to BDC
Loop through internal table and pass records to BDC call transaction.
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
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.
The filnal BDC for migrating Material Master basic data is below
REPORT ZSAPN_BDC
NO STANDARD PAGE HEADING LINE-SIZE 255.
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. "input parameter for file upload
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
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.
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.
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR WA_BDCDATA.
WA_BDCDATA-PROGRAM = PROGRAM. "program
WA_BDCDATA-DYNPRO = DYNPRO. "screen
WA_BDCDATA-DYNBEGIN = 'X'. "begin
APPEND WA_BDCDATA TO IT_BDCDATA..
ENDFORM.
FORM BDC_FIELD USING FNAM FVAL.
* IF FVAL <> NODATA.
CLEAR WA_BDCDATA.
WA_BDCDATA-FNAM = FNAM. "field name ex: matnr
WA_BDCDATA-FVAL = FVAL. "field value ex: testmat001
APPEND WA_BDCDATA TO IT_BDCDATA.
* ENDIF.
ENDFORM.