‎2017 Mar 08 6:31 AM
My requirement is to upload a data from excel to SAP abap DDIC table. So I have
TEXT_CONVERT_XLS_TO_SAP FM to upload the data from my excel. But I had a problem that my DDIC table has column in one order but my excel has column in different order. How to I upload data by matching with its column name.
Example:
My DDIC table has following column
Mandt Rollno Name Course DOJ
My Excel has following column
Name Course DOJ Rollno
how I can upload the data in the excel file to DDIC table correctly using column name
‎2017 Mar 08 8:15 AM
Instead of using TEXT_CONVERT_XLS_TO_SAP, you can use ALSM_EXCEL_TO_INTERNAL_TABLE as it is easy to manipulate your records according to your needs and using TEXT_CONVERT_XLS_TO_SAP will give dump because of mismatch datatype.
Refer to the following programs:
ZTCOLG is the DDIC table which has this columns: Mandt, Rollno, Name, Course, DOJ
& Colg.xlsx is the excel file which has the column in this order: Name, Course, DOJ, Rollno
DATA: lt_tab TYPE TABLE OF ztcolg,
ls_tab TYPE ztcolg,
lt_excel TYPE TABLE OF alsmex_tabline,
ls_excel TYPE alsmex_tabline
.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = 'C:\Users\roy\Desktop\Colg.xlsx'
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '4'
i_end_row = '50'
TABLES
intern = lt_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE 'Error in uploading Excel' TYPE 'E'.
ELSE.
LOOP AT lt_excel INTO ls_excel.
CASE ls_excel-col.
WHEN '0001'. "NAME COL IN XLS
MOVE ls_excel-value TO ls_tab-name.
WHEN '0002'. "COURSE COL IN XLS
MOVE ls_excel-value TO ls_tab-course.
WHEN '0003'. "DOJ COL IN XLS
MOVE ls_excel-value TO ls_tab-doj.
WHEN '0004'. "ROLL COL IN XLS
MOVE ls_excel-value TO ls_tab-rollno.
APPEND ls_tab TO lt_tab.
CLEAR: ls_excel.
WHEN OTHERS.
ENDCASE.
ENDLOOP.Now, LT_TAB contains the data according to the DDIC columns. Now you can insert this data directly into your table.
‎2017 Mar 08 8:15 AM
Instead of using TEXT_CONVERT_XLS_TO_SAP, you can use ALSM_EXCEL_TO_INTERNAL_TABLE as it is easy to manipulate your records according to your needs and using TEXT_CONVERT_XLS_TO_SAP will give dump because of mismatch datatype.
Refer to the following programs:
ZTCOLG is the DDIC table which has this columns: Mandt, Rollno, Name, Course, DOJ
& Colg.xlsx is the excel file which has the column in this order: Name, Course, DOJ, Rollno
DATA: lt_tab TYPE TABLE OF ztcolg,
ls_tab TYPE ztcolg,
lt_excel TYPE TABLE OF alsmex_tabline,
ls_excel TYPE alsmex_tabline
.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = 'C:\Users\roy\Desktop\Colg.xlsx'
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '4'
i_end_row = '50'
TABLES
intern = lt_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE 'Error in uploading Excel' TYPE 'E'.
ELSE.
LOOP AT lt_excel INTO ls_excel.
CASE ls_excel-col.
WHEN '0001'. "NAME COL IN XLS
MOVE ls_excel-value TO ls_tab-name.
WHEN '0002'. "COURSE COL IN XLS
MOVE ls_excel-value TO ls_tab-course.
WHEN '0003'. "DOJ COL IN XLS
MOVE ls_excel-value TO ls_tab-doj.
WHEN '0004'. "ROLL COL IN XLS
MOVE ls_excel-value TO ls_tab-rollno.
APPEND ls_tab TO lt_tab.
CLEAR: ls_excel.
WHEN OTHERS.
ENDCASE.
ENDLOOP.Now, LT_TAB contains the data according to the DDIC columns. Now you can insert this data directly into your table.
‎2017 Mar 08 9:42 AM