ABAP上传Excel中的数据到ALV输出内表
2019-07-22 本文已影响0人
JayDragon
选择屏幕上定义上传文件的输入框:
PARAMETERS p_fname TYPE localfile.
获取上传文件:
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
mask = ',Excel Files,*.XLS;*.XLSX;'
mode = 'O'
title = 'Select upload file'
IMPORTING
filename = p_fname
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
将获取的文件转换成内表数据:
DATA: gt_excel TYPE TABLE OF alsmex_tabline WITH HEADER LINE,
gt_out TYPE TABLE OF ty_out,
gs_out TYPE ty_out.
FIELD-SYMBOLS: <fs_value>.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_fname
i_begin_col = 1
i_begin_row = 2
i_end_col = 8
i_end_row = 65535
TABLES
intern = gt_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
gt_excel具有如下结构:
gt_excel内表结构.png
处理gt_excel数据到输出ALV数据的内表中:
SORT gt_excel BY row col.
LOOP AT gt_excel.
...
可以在这里对上传的数据做一些处理,譬如数量不能为0,时间及日期格式的处理等等
...
ASSIGN COMPONENT gt_excel-col OF STRUCTURE gs_out TO <fs_value>.
<fs_value> = gt_excel-value.
AT END OF row.
APPEND gs_out TO gt_out.
CLEAR gs_out.
ENDAT.
ENDLOOP.