Batch Data
Communication
BDC Overview
Overview
It is the technique of transferring in data from legacy system (NON-SAP) to SAP is called BDC.
There are two techniques available for transferring data.
Outbound process
Inbound process
OUTBOUND PROCESS:
The process of transferring the data from SAP to NON-SAP or another SAP server is called “Outbound Process”.
BDC Overview
INBOUND PROCESS
The process of receiving the data from NON-SAP to SAP server is
called as “Inbound Process”.
BDC is an “Inbound Process”.
BDC Overview
DIFFERENT METHODS OF BDC:
Call transaction (Screen Level Processing)
Session method (Screen Level Processing)
Direct input method->(Standard SAP Programs)
LSMW -> (A tool)
BDC Overview
Few Standard Transactions for performing Business Activities
Create Change Display New Transactions
Customer XD01 XD02 XD03 BP
Vendor XK01 XK02 XK03 BP
Material MM01 MM02 MM03
Sales order VA01 VA02 VA03
Purchase order ME21 ME22 ME23 ME21N
Delivery Order VL01 VL02 VL03
Billing order VF01 VF02 VF03
Call Transaction Method
Call Transaction Method
CALL 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:
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 Method
Syntax:
Call Transaction <Tcode>
Using <BDC DATA>
UPDATE <A/S>
MODE <A/E/N>
MESSAGES INTO <Message Internal Table>
BDC Data
BDC Data:
It is a structure defined in a data dictionary with the below fields.
Program -> Name of the program of a screen
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 BDC DATA:
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.
BDC Data
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’
- - - - -
- - - - -
BDC Data
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 in BDC
Update: There are two types of updates are available.
Asynchronous update (COMMIT)
Synchronous update (COMMIT & WAIT)
DIAL0G 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.
Update in BDC
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 doesn’t return any success or error messages.
Update in BDC
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.
Modes in Call Transactions
MODE:
It specifies the type of the mode to execute the transaction.
There are 3 options for mode
__________________________________________________________
_
MODE DESCRIPTION
__________________________________________________________
_
A All screen mode(Foreground)
E Error screen mode (only error screens will be
displayed)
N No screen mode (Background)
Messages in Call Transaction
MESSAGES:
In the called transaction, we need to handle the messages by declaring
an internal table of type BDCMSGCOLL.
All the messages will be stored in the above internal table.
The structure of BDCMSGCOLL is as below:
MSGTYP Message type(E-error, S-success W –Warning etc..)
MSGID Message ID
MSGNR Message number
MSGV1 Variable part of a message
MSGV2 Variable part of a message
MSGV3 Variable part of a message
MSGV4 Variable part of a message
Messages in Call Transaction
The variable BDCMSGCOLL – MSGV1 will contain the created material
number or vendor number whenever the message type is success (S).
Whenever the message type is error, we need to use the function module
FORMAT_MESSAGE to display the meaningful message.
Recording Method
Recording Method
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.
Steps to Create a Material
Go to MM01
Give the industry sector as Pharmaceuticals.
Give the material type as coupons.
Click on the button ‘select views’
Select the checkbox ‘Basic Data1’
Click on continue button.
Give the description as ‘Test material’.
Give the units as ‘Kgs’.
Click on save.
A message will be displayed with text as ‘Material 1427 is created’.
Steps for Recording
Steps for the Recording:
Go to SHDB
Click on new recording
Give the recording name. eg:YMM01
Give the transaction code. Eg: MM01
Click on the button start recording.
MM01 will be displayed.
Enter the industry sector as Pharmaceuticals
Enter the material type as coupons.
Click on ‘select view’ button.
Steps for Recording
Select the checkbox Basic Data1.
Click on continue button.
Give the description as ‘Test material’.
Give the units as ‘Kgs’ and click on Save.
The recording will display all the technical information.
Click on save
Click on back
Select the recording
Click on the button create program
Give the program name
Steps for Recording
Select the button ‘transfer from recording’.
Press enter
Give the title
Click on the button ‘Source Code’.
The code will be generated as below.
Perform BDC-Dynpro using ‘SAPLGMM’ ‘0060’.
Perform BDC-Field using ‘BDC_CURSOR’
‘RMMG1-MRART’.
“
“
Steps for Recording
FORM bdc_dynpro using program dynpro.
Clear BDCDATA.
BDCDATA-program = program.
BDCDATA-dynpro = dynpro.
BDCDATA-dynbegin = ‘x’.
Append BDCDATA.
ENDFORM.
Steps for Recording
*INSERT FIELD.
FORM bdc_field using FNAM FVAL.
Clear BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
Append BDCDATA.
ENDFORM.
Steps To Create a BDC Program
Steps to create a BDC program:
Create the recording for the transaction
Create an internal table of type flat file structure
Upload the data from flat file into the internal table using GUI_UPLOAD
Loop at I_FILE into WA_FILE
***Copy the code generated from Recording and paste it here
Perform BDC-Dynpro using <Prg name> <Scrn No>
Perform BDC-Field using <fnam> <fval>
Steps To Create a BDC Program
Call transaction ‘tcode’ Call the transaction
Using BDCDATA
Update A/S
Mode A/E/N
Message into MESSTAB.
If SY-SUBRC = 0.
Perform display_success_rec. Subroutine for SUCCES rec’s
Else
Perform display_error_rec. Subroutine for ERROR rec’s
Endif.
Steps To Create a BDC Program
Form display_success_rec.
Read table MESSTAB
With key MSGTYP = ‘S’.
…….
Endform.
Form display_error_rec.
Loop at MESSTAB where MSGTYP = ‘E’.
Call function ‘FORMAT_MESSAGE’.
……..
Endloop.
Endform.
Example program on Call transaction
Example program on Call transaction
BReq : Upload material master data from flat file given
as below
FLAT FILE SHOULD BE AS BELOW
**********************************************
*******************
Indsector Mattype desc
units
P
COUP DESC5 KGS
P
COUP DESC6 KGS
P
COUP DESC7 KGx
P
COUP DESC8 KGS
Example program on Call transaction
TYPES : BEGIN OF TY_FILE,
MBRSH TYPE MARA-MBRSH,
MTART TYPE MARA-MTART,
MAKTX TYPE MAKT-MAKTX,
MEINS TYPE MARA-MEINS,
END OF TY_FILE.
DATA : I_FILE TYPE TABLE OF TY_FILE .
DATA : WA_FILE TYPE TY_FILE .
DATA : LV_MSG TYPE STRING .
**********************BDC DATA DECLARARATIONS
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
Example program on Call transaction
BREAK-POINT .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\MARADATA.TXT'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = I_FILE.
Example program on Call transaction
LOOP AT I_FILE INTO WA_FILE .
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_field using 'BDC_OKCODE'
'=AUSW'.
perform bdc_field using 'RMMG1-MBRSH'
WA_FILE-MBRSH.
perform bdc_field using 'RMMG1-MTART'
WA_FILE-MTART.
Example program on Call transaction
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'
WA_FILE-MAKTX.
Example program on Call transaction
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
WA_FILE-MEINS.
perform bdc_field using 'MARA-MTPOS_MARA'
'NORM'.
CALL TRANSACTION 'MM01'
USING bdcdata
UPDATE 'A'
MODE 'N'
MESSAGES INTO MESSTAB .
If SY-SUBRC = 0.
Perform display_success_rec.
Else .
Perform display_error_rec.
Endif.
Example program on Call transaction
CLEAR WA_FILE .
REFRESH BDCDATA.
CLEAR BDCDATA.
REFRESH MESSTAB .
CLEAR MESSTAB.
ENDLOOP .
Example program on Call transaction
*----------------------------------------------------------------------*
*
Start new screen *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.
"BDC_DYNPRO
Example program on Call transaction
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FNAM text
* -->FVAL text
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
* IF FVAL <> NODATA.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
* ENDIF.
ENDFORM. "BDC_FIELD
Example program on Call transaction
*&---------------------------------------------------------------------*
*&
Form display_success_rec
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM display_success_rec .
READ TABLE MESSTAB WITH KEY MSGTYP = 'S' .
WRITE : / 'material is created with no:' , messtab-msgv1 COLOR 5.
ENDFORM.
Example program on Call transaction
FORM display_error_rec .
LOOP AT MESSTAB WHERE MSGTYP = 'E' .
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = MESSTAB-MSGID
LANG = 'E'
NO = MESSTAB-MSGNR
V1 = MESSTAB-MSGV1
V2 = MESSTAB-MSGV2
V3 = MESSTAB-MSGV3
V4 = MESSTAB-MSGV4
IMPORTING
MSG = LV_MSG.
WRITE / lv_msg COLOR 6.
ENDLOOP .
ENDFORM. " display_error_rec
Session Method
SESSION METHOD
Session Method
SESSION METHOD:
This method is used to transfer large amount of data (eg: >10,000 to 10
lakhs)
It is basically a 2 step process
Create a session
Process a session
Session: a session contains a group of records, which have to be
transferred into SAP.
To create a session, we use the below function modules.
BDC_Opengroup
BDC_Insert
BDC_Closegroup
Session Method
BDC_OPENGROUP: This function module is used to create a session
with the below parameters.
client no = client no
user name = user name
group name = Session Name
Keep = ’X’
hold Date = session is locked until the specified date
Keep = ‘X’ , specifies the session to be available in the session queue for
processing at a later point of time.
Just call the function module and provide the above parameters.
The session will be created
Session Method
BDC_INSERT:
This function module is used to transfer the data from BDCDATA
structure into the session.
Just call the function module and provide the transaction code name and
BDCDATA internal table name.
BDC_CLOSEGROUP:
This function module is used to close the session which is created by
function module BDC_OPENGROUP.
Once the session is created, we need to process the session.
Session Method
Processing the session:
SM35 is the transaction code for processing the session.
Go to SM35
Select the session name. eg:ZSESS1
Click on process button.
Select either foreground or background or error mode, click on the
process button.
The session will be processed.
Session Method
Status of session:
To know the status or to know how many records are successfully
processed, follow the below steps.
select the session name. eg:ZSESS1
click on the button Analysis
click on the tap Log.
it will clearly display all the messages whether each record is successful
or error with clear meaningful messages.
Difference between call transaction and session:
Differences between Call Transaction and
Session Method
Example on Session Method
Example on Session Method
TYPES : BEGIN OF TY_FILE,
MTART TYPE MARA-MTART,
MBRSH TYPE MARA-MBRSH,
MAKTX TYPE MAKT-MAKTX,
MEINS TYPE MARA-MEINS,
END OF TY_FILE.
DATA : I_FILE TYPE TABLE OF TY_FILE .
DATA : WA_FILE TYPE TY_FILE .
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER
LINE. BREAK-POINT .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\MARA.TXT'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = I_FILE.
Example on Session Method
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = 'ZARJUN'
KEEP = 'X'
USER = SY-UNAME.
LOOP AT I_FILE INTO WA_FILE .
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_field using 'BDC_OKCODE'
'=AUSW'.
perform bdc_field using 'RMMG1-MBRSH'
Example on Session Method
*****CONTINUE ALL THE RECORDED STMTS UNITL LAST
STMT
perform bdc_field using 'MARA-MTPOS_MARA'
'NORM'.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'MM01'
TABLES
DYNPROTAB = BDCDATA.
CLEAR WA_FILE .
REFRESH BDCDATA.
CLEAR BDCDATA.
ENDLOOP .
Example on Session Method
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE : / 'SESSION IS SUCCESSFULLY CREATED AND CLO
SED' .
UNIT TESTING :
Execute the program
Goto SM35 and check the status of session
Process the session
Ceck for any errors
Direct Input Method
Direct Input Method
Direct Input Method:
These are standard SAP programs which are used to update / upload the
data from flat file into SAP
we rarely use direct input programs in the real time, because of below
limitations.
The file structure should be created as per the structure of an standard
internal table declared in the standard program.
Here, we can’t catch all types of errors because direct input programs
works directly on open SQL statements, where as call transaction and
session method uses ‘Screen level processing’ (data is transferred
through the screens) where we can catch all type of errors.
‘RMDATIND’ is a standard direct input program for uploading material
master data.
LSMW (Legacy System Migration Workbench)
LSMW (Legacy System Migration Workbench)
It is a SAP tool which is used to transfer the data fro legacy system to
SAP.
It is mainly used to transfer very less amount of data. (<5000)
LSMW contains very little coding
It is mainly designed for consultants who doesn’t have any programming
language. i.e. functional consultants.
There are 4 methods available in LSMW.
direct input method
recording method
BAPI method
ALE/IDOC method.
Difference between LSMW and BDC
LSMW is a more user friendly tool, through which one can do the same
work as the BDC. One just has to follow the 14 steps.
BDC is basically a program which is either generated by SAP after a
recording or programmed by a abaper. It’s like running the transaction
manually but all the data is populated in the screens automatically.
LSMW provides various methods for migration of data, namely those of
direct input, batch input recording and IDOC. BDC however simply makes
use of reccroding. There are 2 ways of implementing BDC, the call
transaction method and the session method.
In LSMW, mapping is taken care of with the help of SAP, where as in
BDC one has to provide explicit mapping directions.
Difference between LSMW and BDC
In BDC, we can schedule the job, so the uploading can be done at the
same time or later periodically while in LSMW. It has to be done at once
only. So through LSMW, one can’t upload large amount of data. Hence
we use LSMW for updating or inserting below 5000 records and we use
BDC to upload records more than 5000.
Application Server Files
Working with files
In SAP, a file can be located either in presentation server or application
server.
Tcode: AL11 – Application server files
If the file is located in presentation server, we can use GUI_UPLOAD,
GUI_DOWNLOAD function modules to read or write the data in files.
If the file is located in application server, we use the below syntaxes to
read or write the data into files.
OPEN DATASET<filename>FOR<input/output/append>IN TEXT MODE
ENCODING DEFAULT
READ DATASET <filename> INTO <variable>
TRANSFER
<variable/wa> to <fname>.
CLOSE DATASET<filename>
Working with files
Open dataset: This statement is used to open a file in application
server for
INPUT : means, the file is opened for reading the data from file
OUTPUT : means, the file is opened for writing the data into file.
APPEND : means, the file is opened for appending new records
into the file.
Close dataset: This statement is used to close the file which is
opened by “OPEN DATASET”.
Note: AL11 is the transaction code for directories in application server.
The default directories which are generally used are
DIR_HOME,DIR_TEMP,DIR_NAME .
Transactions for uploading and downloading
files in AL11
Download file
CG3Y
Upload file
CG3Z
Reading data from file
Reading data from file:
we use the below statement to read the data from application server file.
Syntax: READ DATASET <filename> INTO <variable>
Eg: READ DATASET mara.txt INTO v_str
(where, v_str is a type string)
Writing data into application server
Writing data into application server:
We use the below statement for writing the data into application server
file.
Syntax: TRANSFER <variable/wa> to <fname>.
Eg: TRANSFER wa_mara to mara.txt.
Example for Writing data into file
Types : begin of ty_mara,
Matnr type mara-matnr,
Mtart type mara-mtart,
Mbrsh type mara-mbrsh,
Meins type mara-meins,
End of ty_mara.
Data : I_mara type table of ty_mara.
Data : wa_mara type ty_mara.
Data : fname(30) type c.
Example for Writing data into file
Fname = ‘mara.txt’.”stored in default directory DIR_HOME.
Select matnnr mtart mbrsh meins
From mara
Into table i_mara
Up to 10 rows.
Open data set fnaame for output in text mode encoding default.
If SY-SUBRC <> 0.
MESSAGE ‘file could not be opened’ type ‘E’.
ELSE.
Example for Writing data into file
Loop at i_mara into wa_mara.
Transfer wa_mara to fname.
Endloop.
Close dataset fname.
Write : / ‘the data is written successfully into file’.
Example for Reading data from the file
Data : fname(30) type c.
Data : v_str type string.
Fname = ‘mara.txt’.
Open dataset fname for input in text mode encoding default.
If SY-SUBRC <> 0.
Message ‘file could not be opened’ type ‘E’.
ELSE.
DO.
Read dataset fname into v_str.
Example for Reading data from the file
If SY-SUBRC <> 0.
EXIT.
ELSE.
Write : / v_str.
ENDIF.
ENDDO.
ENDIF.