Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

uploading data from excel

Former Member
0 Likes
1,340

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
770

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.

2 REPLIES 2
Read only

Former Member
0 Likes
771

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.

Read only

0 Likes
770

Thank you

Vigneshwaran