Sample Program to Upload MS Excel File data into SAP R/3 Using BDC
report ZXXXX
no standard page heading line-size 255.
include bdcrecx1.
TABLES : ZEMP.
DATA : ITAB TYPE STANDARD TABLE OF ZEMP WITH HEADER LINE,
G_XLDATA LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
DATA: p_file LIKE ibipparms-path.
start-of-selection.
no standard page heading line-size 255.
include bdcrecx1.
TABLES : ZEMP.
DATA : ITAB TYPE STANDARD TABLE OF ZEMP WITH HEADER LINE,
G_XLDATA LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
DATA: p_file LIKE ibipparms-path.
start-of-selection.
*Function Module to fetch file from the presentation server
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
*Function Module to upload excel file data to internal table
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = p_file
I_BEGIN_COL = 1
I_BEGIN_ROW = 1
I_END_COL = 100
I_END_ROW = 100
TABLES
INTERN = G_XLDATA
.
LOOP AT G_XLDATA.
CASE G_XLDATA-COL.
WHEN 1.
ITAB-EMPID = G_XLDATA-VALUE.
WHEN 2.
ITAB-EMPNAME = G_XLDATA-VALUE.
WHEN 3.
ITAB-STREET = G_XLDATA-VALUE.
WHEN 4.
ITAB-CITY = G_XLDATA-VALUE.
APPEND ITAB.
CLEAR ITAB.
ENDCASE.
ENDLOOP.
perform open_group.
LOOP AT ITAB.
perform bdc_dynpro using 'ZRSCREEN1' '0100'.
perform bdc_field using 'BDC_OKCODE'
'=INSERT'.
perform bdc_field using 'BDC_CURSOR'
'ZEMP-CITY'.
perform bdc_field using 'ZEMP-EMPID'
ITAB-EMPID.
perform bdc_field using 'ZEMP-EMPNAME'
ITAB-EMPNAME.
perform bdc_field using 'ZEMP-STREET'
ITAB-STREET.
perform bdc_field using 'ZEMP-CITY'
ITAB-CITY.
perform bdc_dynpro using 'ZRSCREEN1' '0100'.
perform bdc_field using 'BDC_OKCODE'
'/ELOGOUT'.
perform bdc_field using 'BDC_CURSOR'
'ZEMP-EMPID'.
perform bdc_field using 'ZEMP-EMPID'
'11'.
perform bdc_field using 'ZEMP-EMPNAME'
'JAMES SAWYER'.
perform bdc_field using 'ZEMP-STREET'
'B-100'.
perform bdc_field using 'ZEMP-CITY'
'SECTOR-100'.
perform bdc_transaction using 'ZRSCREEN1'.
ENDLOOP.
perform close_group.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = p_file
I_BEGIN_COL = 1
I_BEGIN_ROW = 1
I_END_COL = 100
I_END_ROW = 100
TABLES
INTERN = G_XLDATA
.
LOOP AT G_XLDATA.
CASE G_XLDATA-COL.
WHEN 1.
ITAB-EMPID = G_XLDATA-VALUE.
WHEN 2.
ITAB-EMPNAME = G_XLDATA-VALUE.
WHEN 3.
ITAB-STREET = G_XLDATA-VALUE.
WHEN 4.
ITAB-CITY = G_XLDATA-VALUE.
APPEND ITAB.
CLEAR ITAB.
ENDCASE.
ENDLOOP.
perform open_group.
LOOP AT ITAB.
perform bdc_dynpro using 'ZRSCREEN1' '0100'.
perform bdc_field using 'BDC_OKCODE'
'=INSERT'.
perform bdc_field using 'BDC_CURSOR'
'ZEMP-CITY'.
perform bdc_field using 'ZEMP-EMPID'
ITAB-EMPID.
perform bdc_field using 'ZEMP-EMPNAME'
ITAB-EMPNAME.
perform bdc_field using 'ZEMP-STREET'
ITAB-STREET.
perform bdc_field using 'ZEMP-CITY'
ITAB-CITY.
perform bdc_dynpro using 'ZRSCREEN1' '0100'.
perform bdc_field using 'BDC_OKCODE'
'/ELOGOUT'.
perform bdc_field using 'BDC_CURSOR'
'ZEMP-EMPID'.
perform bdc_field using 'ZEMP-EMPID'
'11'.
perform bdc_field using 'ZEMP-EMPNAME'
'JAMES SAWYER'.
perform bdc_field using 'ZEMP-STREET'
'B-100'.
perform bdc_field using 'ZEMP-CITY'
'SECTOR-100'.
perform bdc_transaction using 'ZRSCREEN1'.
ENDLOOP.
perform close_group.