货铺QQ群号:834508274
进群统一修改群名片,例如BJ_ABAP_森林木。群内禁止发广告及其他一切无关链接,小程序等,进群看公告,谢谢配合
不修改昵称会被不定期踢除,谢谢配合
有批导需求的时候,一般是首先下载模板,然后再上载。
下面模板的方式,通常使用SMW0先上载,再在程序中下载使用。
Excel模板如下:
首先:SMW0
Demo程序:
*& Report ZLM_DOWM_TMP01
*&
*&---------------------------------------------------------------------*
*&
*& 下载模板demo sap干货铺 sapliumeng
*&---------------------------------------------------------------------*
REPORT ZLM_DOWM_TMP01.
TABLES:SSCRFIELDS.
TYPE-POOLS:SLIS,ISOC.
DATA:LV_OBJID TYPE WWWDATATAB-OBJID VALUE 'ZLM_SPFLI'. "SWMO 上载模板ID
SELECTION-SCREEN:FUNCTION KEY 1.
PARAMETERS :P_FILE LIKE RLGRAP-FILENAME .
INITIALIZATION.
SSCRFIELDS-FUNCTXT_01 = '下载模板'.
AT SELECTION-SCREEN.
CASE SSCRFIELDS-UCOMM.
WHEN 'FC01'.
PERFORM FRM_DOWN_TMPLT USING LV_OBJID.
WHEN 'ONLI'.
WHEN OTHERS.
ENDCASE.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM FRM_FILE_OPEN CHANGING P_FILE.
FORM FRM_DOWN_TMPLT USING P_OBJID TYPE WWWDATATAB-OBJID.
DATA: P_FILE TYPE IBIPPARMS-PATH.
DATA: LO_OBJDATA LIKE WWWDATATAB,
LC_FILENAME TYPE STRING , "
LC_FULLPATH TYPE STRING VALUE 'C:\',
LC_PATH TYPE STRING VALUE 'C:\',
LS_DESTINATION LIKE RLGRAP-FILENAME,
LI_RC LIKE SY-SUBRC.
* DATA: p_objid TYPE wwwdatatab-objid .
DATA: P_DEST LIKE SAPB-SAPPFAD.
CONCATENATE P_OBJID '上载模板.xlsx' INTO LC_FILENAME.
"down
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG "
EXPORTING
DEFAULT_EXTENSION = 'XLS'
DEFAULT_FILE_NAME = LC_FILENAME
CHANGING
FILENAME = LC_FILENAME
PATH = LC_PATH
FULLPATH = LC_FULLPATH "full path
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4.
IF LC_FULLPATH = ''.
RETURN.
ENDIF.
LS_DESTINATION = LC_FULLPATH.
"check
SELECT SINGLE RELID OBJID
FROM WWWDATA INTO CORRESPONDING FIELDS OF LO_OBJDATA
WHERE SRTF2 = 0
AND RELID = 'MI'
AND OBJID = P_OBJID.
IF SY-SUBRC NE 0 OR LO_OBJDATA-OBJID EQ SPACE.
MESSAGE '模板下载失败' TYPE 'E'.
ENDIF.
"down
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
KEY = LO_OBJDATA
DESTINATION = LS_DESTINATION
IMPORTING
RC = LI_RC.
IF LI_RC NE 0.
MESSAGE TEXT-E11 TYPE 'E'.
ENDIF.
ENDFORM. " FRM_DOWN_TMPLT
FORM FRM_FILE_OPEN CHANGING P_FILE.
DATA: LV_FILE TYPE STRING.
CLEAR LV_FILE.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
MASK = ',Excel file,*.xls;*.xlsx;'
TITLE = '选择文件'(100)
IMPORTING
FILENAME = LV_FILE
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
IF SY-SUBRC <> 0 AND SY-SUBRC <> 3.
MESSAGE '选择文件出错!'(007) TYPE 'E'.
ENDIF.
P_FILE = LV_FILE.
ENDFORM. " FRM_FILE_OPEN
如果上载过程中报错:
这个解决办法很简单,只需要维护下就行了
demo 代码可以copy过去,略作调整即可使用,比从头写快的多。