【ABAP系列】SAP ABAP下载带密码的Excel文件
公众号:matinal
本文作者:matinal
前言部分
大家可以关注我的公众号,公众号里的排版更好,阅读更舒适。
正文部分
REPORT ztest. DATA : BEGIN OF li_makt OCCURS 0, matnr TYPE matnr, maktx TYPE maktx, END OF li_makt. DATA: BEGIN OF li_head OCCURS 0, field(30) TYPE c, END OF li_head. SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-002. PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY. SELECTION-SCREEN END OF BLOCK b2. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. PERFORM browse_file CHANGING p_file. START-OF-SELECTION. REFRESH li_head. DEFINE mc_head. li_head-field = &1. APPEND li_head. END-OF-DEFINITION. SELECT matnr maktx INTO TABLE li_makt FROM makt UP TO 20 ROWS WHERE spras = sy-langu . mc_head : 'Material No', 'Material Description'. CALL FUNCTION 'EXCEL_OLE_STANDARD_DAT' EXPORTING file_name = p_file create_pivot = 0 data_sheet_name = 'Data Material' pivot_sheet_name = ' ' password = 'plazapp' password_option = 1 TABLES data_tab = li_makt fieldnames = li_head EXCEPTIONS file_not_exist = 1 filename_expected = 2 communication_error = 3 ole_object_method_error = 4 ole_object_property_error = 5 invalid_filename = 6 invalid_pivot_fields = 7 download_problem = 8 OTHERS = 9. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. FORM browse_file CHANGING p_file LIKE rlgrap-filename. DATA: filetab TYPE filetable, rc TYPE i, lv_offset TYPE i. FREE filetab. CALL METHOD cl_gui_frontend_services=>file_open_dialog EXPORTING window_title = 'Choose File' default_extension = '*.*' default_filename = 'c:\*.xls' CHANGING file_table = filetab rc = rc EXCEPTIONS file_open_dialog_failed = 1 cntl_error = 2 error_no_gui = 3 OTHERS = 4. IF sy-subrc = 0. READ TABLE filetab INTO p_file INDEX 1. ENDIF. ENDFORM. " browse_file
公众号:matinal
本博作者:matinal
-------------------------------------------
欢迎来到matinal的博客
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!