*&---------------------------------------------------------------------*
*& REPORT Z_UP_DOWN_REQUEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_UP_DOWN_REQUEST.
TYPE-POOLS: TRWBO, STMS.
DATA:
ES_SELECTED_REQUEST TYPE TRWBO_REQUEST_HEADER,
ES_SELECTED_TASK TYPE TRWBO_REQUEST_HEADER,
IV_ORGANIZER_TYPE TYPE TRWBO_CALLING_ORGANIZER,
IS_SELECTION TYPE TRWBO_SELECTION.
DATA: FOLDER TYPE STRING ,
FLAG TYPE C ,
DIR_TRANS TYPE TEXT255 ,
PATH2 TYPE TEXT255 ,
LOCALFOLDER(128) TYPE C ,
UPFILENAME(11) TYPE C.
DATA:
LT_REQUEST TYPE STMS_TR_REQUESTS,
LT_TP_MAINTAIN TYPE STMS_TP_MAINTAINS.
DATA:
ET_REQUEST_INFOS TYPE STMS_WBO_REQUESTS,
REQUEST_INFO TYPE STMS_WBO_REQUEST,
REQUEST LIKE E070-TRKORR.
DATA: BEGIN OF IT_MEMO OCCURS 0 ,
LINE(255) TYPE C,
END OF IT_MEMO.
DATA: ERROR LIKE BOOLE-BOOLE ,
ERR_TXT(100) TYPE C .
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE T1.
PARAMETERS: DOWNLOAD RADIOBUTTON GROUP TYP USER-COMMAND SELE DEFAULT ‘X‘.
PARAMETERS: UPLOAD RADIOBUTTON GROUP TYP.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE T2.
PARAMETERS: P_FILE(255) TYPE C LOWER CASE MODIF ID M2,
P_CLIENT LIKE TMSBUFFER-TARCLI DEFAULT SY-MANDT
MATCHCODE OBJECT H_T000 MODIF ID M2.
SELECTION-SCREEN END OF BLOCK B2.
SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE T3.
PARAMETERS:P_REQNUM TYPE TRKORR MODIF ID M3,
P_FOLDER LIKE RLGRAP-FILENAME DEFAULT ‘C:\‘ LOWER CASE MODIF ID M3 ,
P_MEMO(255) TYPE C MODIF ID M3.
SELECTION-SCREEN END OF BLOCK B3.
INITIALIZATION.
T1 = ‘选择功能‘.
T2 = ‘上传参数‘.
T3 = ‘下载参数‘.
IF SY-OPSYS = ‘WINDOWS NT‘.
FLAG = ‘\‘.
ELSE.
FLAG = ‘/‘.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_REQNUM.
IV_ORGANIZER_TYPE = ‘W‘.
IS_SELECTION-REQSTATUS = ‘R‘.
CALL FUNCTION ‘TR_PRESENT_REQUESTS_SEL_POPUP‘
EXPORTING
IV_ORGANIZER_TYPE = IV_ORGANIZER_TYPE
IS_SELECTION = IS_SELECTION
IMPORTING
ES_SELECTED_REQUEST = ES_SELECTED_REQUEST
ES_SELECTED_TASK = ES_SELECTED_TASK.
P_REQNUM = ES_SELECTED_REQUEST-TRKORR.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FOLDER.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_BROWSE
CHANGING
SELECTED_FOLDER = FOLDER
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
OTHERS = 3.
P_FOLDER = FOLDER.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
DATA:
FILE TYPE FILE_TABLE,
RC TYPE I,
FILE_TABLE TYPE FILETABLE,
FILE_FILTER TYPE STRING VALUE ‘(K*.*)|K*.*||‘.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
EXPORTING
FILE_FILTER = FILE_FILTER
CHANGING
FILE_TABLE = FILE_TABLE
RC = RC
EXCEPTIONS
FILE_OPEN_DIALOG_FAILED = 1
CNTL_ERROR = 2
ERROR_NO_GUI = 3
NOT_SUPPORTED_BY_GUI = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
READ TABLE FILE_TABLE INTO FILE INDEX 1.
P_FILE = FILE.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
CASE SCREEN-GROUP1.
WHEN ‘M2‘.
IF DOWNLOAD = ‘X‘.
SCREEN-ACTIVE = ‘0‘.
ELSE.
SCREEN-ACTIVE = ‘1‘.
ENDIF.
WHEN ‘M3‘.
IF DOWNLOAD = ‘X‘.
SCREEN-ACTIVE = ‘1‘.
ELSE.
SCREEN-ACTIVE = ‘0‘.
ENDIF.
ENDCASE.
MODIFY SCREEN.
ENDLOOP.
START-OF-SELECTION.
CALL FUNCTION ‘RSPO_R_SAPGPARAM‘
EXPORTING
NAME = ‘DIR_TRANS‘
IMPORTING
VALUE = DIR_TRANS
EXCEPTIONS
ERROR = 0
OTHERS = 0.
IF DOWNLOAD = ‘X‘.
IF P_REQNUM = ‘‘ OR P_FOLDER = ‘‘.
MESSAGE ‘必须输入请求号和地址‘ TYPE ‘I‘.
EXIT.
ENDIF.
PERFORM DOWNLOADREQUEST.
ELSE.
IF P_CLIENT = ‘‘ OR P_FILE = ‘‘ .
MESSAGE ‘必须输入文件名和CLIENT‘ TYPE ‘I‘.
EXIT.
ENDIF.
PERFORM UPLOADREQUEST.
PERFORM ADDREQUEST.
ENDIF.
*&---------------------------------------------------------------------*
*& FORM DOWNLOADREQUEST
*&---------------------------------------------------------------------*
FORM DOWNLOADREQUEST .
CONCATENATE P_REQNUM+3(7) ‘.‘ P_REQNUM(3) INTO P_REQNUM.
CONCATENATE DIR_TRANS ‘COFILES‘ P_REQNUM INTO PATH2 SEPARATED BY FLAG.
CONCATENATE P_FOLDER ‘\‘ P_REQNUM INTO LOCALFOLDER.
PERFORM DOWN_FILE USING PATH2
LOCALFOLDER .
P_REQNUM(1) = ‘R‘.
CONCATENATE DIR_TRANS ‘DATA‘ P_REQNUM INTO PATH2 SEPARATED BY FLAG.
CONCATENATE P_FOLDER ‘\‘ P_REQNUM INTO LOCALFOLDER.
PERFORM DOWN_FILE USING PATH2
LOCALFOLDER .
IF P_MEMO <> ‘‘.
DATA STR TYPE STRING.
IT_MEMO-LINE = P_MEMO.
APPEND IT_MEMO.
P_REQNUM(1) = ‘K‘.
P_REQNUM+8(3) = ‘TXT‘.
CONCATENATE P_FOLDER ‘\‘ P_REQNUM INTO LOCALFOLDER.
STR = LOCALFOLDER .
CALL FUNCTION ‘GUI_DOWNLOAD‘
EXPORTING
FILENAME = STR
TABLES
DATA_TAB = IT_MEMO.
ENDIF.
MESSAGE ‘成功下载!‘ TYPE ‘I‘.
ENDFORM. " DOWNLOADREQUEST
*&--------------------------------------------------------------------*
*& FORM DOWN_FILE
*&--------------------------------------------------------------------*
FORM DOWN_FILE USING P_PATH
FILE_NAME .
DATA: PATH LIKE RCGFILETR-FTAPPL .
DATA: LOCALFILE LIKE RCGFILETR-FTFRONT.
PATH = P_PATH .
LOCALFILE = FILE_NAME .
CLEAR:ERROR,ERR_TXT.
CALL FUNCTION ‘C13Z_FILE_DOWNLOAD_BINARY‘
EXPORTING
I_FILE_FRONT_END = LOCALFILE
I_FILE_APPL = PATH
I_FILE_OVERWRITE = ‘X‘
IMPORTING
E_FLG_OPEN_ERROR = ERROR
E_OS_MESSAGE = ERR_TXT
EXCEPTIONS
FE_FILE_OPEN_ERROR = 1
FE_FILE_EXISTS = 2
FE_FILE_WRITE_ERROR = 3
AP_NO_AUTHORITY = 4
AP_FILE_OPEN_ERROR = 5
AP_FILE_EMPTY = 6
OTHERS = 7.
IF SY-SUBRC <> 0.
IF SY-MSGTY = ‘‘ .
SY-MSGTY = ‘E‘ .
ENDIF .
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF ERROR = ‘X‘.
MESSAGE ERR_TXT TYPE ‘I‘.
STOP.
ENDIF.
ENDFORM. " DOWN_FILE
*&--------------------------------------------------------------------*
*& FORM UP_FILE
*&--------------------------------------------------------------------*
FORM UP_FILE USING P_PATH
FILE_NAME .
DATA: PATH LIKE RCGFILETR-FTAPPL .
DATA: LOCALFILE LIKE RCGFILETR-FTFRONT.
PATH = P_PATH .
LOCALFILE = FILE_NAME .
CLEAR:ERROR,ERR_TXT.
SY-CPROG = ‘RC1TCG3Y‘.
CALL FUNCTION ‘C13Z_FILE_UPLOAD_BINARY‘
EXPORTING
I_FILE_FRONT_END = LOCALFILE
I_FILE_APPL = PATH
I_FILE_OVERWRITE = ‘X‘
IMPORTING
E_FLG_OPEN_ERROR = ERROR
E_OS_MESSAGE = ERR_TXT
EXCEPTIONS
FE_FILE_NOT_EXISTS = 1
FE_FILE_READ_ERROR = 2
AP_NO_AUTHORITY = 3
AP_FILE_OPEN_ERROR = 4
AP_FILE_EXISTS = 5
OTHERS = 6.
IF SY-SUBRC <> 0.
IF SY-MSGTY = ‘‘ .
SY-MSGTY = ‘E‘ .
ENDIF .
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF ERROR = ‘X‘.
MESSAGE ERR_TXT TYPE ‘I‘.
STOP.
ENDIF.
* IF SY-SUBRC <> 0.
* CASE SY-SUBRC .
* WHEN 1 .
* MESSAGE ‘本地文件不存在!‘ TYPE ‘I‘ .
* WHEN 2 .
* MESSAGE ‘读取本地文件出错!‘ TYPE ‘I‘ .
* WHEN 3 .
* MESSAGE ‘服务器权限错误!‘ TYPE ‘I‘ .
* WHEN 4 .
* MESSAGE ‘服务器文件打开错误!‘ TYPE ‘I‘ .
* WHEN 5 .
* MESSAGE ‘服务器文件已经存在!‘ TYPE ‘I‘ .
* WHEN 6 .
* MESSAGE ‘其他错误!‘ TYPE ‘I‘ .
* ENDCASE .
* ENDIF.
ENDFORM. "UP_FILE
*&---------------------------------------------------------------------*
*& FORM UPLOADREQUEST
*&---------------------------------------------------------------------*
FORM UPLOADREQUEST .
DATA:
FILENAME LIKE SDBAH-ACTID ,
EXTENSION LIKE SDBAD-FUNCT,
N TYPE I ,
M TYPE I .
CALL FUNCTION ‘SPLIT_FILENAME‘
EXPORTING
LONG_FILENAME = P_FILE
IMPORTING
PURE_FILENAME = FILENAME
PURE_EXTENSION = EXTENSION.
CONCATENATE FILENAME ‘.‘ EXTENSION INTO UPFILENAME .
CONCATENATE EXTENSION FILENAME INTO REQUEST.
CONCATENATE DIR_TRANS ‘COFILES‘ UPFILENAME INTO PATH2 SEPARATED BY FLAG.
PERFORM UP_FILE USING PATH2
P_FILE .
UPFILENAME(1) = ‘R‘.
CONCATENATE DIR_TRANS ‘DATA‘ UPFILENAME INTO PATH2 SEPARATED BY FLAG.
N = STRLEN( P_FILE ).
M = N - 11 .
P_FILE+M(1) = ‘R‘.
PERFORM UP_FILE USING PATH2
P_FILE .
ENDFORM. " UPLOADREQUEST
*&---------------------------------------------------------------------*
*& FORM ADDREQUEST
*&---------------------------------------------------------------------*
FORM ADDREQUEST .
DATA SYSTEM LIKE TMSCSYS-SYSNAM .
SYSTEM = SY-SYSID.
CALL FUNCTION ‘TR_AUTHORITY_CHECK_ADMIN‘
EXPORTING
IV_ADMINFUNCTION = ‘TADD‘
EXCEPTIONS
E_NO_AUTHORITY = 1
E_INVALID_USER = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
EXIT.
ENDIF.
CALL FUNCTION ‘TMS_UI_APPEND_TR_REQUEST‘
EXPORTING
IV_SYSTEM = SYSTEM
IV_REQUEST = REQUEST
IV_EXPERT_MODE = ‘X‘
IV_CTC_ACTIVE = ‘X‘
EXCEPTIONS
CANCELLED_BY_USER = 1
APPEND_REQUEST_FAILED = 2
OTHERS = 3.
CHECK SY-SUBRC = 0.
CALL FUNCTION ‘TMS_MGR_READ_TRANSPORT_REQUEST‘
EXPORTING
IV_REQUEST = REQUEST
IV_TARGET_SYSTEM = SYSTEM
IMPORTING
ET_REQUEST_INFOS = ET_REQUEST_INFOS
EXCEPTIONS
READ_CONFIG_FAILED = 1
TABLE_OF_REQUESTS_IS_EMPTY = 2
SYSTEM_NOT_AVAILABLE = 3
OTHERS = 4.
CLEAR REQUEST_INFO.
READ TABLE ET_REQUEST_INFOS INTO REQUEST_INFO INDEX 1.
IF REQUEST_INFO-E070-KORRDEV = ‘CUST‘ AND NOT P_CLIENT IS INITIAL.
CALL FUNCTION ‘TMS_MGR_MAINTAIN_TR_QUEUE‘
EXPORTING
IV_COMMAND = ‘FILLCLIENT‘
IV_SYSTEM = SYSTEM
IV_REQUEST = REQUEST
IV_TARCLI = P_CLIENT
IV_MONITOR = ‘X‘
IV_VERBOSE = ‘X‘
IMPORTING
ET_TP_MAINTAINS = LT_TP_MAINTAIN
EXCEPTIONS
READ_CONFIG_FAILED = 1
TABLE_OF_REQUESTS_IS_EMPTY = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
EXIT.
ENDIF.
ENDIF.
CALL FUNCTION ‘TR_AUTHORITY_CHECK_ADMIN‘
EXPORTING
IV_ADMINFUNCTION = ‘IMPS‘
EXCEPTIONS
E_NO_AUTHORITY = 1
E_INVALID_USER = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
EXIT.
ENDIF.
CALL FUNCTION ‘TMS_UI_IMPORT_TR_REQUEST‘
EXPORTING
IV_SYSTEM = SYSTEM
IV_REQUEST = REQUEST
IV_TARCLI = P_CLIENT
IV_SOME_ACTIVE = SPACE
EXCEPTIONS
CANCELLED_BY_USER = 1
IMPORT_REQUEST_DENIED = 2
IMPORT_REQUEST_FAILED = 3
OTHERS = 4.
ENDFORM. " ADDREQUEST