上传下载员工照片(HR Photo)
批量上传图片
*&---------------------------------------------------------------------*
*& Report ZCHJ_HR001 *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT Z_BARRY_HR_PHOTO_UPLOAD.
TABLES:PA0001.
DATA: SAPOBJID LIKE SAPB-SAPOBJID,
SAPPFAD LIKE SAPB-SAPPFAD.
*& Report ZCHJ_HR001 *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT Z_BARRY_HR_PHOTO_UPLOAD.
TABLES:PA0001.
DATA: SAPOBJID LIKE SAPB-SAPOBJID,
SAPPFAD LIKE SAPB-SAPPFAD.
DATA: GD_PATH TYPE STRING ,
FILETAB TYPE TABLE OF FILE_INFO WITH HEADER LINE,
COUNT TYPE I.
DATA: FILENAME(40) TYPE C ,
FILEEXT(10) TYPE C ,
LEN TYPE I .
*重点图片名称要等于系统员工编号
PARAMETERS: FILEPATH LIKE RLGRAP-FILENAME."上传文件夹路径
AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILEPATH.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_BROWSE
EXPORTING
WINDOW_TITLE = 'File Directory'
INITIAL_FOLDER = 'C:\'
CHANGING
FILETAB TYPE TABLE OF FILE_INFO WITH HEADER LINE,
COUNT TYPE I.
DATA: FILENAME(40) TYPE C ,
FILEEXT(10) TYPE C ,
LEN TYPE I .
*重点图片名称要等于系统员工编号
PARAMETERS: FILEPATH LIKE RLGRAP-FILENAME."上传文件夹路径
AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILEPATH.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_BROWSE
EXPORTING
WINDOW_TITLE = 'File Directory'
INITIAL_FOLDER = 'C:\'
CHANGING
SELECTED_FOLDER = GD_PATH.
CALL METHOD CL_GUI_CFW=>FLUSH.
CONCATENATE GD_PATH '' INTO FILEPATH.
START-OF-SELECTION.
GD_PATH = FILEPATH .
CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES
EXPORTING
DIRECTORY = GD_PATH
FILTER = '*.jpg'
CHANGING
FILE_TABLE = FILETAB[]
COUNT = COUNT
EXCEPTIONS
CNTL_ERROR = 1
CALL METHOD CL_GUI_CFW=>FLUSH.
CONCATENATE GD_PATH '' INTO FILEPATH.
START-OF-SELECTION.
GD_PATH = FILEPATH .
CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES
EXPORTING
DIRECTORY = GD_PATH
FILTER = '*.jpg'
CHANGING
FILE_TABLE = FILETAB[]
COUNT = COUNT
EXCEPTIONS
CNTL_ERROR = 1
DIRECTORY_LIST_FILES_FAILED = 2
WRONG_PARAMETER = 3
ERROR_NO_GUI = 4connect下载
NOT_SUPPORTED_BY_GUI = 5
OTHERS = 6.
*判断图片编号是否等于8位
LOOP AT FILETAB.
SPLIT FILETAB-FILENAME AT '.' INTO FILENAME FILEEXT.
LEN = STRLEN( FILENAME ) .
IF LEN <> 8 .
MESSAGE E000(OO) WITH '文件名长度必须等于8位'.
ENDIF.
ENDLOOP.
LOOP AT FILETAB.
WRONG_PARAMETER = 3
ERROR_NO_GUI = 4connect下载
NOT_SUPPORTED_BY_GUI = 5
OTHERS = 6.
*判断图片编号是否等于8位
LOOP AT FILETAB.
SPLIT FILETAB-FILENAME AT '.' INTO FILENAME FILEEXT.
LEN = STRLEN( FILENAME ) .
IF LEN <> 8 .
MESSAGE E000(OO) WITH '文件名长度必须等于8位'.
ENDIF.
ENDLOOP.
LOOP AT FILETAB.
*判断员工编号是否存在
SELECT SINGLE *
FROM PA0001
WHERE PERNR = FILETAB-FILENAME+0(8).
IF SY-SUBRC = 0.
SELECT SINGLE *
FROM PA0001
WHERE PERNR = FILETAB-FILENAME+0(8).
IF SY-SUBRC = 0.
*判断员工编号是否已过期
SELECT SINGLE *
FROM PA0001
WHERE PERNR = FILETAB-FILENAME+0(8)
AND BEGDA =< SY-DATUM
AND ENDDA >= SY-DATUM.
IF SY-SUBRC = 0.
CONCATENATE GD_PATH '\' FILETAB-FILENAME INTO SAPPFAD.
CONCATENATE FILETAB-FILENAME+0(8) '0002' INTO SAPOBJID.
CALL FUNCTION 'ARCHIV_CREATE_FILE'
SELECT SINGLE *
FROM PA0001
WHERE PERNR = FILETAB-FILENAME+0(8)
AND BEGDA =< SY-DATUM
AND ENDDA >= SY-DATUM.
IF SY-SUBRC = 0.
CONCATENATE GD_PATH '\' FILETAB-FILENAME INTO SAPPFAD.
CONCATENATE FILETAB-FILENAME+0(8) '0002' INTO SAPOBJID.
CALL FUNCTION 'ARCHIV_CREATE_FILE'
EXPORTING
AR_OBJECT = 'HRICOLFOTO'
OBJECT_ID = SAPOBJID
SAP_OBJECT = 'PREL'
DOC_TYPE = 'JPG'
PATH = SAPPFAD
EXCEPTIONS
ERROR_CONECTIONTABLE = 1
ERROR_PARAMETER = 2
ERROR_ARCHIV = 3
ERROR_UPLOAD = 4
ERROR_KERNEL = 5
NO_ENTRY_POSSIBLE = 6
ERROR_COMUNICATIONTABLE = 7
OTHERS = 8.
AR_OBJECT = 'HRICOLFOTO'
OBJECT_ID = SAPOBJID
SAP_OBJECT = 'PREL'
DOC_TYPE = 'JPG'
PATH = SAPPFAD
EXCEPTIONS
ERROR_CONECTIONTABLE = 1
ERROR_PARAMETER = 2
ERROR_ARCHIV = 3
ERROR_UPLOAD = 4
ERROR_KERNEL = 5
NO_ENTRY_POSSIBLE = 6
ERROR_COMUNICATIONTABLE = 7
OTHERS = 8.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
WRITE : / 'Upload ',SAPPFAD,'To pernr ',FILETAB-FILENAME+0(8),'Sccuess!'.
ENDIF.
ELSE.
WRITE : / 'ERROR ',SAPPFAD, '此员工编号 ', FILETAB-FILENAME+0(8),'已过期!'.
ENDIF.
ELSE.
WRITE : / 'ERROR ',SAPPFAD, '此员工编号 ', FILETAB-FILENAME+0(8),'不存在!'.
ENDIF.
ENDLOOP.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
WRITE : / 'Upload ',SAPPFAD,'To pernr ',FILETAB-FILENAME+0(8),'Sccuess!'.
ENDIF.
ELSE.
WRITE : / 'ERROR ',SAPPFAD, '此员工编号 ', FILETAB-FILENAME+0(8),'已过期!'.
ENDIF.
ELSE.
WRITE : / 'ERROR ',SAPPFAD, '此员工编号 ', FILETAB-FILENAME+0(8),'不存在!'.
ENDIF.
ENDLOOP.
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论