SMW0 Excel下载-将功能封装成RFC函数

SMW0 模板上载:

http://www.baidusap.com/abap/others/3239

 

RFC函数:

function z_pub_excel_download_from_smw0 .
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(I_OBJID) TYPE  WWWDATATAB-OBJID OPTIONAL
*"     VALUE(I_FIELDNAME) TYPE  STRING OPTIONAL
*"  EXPORTING
*"     VALUE(E_RETURN) TYPE  BAPIRET2
*"----------------------------------------------------------------------
*--此函数用于,在SWM0上传后,通过此函数下载到本地;
*
* 相关变量定义
  data:lo_objdata     like wwwdatatab,
        lo_mime        like w3mime,
        lc_fullpath    type string value 'c:',
        lc_path        type string value 'c:',
        ls_destination like rlgrap-filename,
        ls_objnam      type string,
        l_rc           like sy-subrc,
        ls_errtxt      type string,
        l_dest         like sapb-sappfad.

* 模板下载路径名
  call method cl_gui_frontend_services=>file_save_dialog
  exporting
    window_title              = '模板下载'
    default_extension         = 'xlsx'
    default_file_name         = i_fieldname
  changing
    filename                  = i_fieldname
    path                      = lc_path
    fullpath                  = lc_fullpath
  exceptions
    cntl_error                = 1
    error_no_gui              = 2
    not_supported_by_gui      = 3
    invalid_default_file_name = 4
    others                    = 5.
* 没有选择路径
  if lc_fullpath = ''.
    e_return-type = 'E'.
    e_return-message =  '请选择正确的路径!'.
    return.
  else.
*-  路径名
    l_dest = lc_fullpath.

    select single
    relid                   "IMPORT/EXPORT 记录中的区域
    objid                   "SAP WWW 网关对象名
    from wwwdata
    into corresponding fields of lo_objdata
    where srtf2 = 0
    and relid = 'MI'
    and objid = i_objid.

    if sy-subrc <> 0 or lo_objdata-objid is initial.
      e_return-type = 'E'.
      e_return-message =  '没有获得模板数据'.
      return.
    endif.

    ls_destination = l_dest.
    call function 'DOWNLOAD_WEB_OBJECT'
    exporting
      key         = lo_objdata
      destination = ls_destination
    importing
      rc          = l_rc.
    if l_rc <> 0.
      e_return-type = 'E'.
      e_return-message =  '模板下载失败'.
      return.
    endif.
  endif.

endfunction.

 

函数调用:

REPORT ztest1.

data: lv_objid  type w3objid,
      ls_return type bapiret2.

lv_objid = 'XXXX'.    "SMW0定义的对象名称

clear ls_return.

call function 'Z_PUB_EXCEL_DOWNLOAD_FROM_SMW0'
exporting
  i_objid     = lv_objid
  i_fieldname = '模板下载'
importing
  e_return    = ls_return.

if ls_return-type eq 'E'.
  message ls_return-message type 'S' display like 'E'.
  stop.
endif.

 

posted @ 2021-01-08 17:10  肆意点  阅读(112)  评论(0编辑  收藏  举报