REPORT ZSAPTIP_002.
*&-------------------------------------------------------------*
*& DATA & TABLES DEFINE
*&-------------------------------------------------------------*
TYPE-POOLS: CTSLG.
TABLES: E070.
DATA: BEGIN OF GT_STDOUT OCCURS 0,
LINE(700),
END OF GT_STDOUT.
DATA: BEGIN OF GT_RELEASE OCCURS 0,
STEPID TYPE TSTRFCOFIL-FUNCTION,
RC TYPE TSTRFCOFIL-RETCODE,
END OF GT_RELEASE.
DATA: GT_EPSFILI LIKE EPSFILI OCCURS 0 WITH HEADER LINE.
DATA: GS_COFILE TYPE CTSLG_COFILE,
GS_SYSTEM TYPE CTSLG_SYSTEM,
GS_STEP TYPE CTSLG_STEP.
DATA: GV_PATH LIKE SAPB-SAPPFAD,
GV_TARGETPATH LIKE SAPB-SAPPFAD,
GV_FILENAME(30),
GV_DIR_NAME LIKE EPSF-EPSDIRNAM,
GV_FILE_MASK LIKE EPSF-EPSFILNAM,
CMD(255).
PARAMETERS: P_TRKORR LIKE E070-TRKORR OBLIGATORY.
*&-------------------------------------------------------------*
START-OF-SELECTION.
*&-------------------------------------------------------------*
SELECT SINGLE *
FROM E070
WHERE TRKORR = P_TRKORR.
IF
LEAVE LIST-PROCESSING.
ENDIF.
PERFORM CHECK_RELEASE.
PERFORM FILE_DOWN.
*&-------------------------------------------------------------*
*& Form CHECK_RELEASE
*&-------------------------------------------------------------*
form CHECK_RELEASE .
CALL FUNCTION 'TR_READ_GLOBAL_INFO_OF_REQUEST'
EXPORTING
IV_TRKORR = P_TRKORR
IMPORTING
ES_COFILE = GS_COFILE.
LOOP AT GS_COFILE-SYSTEMS INTO GS_SYSTEM.
LOOP AT GS_SYSTEM-STEPS INTO GS_STEP.
GT_RELEASE-STEPID = GS_STEP-STEPID.
GT_RELEASE-RC = GS_STEP-RC.
COLLECT GT_RELEASE.
ENDLOOP.
ENDLOOP.
LOOP AT GT_RELEASE WHERE STEPID = 'E'.
EXIT.
ENDLOOP.
IF
WRITE:/ '요청', P_TRKORR, '이 릴리즈되지 않았습니다.'.
STOP.
ENDIF.
endform. " CHECK_RELEASE
*&-------------------------------------------------------------*
*& Form FILE_DOWN
*&-------------------------------------------------------------*
form FILE_DOWN .
CMD = 'pwd'.
CALL 'SYSTEM' ID 'COMMAND' FIELD CMD
ID 'TAB' FIELD GT_STDOUT-*SYS*.
READ TABLE GT_STDOUT INDEX 1.
CHECK SY-SUBRC EQ 0.
GV_DIR_NAME = GT_STDOUT.
CONCATENATE 'tar cvf - `find /usr/sap/trans -name ''*'
P_TRKORR+4(6)
'*'' -print`'
INTO CMD.
CONCATENATE 'bona' P_TRKORR '.tar' INTO GV_FILENAME.
CONCATENATE CMD '>' GV_FILENAME
INTO CMD SEPARATED BY SPACE.
CALL 'SYSTEM' ID 'COMMAND' FIELD CMD
ID 'TAB' FIELD GT_STDOUT-*SYS*.
GV_FILE_MASK = GV_FILENAME.
CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
EXPORTING
DIR_NAME = GV_DIR_NAME
FILE_MASK = GV_FILE_MASK
TABLES
DIR_LIST = GT_EPSFILI
EXCEPTIONS
INVALID_EPS_SUBDIR = 1
SAPGPARAM_FAILED = 2
BUILD_DIRECTORY_FAILED = 3
NO_AUTHORIZATION = 4
READ_DIRECTORY_FAILED = 5
TOO_MANY_READ_ERRORS = 6
EMPTY_DIRECTORY_LIST = 7
OTHERS = 8.
SORT GT_EPSFILI BY SIZE DESCENDING.
READ TABLE GT_EPSFILI INDEX 1.
CHECK GT_EPSFILI-SIZE > 0.
CONCATENATE GV_DIR_NAME '/' GV_FILENAME INTO GV_PATH.
CONCATENATE 'C:' GV_FILENAME INTO GV_TARGETPATH.
CALL FUNCTION 'ARCHIVFILE_SERVER_TO_CLIENT'
EXPORTING
PATH = GV_PATH
TARGETPATH = GV_TARGETPATH
EXCEPTIONS
ERROR_FILE = 1
OTHERS = 2.
IF SY-SUBRC = 0.
WRITE:/ '파일 다운로드 완료:', GV_TARGETPATH.
ELSE.
WRITE:/ '파일 다운로드 실패’.
STOP.
ENDIF.
endform. " FILE_DOWN