ABAP EXCEL文件导入ABAP内表中详解编程语言

如何把
EXCEL
文件导入
ABAP
内表中?
可以使用功能模块
ALSM_EXCEL_TO_INTERNAL_TABLE 
读取
excel
文件中的内容,放入类型为
alsmex_tabline
的内中。然后你可以把这个表中的内容插入到你想放入的内表中:

REPORT ZIMPEXCEL .
TYPES: BEGIN OF ty_upload,
         field1(12) TYPE c,
         field2(12) TYPE c,
         field3(12) TYPE c,
       END OF ty_upload.

DATA: it_upload TYPE STANDARD TABLE OF ty_upload,
      wa_upload TYPE ty_upload,
      itab TYPE STANDARD TABLE OF alsmex_tabline WITH DEFAULT KEY.

FIELD-SYMBOLS: <wa_itab> TYPE alsmex_tabline.

CALL FUNCTION ‘ALSM_EXCEL_TO_INTERNAL_TABLE’
  EXPORTING
    FILENAME                      = ‘c:/test.xls’
    I_BEGIN_COL                   = 1
    I_BEGIN_ROW                   = 1
    I_END_COL                     = 3
    I_END_ROW                     = 65535
  TABLES
    INTERN                        = itab
  EXCEPTIONS
    INCONSISTENT_PARAMETERS       = 1
    UPLOAD_OLE                    = 2
    OTHERS                        = 3.
IF SY-SUBRC <> 0.
ENDIF.
SORT itab BY row.
LOOP AT itab ASSIGNING <wa_itab>.
  CASE <wa_itab>-col.
  WHEN ‘0001’.
    wa_upload-field1 = <wa_itab>-value.
  WHEN ‘0002’.
    wa_upload-field2 = <wa_itab>-value.
  WHEN ‘0003’.
    wa_upload-field3 = <wa_itab>-value.
  ENDCASE.
  AT END OF row.
    APPEND wa_upload TO it_upload.
    CLEAR wa_upload.
  ENDAT.
ENDLOOP.
 

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/18251.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论