BDC Using Call Transaction Method
BDC Using Call Transaction Method
When SAP is implemented we need Data to migrate from non-SAP system i.e. Legacy system to SAP
system. One way of doing this is BDC (Batch Data Communication).
Requirement:- For Developing BDC using CALL TRANSACTION method we need to do the recording of
the corresponding transaction & flat file in which data is stored. Flat file can be Text file or Excel File. In
CALL TRANSACTION we also have to create the Error Log file.
In BDC we use structure BDCDATA for Batch Input, which has following components.
A BDCDATA structure can contain the batch input data for only a single run of a transaction
In CALL TRANSACTION method, we need to create Log for the Error Message, for this we use structure
BDCMSGCOLL.
(If you are using the same file for practice make sure you remove the above two heading rows.)
Define the internal table structure as per the above file structure.
DATA:
BEGIN OF fs_field,
bsart TYPE eban-bsart, ” Document Type.
matnr TYPE eban-matnr, " Material Number.
menge TYPE eban-menge, " Quantity Requested.
werks TYPE eban-werks, " Plant.
END OF fs_field.
*Input Path
SELECTION-SCREEN BEGIN OF BLOCK blck WITH FRAME TITLE text-011.
PARAMETERS:
p_file TYPE rlgrap-filename, " File Path
e_file TYPE rlgrap-filename OBLIGATORY, " Error File Path
p_mode TYPE c OBLIGATORY DEFAULT 'N'. " Mode
SELECTION-SCREEN END OF BLOCK blck.
* Structure Decleration
DATA :
BEGIN OF fs_field,
bsart TYPE eban-bsart, " Document Type.
matnr TYPE eban-matnr, " Material Number.
menge TYPE eban-menge, " Quantity Requested.
werks TYPE eban-werks, " Plant.
END OF fs_field.
DATA:
fs_bdcdata LIKE LINE OF t_bdcdata, " Structure type of bdcdata
w_str TYPE string.
* Data decleration
DATA:
wa_path TYPE string ,
wa_error TYPE string,
wa_cnt TYPE i,
w_mode TYPE c,
wa_cnt1(2) TYPE n,
it_output type table of ty_s_error,
wa_output like line of it_output.
AT SELECTION-SCREEN.
* Mode 'A' = Foreground mode
* Mode 'N' = Background mode
IF p_mode = 'A' OR p_mode = 'N' .
w_mode = p_mode.
ELSE.
*Error Message
MESSAGE 'PLEASE ENTER THE MODE A or N' TYPE 'E'.
ENDIF.
TYPES:
fs_struct(4096) TYPE c OCCURS 0 .
DATA:
w_struct TYPE fs_struct.
*********************(populate_bdcdata)***********************
* part 1
FORM populate_bdcdata.
PERFORM :
fill_bdc_data USING 'SAPMM06B' '0100' 'X' ' ' ' ',
fill_bdc_data USING '' '' '' 'EBAN-BSART' fs_field-bsart, " Document
Type.
fill_bdc_data USING '' '' '' 'BDC_OKCODE' '/00', " Enter.
* part 2
FORM fill_bdc_data USING value(p_program)
value(p_dynpro)
value(p_dynbegin)
value(p_fnam)
value(p_fval).
CLEAR fs_bdcdata .
IF p_dynbegin = 'X' .
fs_bdcdata-program = p_program .
fs_bdcdata-dynpro = p_dynpro .
fs_bdcdata-dynbegin = p_dynbegin .
APPEND fs_bdcdata TO t_bdcdata.
ELSE.
fs_bdcdata-fnam = p_fnam.
fs_bdcdata-fval = p_fval.
CONDENSE fs_bdcdata-fval.
APPEND fs_bdcdata TO t_bdcdata.
ENDIF. " IF p_dynbeg..
*********************(insert_data)****************************
FORM insert_data.
IF sy-subrc EQ 0.
* Uploaded into the database
WRITE :/ 'DATA UPLOADED IN TABLE EBAN...' .
ELSE.
* Error Found
LOOP AT t_msg INTO w_msg WHERE msgtyp EQ 'E'.
* Format Message
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = w_msg-msgid
msgnr = w_msg-msgnr
msgv1 = w_msg-msgv1
msgv2 = w_msg-msgv2
msgv3 = w_msg-msgv3
msgv4 = w_msg-msgv4
IMPORTING
message_text_output = w_msg1.
wa_output-msg_err = w_msg1.
wa_string = fs_field-matnr.
wa_error = e_file.
ENDLOOP.
ENDIF.
ENDFORM. "insert_data
And then enter the path of a file where error log will be created.
Finally select the mode. We have following option for the mode.
3. E = Display Error ( If there is any error, it will be displayed in log otherwise it is similar to
background mode)
In case of Error in the upload of any data, an Error file gets generated at the above given path.