智慧屏安装APP的最佳实践与跨平台小程序开发的结合
806
2022-11-26
动态上传excel数据到DB表
因为练习系统是IDES,没数据。
所以从其他系统导出部分数据到excel,然后上传到IDES。
如果是spfli等航班表不需要这样,直接参考下面的就行
TYPE any, .*&---------------------------------------------------------------------**& SELECTION-SCREEN ON VALUE-REQUEST*&---------------------------------------------------------------------*"file F4AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. CALL FUNCTION 'F4_FILENAME' IMPORTING file_name = p_file.*&---------------------------------------------------------------------**& START-OF-SELECTION*&---------------------------------------------------------------------*START-OF-SELECTION. "file name lv_filename = p_file. "upload excel data CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' EXPORTING filename = lv_filename i_begin_col = 1 i_begin_row = 2 i_end_col = 40 i_end_row = 999 TABLES intern = lt_excel EXCEPTIONS inconsistent_parameters = 1 upload_ole = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE 'ALSM_EXCEL_TO_INTERNAL_TABLE Error' TYPE 'E'. ENDIF.*创建动态表结构 CREATE DATA dyn_table TYPE TABLE OF (p_name).*创建动态内表 ASSIGN dyn_table->* TO .*创建动态工作区结构 CREATE DATA dyn_wa LIKE LINE OF .*创建动态工作区 ASSIGN dyn_wa->* TO . SORT lt_excel BY row col. TRY. CLEAR lv_index. LOOP AT lt_excel INTO ls_excel. MOVE ls_excel-col TO lv_index. ASSIGN COMPONENT lv_index OF STRUCTURE TO . CONDENSE ls_excel-value NO-GAPS. MOVE ls_excel-value TO . AT END OF row. APPEND TO . "user defined internal table to store excel data CLEAR . ENDAT. CLEAR ls_excel. ENDLOOP. CATCH cx_root INTO exception. MESSAGE 'Excel data format is wrong,please check' TYPE 'E'. ENDTRY. INSERT (p_name) FROM TABLE ACCEPTING DUPLICATE KEYS. IF sy-subrc <> 0. MESSAGE 'Please check DB data' TYPE 'E'. else. MESSAGE 'OK' TYPE 'S' DISPLAY LIKE 'I'. ENDIF.
这里注意一点
金额,数量,时间,日期等,excel里的格式需要调整。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~