Batch Data Communication
Batch Data Communication
Batch Data Communication
Communication
BDC Overview
Overview
It is the technique of transferring in data from legacy system (NON-SAP) to SAP is called BDC.
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
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:
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
Since, it is very difficult to note down the technical information for each
In this type the call transaction screens will communicate with the update
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
In this mode, the called transaction communicates with the update work
__________________________________________________________
_
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:
Whenever the message type is error, we need to use the function module
The recording method is going to record all the fields in the transaction
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
**********************************************
*******************
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 .
BREAK-POINT .
EXPORTING
FILENAME = 'C:\MARADATA.TXT'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = I_FILE.
Example program on Call transaction
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 *
*----------------------------------------------------------------------*
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:
lakhs)
It is basically a 2 step process
Create a session
Process a session
Keep = ‘X’ , specifies the session to be available in the session queue for
Just call the function module and provide the transaction code name and
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
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
we rarely use direct input programs in the real time, because of below
limitations.
Here, we can’t catch all types of errors because direct input programs
SAP.
It is mainly used to transfer very less amount of data. (<5000)
LSMW contains very little coding
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 BDC, we can schedule the job, so the uploading can be done at the
server.
ENCODING DEFAULT
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.