0% found this document useful (0 votes)
194 views5 pages

Example On BDC Session Method

This document provides an example of using the BDC (Business Data Connector) session method to populate a custom table in SAP. It describes recording transactions using SM30 to generate BDC code, which is then used in an ABAP report to automate entering data from an internal table into the custom table. The code sample shows opening a BDC session, reading data from a file into an internal table, then using BDC functions like BDC_DYNPRO and BDC_FIELD to navigate screens and enter the data to update the custom table.

Uploaded by

Debesh Swain
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
194 views5 pages

Example On BDC Session Method

This document provides an example of using the BDC (Business Data Connector) session method to populate a custom table in SAP. It describes recording transactions using SM30 to generate BDC code, which is then used in an ABAP report to automate entering data from an internal table into the custom table. The code sample shows opening a BDC session, reading data from a file into an internal table, then using BDC functions like BDC_DYNPRO and BDC_FIELD to navigate screens and enter the data to update the custom table.

Uploaded by

Debesh Swain
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Example on BDC Session Method

Sometimes there is a need to populate custom table using BDC. That time first the custom table is created and then the TMG (Table maintenance generator) is created.

Now from SM30 new entries can be entered into the table through TMG. If the SM30 transaction can be recorded, then the screen sequence of the SM30 transaction can be called inside the data loop(Data can be collected from a desktop file to internal table) to make the table update process automated. So record the SM30 transaction through SHDB and generate the code and transfer the code into an ABAP report. Comment the unnecessary includes and perform statements and write the code as follows. *************************************************************** * REPORT ytest_bdc * * BDC Session Method example * *************************************************************** By Debesh Page 1

Example on BDC Session Method


* By Debesh * * Date 07/06/2013 * *************************************************************** REPORT ytest_bdc NO STANDARD PAGE HEADING LINE-SIZE 255. PARAMETERS : p_path TYPE rlgrap-filename. TYPES : BEGIN OF ty_file , str(255), END OF ty_file. DATA : lt_itab TYPE STANDARD TABLE OF ty_file, lt_itab1 TYPE TABLE OF ycustom_tab . DATA :ls_itab LIKE LINE OF lt_itab, ls_itab1 LIKE LINE OF lt_itab1. DATA : lv_file TYPE string, ls_path TYPE file_table, lt_ftab TYPE filetable, lv_rc TYPE i. DATA : lt_bdc TYPE STANDARD TABLE OF bdcdata, ls_bdc TYPE bdcdata. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. CALL METHOD cl_gui_frontend_services=>file_open_dialog CHANGING file_table = lt_ftab rc = lv_rc EXCEPTIONS file_open_dialog_failed = 1 cntl_error =2 error_no_gui =3 not_supported_by_gui = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ELSE. READ TABLE lt_ftab INTO ls_path INDEX 1. IF sy-subrc IS INITIAL. p_path = ls_path-filename. ENDIF. ENDIF. START-OF-SELECTION. lv_file = p_path. CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = lv_file By Debesh Page 2

Example on BDC Session Method


filetype = 'ASC' TABLES data_tab = lt_itab 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. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. LOOP AT lt_itab INTO ls_itab. SPLIT ls_itab-str AT ' ' INTO ls_itab1-field1 ls_itab1-field2 ls_itab1-field3. APPEND ls_itab1 TO lt_itab1. CLEAR ls_itab1. ENDLOOP. START-OF-SELECTION. CALL FUNCTION 'BDC_OPEN_GROUP' EXPORTING client = sy-mandt group = 'DEMO_SESSION' keep = 'X' user = sy-uname. *perform open_group. LOOP AT lt_itab1 INTO ls_itab1. PERFORM bdc_dynpro USING 'SAPMSVMA' '0100'. PERFORM bdc_field USING 'BDC_CURSOR' 'VIEWNAME'. PERFORM bdc_field USING 'BDC_OKCODE' '=UPD'. PERFORM bdc_field USING 'VIEWNAME' 'YCUSTOM_TAB'. PERFORM bdc_field USING 'VIMDYNFLDS-LTD_DTA_NO' 'X'. By Debesh Page 3

