ABAP 模板檔案上傳下載
阿新 • • 發佈:2018-12-10
此功能使用SAP標準模板檔案功能:SMW0
第一步 選擇你需要建立的模板儲存型別
2.輸入儲存包,查詢既存的模板檔案
3,結果畫面選擇新建,輸入物件名稱和描述,匯入自己的模板(需要修改模板點選修改筆就可以)
儲存到對應的傳入依賴就可以了,這樣可以把模板檔案跟程式一起傳輸到生產機
模板傳輸好後,使用者需要下載模板檔案
DATA: lv_filename TYPE string, lv_path TYPE string, lv_fullpath TYPE string, lv_user_action TYPE i, lv_destination LIKE rlgrap-filename, ls_objdata LIKE wwwdatatab, lv_objid TYPE wwwdatatab-objid, lv_rc TYPE sy-subrc. CHECK sy-ucomm = 'DOWN'. lv_filename = '物料主資料批量匯入'. CONCATENATE sy-datum '_' sy-uzeit '_' lv_filename INTO lv_filename. * 獲取模板儲存路勁 CALL METHOD cl_gui_frontend_services=>file_save_dialog EXPORTING * window_title = default_extension = 'XLSX' default_file_name = lv_filename * with_encoding = * file_filter = initial_directory = lv_path * prompt_on_overwrite = 'X' CHANGING filename = lv_filename path = lv_path fullpath = lv_fullpath user_action = lv_user_action * file_encoding = EXCEPTIONS cntl_error = 1 error_no_gui = 2 not_supported_by_gui = 3 OTHERS = 4. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ELSE. CLEAR: lv_destination. lv_destination = lv_fullpath. ENDIF. CHECK lv_user_action <> 9. SELECT SINGLE relid objid FROM wwwdata INTO CORRESPONDING FIELDS OF ls_objdata WHERE srtf2 = 0 AND objid = c_objid "匯入模板時輸入的物件名稱 AND relid = 'MI'. IF sy-subrc = 0. CLEAR: lv_rc. CALL FUNCTION 'DOWNLOAD_WEB_OBJECT' "#EC * EXPORTING key = ls_objdata destination = lv_destination IMPORTING rc = lv_rc. IF lv_rc NE 0. MESSAGE '該資料模板不存在!' TYPE 'E'. ELSE. MESSAGE '模板下載成功' TYPE 'S'. ENDIF. ELSE. MESSAGE '該資料模板不存在!' TYPE 'E'. ENDIF.