功能:下载请求号到本地文件(转)
***此程序已不知道出处,仅做记录*
*======================================================================*
* Initial idea and first release by Igor Yaskevitch (IBS), 2003 *
* Enhancements by Sergey Korolev, 2005 (Added F4 value *
* requests, authority checks, TMS function usage) *
*----------------------------------------------------------------------*
* Function : This is a utility tool for downloading binary *
* files of transport request to a Client PC *
*======================================================================*
REPORT YRS_DOWNLOAD_TRANSPORT_REQUEST.
PARAMETERS:
P_REQEST TYPE TRKORR OBLIGATORY,
P_FOLDER(255) TYPE C LOWER CASE, P_SEPR OBLIGATORY.
DATA:
FOLDER TYPE STRING,
RETVAL LIKE TABLE OF DDSHRETVAL WITH HEADER LINE,
FLDVALUE LIKE HELP_INFO-FLDVALUE,
TRANSDIR TYPE TEXT255,
FILENAME(255),
TRFILE(20) TYPE C,
* datatab TYPE TABLE OF text8192 WITH HEADER LINE,
BEGIN OF DATATAB OCCURS 0,
TEXT(8192) TYPE X,
END OF DATATAB,
LEN TYPE I,
FLEN TYPE I.
TYPE-POOLS: SABC, STMS, TRWBO.
INITIALIZATION.
CONCATENATE SY-SYSID 'K*' INTO P_REQEST.
IF SY-OPSYS = 'Windows NT'.
P_SEPR = '\'.
ELSE.
P_SEPR = '/'.
ENDIF.
* CALL FUNCTION 'WSAF_BUILD_SEPARATOR'
* IMPORTING
* separator = p_sepr
* EXCEPTIONS
* separator_not_maintained = 1
* wrong_call = 2
* wsaf_config_not_maintained = 3
* OTHERS = 4.
*
* IF sy-subrc NE 0.
* MESSAGE s001(00)
* WITH
* 'Unable to find out the separator symbol for the system.'(011).
* ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_REQEST.
DATA:
TT_SYSTEM TYPE TABLE OF TMSCSYS WITH HEADER LINE,
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.
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_REQEST = ES_SELECTED_REQUEST-TRKORR.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FOLDER.
DATA: TITLE TYPE STRING.
TITLE = 'Select target folder'(005).
CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_BROWSE
EXPORTING
WINDOW_TITLE = TITLE
CHANGING
SELECTED_FOLDER = FOLDER
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
OTHERS = 3.
CALL FUNCTION 'CONTROL_FLUSH'
EXCEPTIONS
CNTL_SYSTEM_ERROR = 1
CNTL_ERROR = 2
OTHERS = 3.
P_FOLDER = FOLDER.
AT SELECTION-SCREEN ON P_REQEST.
DATA: REQUEST_INFO TYPE STMS_WBO_REQUEST,
REQUEST_INFOS TYPE STMS_WBO_REQUESTS.
REFRESH REQUEST_INFOS.
CALL FUNCTION 'TMS_MGR_READ_TRANSPORT_REQUEST'
EXPORTING
IV_REQUEST = P_REQEST
IV_HEADER_ONLY = 'X'
IMPORTING
ET_REQUEST_INFOS = REQUEST_INFOS
EXCEPTIONS
READ_CONFIG_FAILED = 1
TABLE_OF_REQUESTS_IS_EMPTY = 2
SYSTEM_NOT_AVAILABLE = 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.
ENDIF.
CLEAR REQUEST_INFO.
READ TABLE REQUEST_INFOS INTO REQUEST_INFO INDEX 1.
IF SY-SUBRC NE 0
OR REQUEST_INFO-E070-TRKORR IS INITIAL.
MESSAGE E398(00) WITH 'Request'(006) P_REQEST 'not found'(007).
ELSEIF REQUEST_INFO-E070-TRSTATUS NE 'R'.
MESSAGE E398(00)
WITH 'You must release request'(008)
REQUEST_INFO-E070-TRKORR
'before downloading'(009).
ENDIF.
START-OF-SELECTION.
FOLDER = P_FOLDER.
CONCATENATE P_REQEST+3(7) '.' P_REQEST(3) INTO TRFILE.
CALL FUNCTION 'RSPO_R_SAPGPARAM'
EXPORTING
NAME = 'DIR_TRANS'
IMPORTING
VALUE = TRANSDIR
EXCEPTIONS
ERROR = 0
THERS = 0.
PERFORM COPY_FILE USING 'cofiles' TRFILE.
TRFILE(1) = 'R'.
PERFORM COPY_FILE USING 'data' TRFILE.
TRFILE(1) = 'D'.
PERFORM COPY_FILE USING 'data' TRFILE.
*---------------------------------------------------------------------*
* FORM. copy_file *
*---------------------------------------------------------------------*
* --> SUBDIR * * --> FNAME *
*---------------------------------------------------------------------*
FORM COPY_FILE USING SUBDIR FNAME.
DATA:
AUTH_FILENAME TYPE AUTHB-FILENAME,
GUI_FILENAME TYPE STRING.
CONCATENATE TRANSDIR SUBDIR FNAME
INTO FILENAME
SEPARATED BY P_SEPR.
REFRESH DATATAB.
CLEAR FLEN.
AUTH_FILENAME = FILENAME.
CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
EXPORTING
ACTIVITY = SABC_ACT_READ
FILENAME = AUTH_FILENAME
EXCEPTIONS
NO_AUTHORITY = 1
ACTIVITY_UNKNOWN = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
FORMAT COLOR COL_NEGATIVE.
WRITE: / 'Read access denied. File'(001),
FILENAME.
FORMAT COLOR OFF. EXIT.
ENDIF.
OPEN DATASET FILENAME FOR INPUT IN BINARY MODE.
IF SY-SUBRC NE 0.
FORMAT COLOR COL_TOTAL.
WRITE: / 'File open error'(010), FILENAME.
FORMAT COLOR OFF. EXIT.
ENDIF.
CLEAR FLEN.
DATA: MLEN TYPE I.
MLEN = 8192.
DO.
CLEAR LEN.
READ DATASET FILENAME INTO DATATAB MAXIMUM LENGTH MLEN LENGTH LEN.
FLEN = FLEN + LEN.
IF LEN > 0. APPEND DATATAB. ENDIF.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET FILENAME.
CONCATENATE P_FOLDER '\' FNAME INTO GUI_FILENAME.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
EXPORTING
BIN_FILESIZE = FLEN
FILENAME = GUI_FILENAME
FILETYPE = 'BIN'
CHANGING
DATA_TAB = DATATAB[]
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 24.
IF SY-SUBRC = 0.
WRITE: / 'File'(002), FILENAME, 'downloaded. Length'(003), FLEN.
ELSE.
FORMAT COLOR COL_NEGATIVE.
WRITE: / 'File download error. Filename:'(004), FILENAME.
FORMAT COLOR OFF.
ENDIF.
ENDFORM. "copy_file