Sie sind auf Seite 1von 3

Example on BDC Direct Input Method The Input file should have fields separated by space.

As using the method the table KNA1 is going to be updated so the file should contain atleast KUNNR field which is the key field of the table. Selection Screen :

Code: *&---------------------------------------------------------------------* *& Report YTEST_BDC_DIRECT_METHOD *& BDC Direct Input method to update KNA1 from local file *&---------------------------------------------------------------------* *& By Debesh *& Date 07/06/2013 *&---------------------------------------------------------------------* REPORT ytest_bdc_direct_method. 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 kna1 . 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. 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 By Debesh Page 1

Example on BDC Direct Input Method 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 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. By Debesh Page 2

Example on BDC Direct Input Method SPLIT ls_itab-str AT ' ' INTO ls_itab1-kunnr ls_itab1-name1 ls_itab1-ort01 ls_itab1-land1. ls_itab1-mandt = sy-mandt. APPEND ls_itab1 TO lt_itab1. CLEAR ls_itab1. ENDLOOP. LOOP AT lt_itab1 INTO ls_itab1. INSERT into kna1 values ls_itab1. CLEAR ls_itab1. IF sy-subrc = 0. WRITE :/ 'RECORDS ARE INSERTED INTO KNA1'. ELSEIF sy-subrc = 4. WRITE :/ 'RECORDS ALREADY EXISTS'. ENDIF. ENDLOOP.

Upon successful insertion message gets displayed:

By Debesh

Page 3

Das könnte Ihnen auch gefallen