Skip to Content

uploading data from excel

Mar 08, 2017 at 06:31 AM


avatar image

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.


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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Subhajit Roy Mar 08, 2017 at 08: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

    filename                = 'C:\Users\roy\Desktop\Colg.xlsx'
    i_begin_col             = '1'
    i_begin_row             = '1'
    i_end_col               = '4'
    i_end_row               = '50'
    intern                  = lt_excel
    inconsistent_parameters = 1
    upload_ole              = 2
    OTHERS                  = 3.
IF sy-subrc <> 0.
  MESSAGE 'Error in uploading Excel' TYPE 'E'.
  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.

Now, LT_TAB contains the data according to the DDIC columns. Now you can insert this data directly into your table.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thank you