Example on BDC Session Method


PERFORM bdc_dynpro USING 'SAPLZDEMO_FG' '1011'. PERFORM bdc_field USING 'BDC_CURSOR' 'YCUSTOM_TAB-FIELD1(01)'. PERFORM bdc_field USING 'BDC_OKCODE' '=NEWL'. PERFORM bdc_dynpro USING 'SAPLZDEMO_FG' '1011'. PERFORM bdc_field USING 'BDC_CURSOR' 'YCUSTOM_TAB-FIELD3(01)'. PERFORM bdc_field USING 'BDC_OKCODE' '=SAVE'. PERFORM bdc_field USING 'YCUSTOM_TAB-FIELD1(01)' ls_itab1-field1. PERFORM bdc_field USING 'YCUSTOM_TAB-FIELD2(01)' ls_itab1-field2. PERFORM bdc_field USING 'YCUSTOM_TAB-FIELD3(01)' ls_itab1-field3. PERFORM bdc_dynpro USING 'SAPLSTRD' '0300'. PERFORM bdc_field USING 'BDC_CURSOR' 'KO008-TRKORR'. PERFORM bdc_field USING 'BDC_OKCODE' '=LOCK'. PERFORM bdc_field USING 'KO008-TRKORR' 'DEVK900002'. PERFORM bdc_dynpro USING 'SAPLZDEMO_FG' '1011'. PERFORM bdc_field USING 'BDC_CURSOR' 'YCUSTOM_TAB-FIELD1(02)'. PERFORM bdc_field USING 'BDC_OKCODE' '=SAVE'. PERFORM bdc_dynpro USING 'SAPLZDEMO_FG' '1011'. PERFORM bdc_field USING 'BDC_CURSOR' 'YCUSTOM_TAB-FIELD1(02)'. PERFORM bdc_field USING 'BDC_OKCODE' '=BACK'. PERFORM bdc_dynpro USING 'SAPLZDEMO_FG' '1011'. PERFORM bdc_field USING 'BDC_CURSOR' 'YCUSTOM_TAB-FIELD1(02)'. PERFORM bdc_field USING 'BDC_OKCODE' '=BACK'. PERFORM bdc_dynpro USING 'SAPMSVMA' '0100'. PERFORM bdc_field USING 'BDC_OKCODE' '/EBACK'. PERFORM bdc_field USING 'BDC_CURSOR' 'VIEWNAME'. APPEND ls_bdc TO lt_bdc. CLEAR ls_bdc. ENDLOOP. CALL FUNCTION 'BDC_INSERT' EXPORTING tcode = 'SM30' TABLES dynprotab = lt_bdc. CALL FUNCTION 'BDC_CLOSE_GROUP'. *&---------------------------------------------------------------------* *& Form BDC_DYNPRO *&---------------------------------------------------------------------* * Send BDC screen details to BDC Data *----------------------------------------------------------------------* * -->P_0668 program name * -->P_0669 screen no *----------------------------------------------------------------------* FORM bdc_dynpro USING value(p_0668) By Debesh Page 4

Example on BDC Session Method


value(p_0669). CLEAR ls_bdc. ls_bdc-program = p_0668. ls_bdc-dynpro = p_0669. ls_bdc-dynbegin = 'X'. APPEND ls_bdc TO lt_bdc. ls_bdc-fnam = ''. ENDFORM. " BDC_DYNPRO *&---------------------------------------------------------------------* *& Form BDC_FIELD *&---------------------------------------------------------------------* * Send Screen field values to BDC DATA *----------------------------------------------------------------------* * -->P_0673 field name * -->P_0674 field value *----------------------------------------------------------------------* FORM bdc_field USING value(p_0673) value(p_0674). CLEAR ls_bdc. ls_bdc-fnam = p_0673. ls_bdc-fval = p_0674. APPEND ls_bdc TO lt_bdc. ENDFORM. " BDC_FIELD

By Debesh

Page 5

You might also like