此功能使用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.