1, 问题描述
用excel上载大数据量的BOM数据到SAP系统中,一次上载的数量级别在10万条左右,这时用ALSM_EXCEL_TO_INTERNAL_TABLE上载时会dump,查看了代码发现ALSM_EXCEL_TO_INTERNAL_TABLE中是将数据先保存到剪贴板(Clippboard )上,然后在保存到内表中,很不幸剪贴板大小有限制,超过就会dump。
2, 问题解决
解决方法比较简单,就是在循环中调用ALSM_EXCEL_TO_INTERNAL_TABLE,将一次上载的内容分成多次,以便减少保存到剪贴板中的内容。
代码如下:
下面代码中,每次上载40000条数据,循环10次,最多可以上载40万,当然循环次数还可以按需求扩大。
REPORT ztest_upload_excel. DATA:g_begin_row TYPE i, g_end_row TYPE i. DATA:git_temp TYPE TABLE OF alsmex_tabline, gwa_temp TYPE alsmex_tabline. TYPES:BEGIN OF ty_upload, werks TYPE ymoe_compalloc-werks, "Plant root TYPE ymoe_compalloc-root, "Root material maktxr TYPE makt-maktx, "Description ( R ) parent TYPE ymoe_compalloc-parent, "Parent maktxp TYPE makt-maktx, "Description ( P ) beskz TYPE marc-beskz, "Procurement Type sobsl TYPE marc-sobsl, "Special Procurement Type component TYPE ymoe_compalloc-component, "Component maktxc TYPE makt-maktx, "Description ( C ) prodline TYPE ymoe_compalloc-prodline, "Production Line workstation TYPE ymoe_compalloc-workstation, "Work Station END OF ty_upload. DATA:git_upload TYPE STANDARD TABLE OF ty_upload, gwa_upload LIKE LINE OF git_upload. PARAMETERS:p_file TYPE rlgrap-filename DEFAULT 'C: empupload.xlsx' OBLIGATORY. "File Name AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. PERFORM frm_get_filename. *----------------------------------------------------------------------* * Start-of-Selection *----------------------------------------------------------------------* START-OF-SELECTION. g_begin_row = 2. g_end_row = g_begin_row + 40000. DO 10 TIMES. REFRESH:git_temp. * Get EXCEL-Sheet in internal table CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' EXPORTING filename = p_file i_begin_col = '1' i_begin_row = g_begin_row i_end_col = '11' i_end_row = g_end_row TABLES intern = git_temp EXCEPTIONS inconsistent_parameters = 1 upload_ole = 2 OTHERS = 3. IF git_temp[] IS INITIAL. EXIT. ELSE. LOOP AT git_temp INTO gwa_temp. AT NEW row. CLEAR gwa_upload. ENDAT. CASE gwa_temp-col. WHEN '1'. gwa_upload-werks = gwa_temp-value. WHEN '2'. gwa_upload-root = gwa_temp-value. WHEN '3'. gwa_upload-maktxr = gwa_temp-value. WHEN '4'. gwa_upload-parent = gwa_temp-value. WHEN '5'. gwa_upload-maktxp = gwa_temp-value. WHEN '6'. gwa_upload-beskz = gwa_temp-value. WHEN '7'. gwa_upload-sobsl = gwa_temp-value. WHEN '8'. gwa_upload-component = gwa_temp-value. WHEN '9'. gwa_upload-maktxc = gwa_temp-value. WHEN '10'. gwa_upload-prodline = gwa_temp-value. WHEN '11'. gwa_upload-workstation = gwa_temp-value. ENDCASE. AT END OF row. APPEND gwa_upload TO git_upload. ENDAT. ENDLOOP. g_begin_row = g_end_row + 1. g_end_row = g_begin_row + 40000. ENDIF. ENDDO. *&---------------------------------------------------------------------* *& Form FRM_GET_FILENAME *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_get_filename . DATA:l_filter TYPE string, lit_file TYPE STANDARD TABLE OF file_table, lwa_file LIKE LINE OF lit_file, l_rc TYPE i. CLEAR:p_file. l_filter = 'Microsoft Excel Files (*.XLS;*.XLSX;*.XLSM)|*.XLS;*.XLSX;*.XLSM|'. CALL METHOD cl_gui_frontend_services=>file_open_dialog EXPORTING * window_title = default_extension = '.xlsx' * default_filename = file_filter = l_filter * with_encoding = * initial_directory = * multiselection = CHANGING file_table = lit_file rc = l_rc * user_action = * file_encoding = EXCEPTIONS file_open_dialog_failed = 1 cntl_error = 2 error_no_gui = 3 not_supported_by_gui = 4 OTHERS = 5. IF sy-subrc = 0. READ TABLE lit_file INTO lwa_file INDEX 1. IF sy-subrc = 0. p_file = lwa_file-filename. ENDIF. ENDIF. ENDFORM.