BDC SheetalShama
BDC SheetalShama
Contributed by
Sheetal Sharma
Under the guidance of TagSkills.
SAP BDC stands for batch data communica
communication
tion and it is a automation of
existing transaction with legacy data code. Each transaction can create only
one record at a time. If you want to create the thousands of records, one way
is execute the same transaction thousands of time. Another way is develop a
BDC program to automate the existing transaction.
transact For example, company
decides to adapt its systems and procedures to SAP, and installs SAP, it will
have to upload a huge volume of data that are a part of its legacy systems or
old systems into the SAP system. This process is done through SAP BDC (Bat(Batch
Data Communication).
Batch input
Batch input is typically used to transfer data from non
non-R/3
R/3 systems to R/3
systems or to transfer data between R/3 systems.
Groups a series of transaction calls together with input data and user actions.
A batch input session can be used to execute a dialog transaction in batch
input, where some or all the screens are processed by the session. Batch input
sessions are stored in the database as database tables and can be used within
a program as internal tables when accessing transactions.
Points to note
BDI works by carrying out normal SAP transactions just as a user would
but it execute the transaction automatically. All the screen validations
and business logic validation will be done while using Batch Data Input.
It is suitable for entering large amo
amount of data.
No manual interaction is required
www.tagskills.com
- We can perform the data base table operation either through DML
commands or through Transaction codes. DML commands are used
to update only one data base table at a time, whereas transaction code
is used to update their relevant data base tables at a time.
1. Session method.
2. Call Transaction Method.
In this method an ABAP/4 program reads the external data to the SAP System
and stores in a batch input session.
After creating the session, you can run the session to execute the SAP
transaction in it.
This method uses the function modules BDC_ OPEN, BDC_INSERT and
an
BDC_CLOSE
1. In the foreground
2. In the background
3. During processing, with error display
You should process batch input sessions in the foreground or using the error
display if you want to test the data transfer.
If you want to execute the data transfer or test its performance, you should
process the sessions in the background.
Asynchronous
ynchronous processing
Session method can process any number of transaction at a time.
time
Synchronous database
abase update.
www.tagskills.com
A batch input process log is generated for each session.
Session cannot be generated in parallel.
You will typically observe the following sequence of steps to develop Batch
Input for your organization
www.tagskills.com
Recording the Data Entry Transaction
The first step in creating a batch input session is to record the transaction
to be automated. This involves manually entering data into SAP and recording
the steps using transaction code SHDB. The system rrecords
ecords all keystrokes and
data entered throughout the transaction and generates an ABAP program that
may be used to automate it.
Once the transaction has been recorded, the data must be prepared for
upload. This includes conve
converting
rting the data to be uploaded into a format that
SAP can process. This can be accomplished using a data conversion tool or by
manually creating a file containing the data in a format that can be uploaded
using the batch input session.
Thee data is uploaded into SAP using the batch input session as the final step in
the BDC process. The batch input session is created using transaction code
SM35, which allows you to choose the ABAP program developed during the
recording process as well as th
the
e file holding the data to be uploaded. The data
is subsequently processed in the background through the system, which
updates the SAP database.
Step 1 – Do the recording and prepare the flat file and upload the data from
flat file to internal table.
www.tagskills.com
Step 2 - We need to record the session using tcode “SHDB” to get the
dummy BDC structure for FI01 screen.
Step 3 - After recording the session we need to write the BDC code to pass the
internal table data to the internal table of BDC structure according to the
recording.
Step 4 - Then data in the BDC internal table need to be updated in the
database table using any BDC method via FI01 screen.
www.tagskills.com
DATA: LT_DATA TYPE TABLE OF TY_T,
WA_D TYPE TY_T.
DATA: lt_BDCDATA type table of BDCDATA ,
wa_BDCDATA type bdcdata.
DATA: LT_MESSTAB TYPE TABLE OF BDCMSGCOLL ,
WA_MESSTAB TYPE BDCMSGCOLL.
DATA: V_FILE TYPE STRING ,
LV_MESSAGE TYPE STRING.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
www.tagskills.com
HOLDDATE_INVALID =5
INTERNAL_ERROR =6
QUEUE_ERROR =7
RUNNING =8
SYSTEM_LOCK_ERROR =9
USER_INVALID = 10
OTHERS = 11
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
*perform open_group.
loop at lt_data into wa_d.
perform bdc_dynpro using 'SAPLMGMM' '0060' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MATNR'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'RMMG1-MATNR'
WA_D-MATNR.
perform bdc_field using 'RMMG1-MBRSH'
WA_D-MBRSH.
perform bdc_field using 'RMMG1-MTART'
WA_D-MTART.
perform bdc_dynpro using 'SAPLMGMM' '0070' 0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
KZSEL(01)'
'X'.
perform bdc_dynpro using 'SAPLMGMM' '4004' '4004'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'MAKT-MAKTX'
WA_D-MAKTX.
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
WA_D-MEINS.
REFRESH LT_BDCDATA.
ENDLOOP.
www.tagskills.com
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN =1
QUEUE_ERROR =2
OTHERS =3
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
*----------------------------------------------------------------------
----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------
----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO..
CLEAR wa_BDCDATA.
wa_BDCDATA-PROGRAM = PROGRAM.
wa_BDCDATA-DYNPRO = DYNPRO.
WA_BDCDATA-DYNBEGIN = 'X'.
APPEND WA_BDCDATA TO LT_BDCDATA.
ENDFORM.
*----------------------------------------------------------------------
----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------
----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR WA_BDCDATA.
WA_BDCDATA-FNAM = FNAM.
WA_BDCDATA-FVAL = FVAL.
APPEND WA_BDCDATA TO LT_BDCDATA.
ENDFORM.
After executing the program will run in session. To access session screen we
have to go to transaction code “SM35”.
On SM35 screen select the session and then click on process. After clicking on
process a new window will appear having multiple options.
Process/foreground meansns we have do the task manually.
www.tagskills.com
Display only error means only the error in the execution will be shown
Background means it will be done automatically in the background.
After clicking on the process radio button on the new window the data will get
uploaded
oaded to the data base table. This green tick will tell that the execution is
successful without any error.
www.tagskills.com
www.tagskills.com
Call Transaction
The first step in using Call Transaction is to create an ABAP program that calls
the transaction code. Transaction codes SE38 or SE80 can be used to generate
this program. The program contains th the
e transaction code as well as additional
logic to validate the data being entered or conduct other tasks.
After the ABAP program has been created, the data must be prepared for
entry. This involves converting the data to be ent
entered
ered into a format that SAP
can process. This can be done with the help of a data conversion tool or by
manually creating a file containing the data in a format that can be uploaded
using the ABAP program.
The Call Transaction procedure continues with the execution of the ABAP
program, which calls the transaction code and enters the data into SAP. The
program can be run using transaction codes SE38 or SE80, and depending on
the outcomes of the transaction code execut
execution,
ion, it may prompt the user for
further input or show messages.
www.tagskills.com
Points to Note:
UPLOAD: - Upload is the function module which is used to browse the file as
well as upload the data from file to internal table. The input for the above
function module is
1. File type
www.tagskills.com
2. Data internal table which is similar as file
In Update we will not get any message if the code execution is done
successfully or not. So we use a predefined structure BDCMSGCOLL and a
predefined function module FORMAT_MESSAGE in order to select required
message.
Coding Screen —
REPORT ZBDCTASK1.
V_FILE = P_FILE.
www.tagskills.com
* DAT_MODE =''
* CODEPAGE =''
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM =''
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK =''
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = LT_LIFNR
* CHANGING
* ISSCANPERFORMED =''
* EXCEPTIONS
* FILE_OPEN_ERROR =1
* FILE_READ_ERROR =2
* NO_BATCH =3
* GUI_REFUSE_FILETRANSFER =4
* INVALID_TYPE =5
* NO_AUTHORITY =6
* UNKNOWN_ERROR =7
* BAD_DATA_FORMAT =8
* HEADER_NOT_ALLOWED =9
* SEPARATOR_NOT_ALLOWED = 10
* HEADER_TOO_LONG = 11
* UNKNOWN_DP_ERROR = 12
* ACCESS_DENIED = 13
* DP_OUT_OF_MEMORY = 14
* DISK_FULL = 15
* DP_TIMEOUT = 16
* OTHERS = 17
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
*include bdcrecx1.
www.tagskills.com
*perform bdc_transaction using 'XK01'.
CALL TRANSACTION 'XK01' USING BDCDATA
MODE CTUMODE.
ENDLOOP.
*----------------------------------------------------------------------
----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------
----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> NODATA.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM.
Output—>
Database Table—>
www.tagskills.com
Difference between Call Transaction method and session method:
The following table highlights the major differences between Call Transaction
and session method−
www.tagskills.com
TagSkills:
Disclaimer –
www.tagskills.com