You are on page 1of 8

BDC using CALL TRANSACTION method

Objective: - Steps For implementing 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. PROGRAM - BDC module pool DYNPRODYNBEGINFNAMFVALBDC Screen number BDC screen start Field name BDC field value

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. For our demo purpose, we would be considering the file format. (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, matnr TYPE eban-matnr, menge TYPE eban-menge, werks TYPE eban-werks, END OF fs_field.
Recoding is done using the Transaction SHDB.

" Material Number. " Quantity Requested. " Plant.

Document Type.

Here we have done Recording for the transaction- ME51. The Recording which you get will be in following format.

ow go to ABAP Editor (SE38). Enter the following code:

*Structure for error message TYPES : BEGIN OF ty_s_error, msg_err(60) TYPE c, END OF ty_s_error. *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, matnr TYPE eban-matnr, menge TYPE eban-menge, werks TYPE eban-werks, END OF fs_field. *Internal table decleration DATA: t_field LIKE TABLE OF fs_field, t_bdcdata LIKE TABLE OF bdcdata. DATA: fs_bdcdata LIKE LINE OF t_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. * Opening window for path selection AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. CALL FUNCTION 'F4_FILENAME' EXPORTING " Structure type of bdcdata

" " " "

Document Type. Material Number. Quantity Requested. Plant.

program_name dynpro_number field_name IMPORTING file_name

= syst-cprog = syst-dynnr = ' ' = p_file.

TYPES: fs_struct(4096) TYPE c OCCURS 0 . DATA: w_struct TYPE fs_struct. * Uploading excel file. CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP' EXPORTING i_field_seperator = 'X' * I_LINE_HEADER = i_tab_raw_data = w_struct i_filename = p_file TABLES i_tab_converted_data = t_field EXCEPTIONS conversion_failed = 1 OTHERS = 2 . IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. *Opening window for Error file download AT SELECTION-SCREEN ON VALUE-REQUEST FOR e_file. CALL FUNCTION 'F4_FILENAME' EXPORTING program_name = syst-cprog dynpro_number = syst-dynnr field_name = ' ' IMPORTING file_name = e_file. * start of selection event. START-OF-SELECTION. LOOP AT t_field INTO fs_field . REFRESH: t_bdcdata. CLEAR fs_bdcdata. PERFORM populate_bdcdata. PERFORM insert_data. ENDLOOP.

" LOOP AT it_c.

*********************(populate_bdcdata)*********************** * part 1 FORM populate_bdcdata. PERFORM : fill_bdc_data USING 'SAPMM06B' '0100' 'X' ' ' ' ', fill_bdc_data USING '' '' '' 'EBAN-BSART' fs_fieldbsart, " Document Type.

fill_bdc_data USING

''

''

''

'BDC_OKCODE' '/00',

" Enter.

fill_bdc_data USING 'SAPMM06B' '0106' 'X' ' ' ' ', fill_bdc_data USING '' '' '' 'EBAN-MATNR(01)' fs_fieldmatnr, " Material Number. fill_bdc_data USING '' '' '' 'EBAN-MENGE(01)' fs_fieldmenge, " Quantity Requested. fill_bdc_data USING '' '' '' 'EBAN-WERKS(01)' fs_field-werks, fill_bdc_data USING '' '' '' 'BDC_OKCODE' '/00', fill_bdc_data USING 'SAPMM06B' '0102' 'X' '' '' , fill_bdc_data USING '' '' '' 'BDC_OKCODE' '=BU'. ENDFORM. " Form populate_bdc.

" Plant. " Enter. " Save.

* 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.. ENDFORM . " Fill_entry

*********************(insert_data)**************************** FORM insert_data. *Data decleration for Error Message DATA: t_msg TYPE TABLE OF bdcmsgcoll, w_msg TYPE bdcmsgcoll, w_msg1(51). * Call transaction 'ME51' CALL TRANSACTION 'ME51' USING t_bdcdata MODE w_mode UPDATE 'S' MESSAGES INTO t_msg. 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'. *

" Collecting Error messages

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.

*Error message in downloaded file data: wa_string(10) type c. wa_string = fs_field-matnr. concatenate wa_string wa_output-msg_err into wa_outputmsg_err separated by space. APPEND wa_output-msg_err TO it_output. wa_error = e_file. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING BIN_FILESIZE filename FILETYPE APPEND write_field_separator TABLES data_tab

* * *

= = = = =

wa_error 'ASC' ' ' 'X'

= it_output

* . IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. " IF sy-subrc <> 0. ENDLOOP. ENDIF. ENDFORM.
Run the Program.

"insert_data

Enter the path of file you need to upload. 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. 1. 2. 3. A = Foreground (Step by step processing will be done by you) N = Background (All the Processing will be done in Background) E = Display Error ( If there is any error, it will be displayed in log otherwise it is similar to background mode)

Finally when all the data is uploaded .

In case of Error in the upload of any data, an Error file gets generated at the above given path.

You might also like