PROGRAM ZAPC0013 MESSAGE-ID S1 LINE-SIZE 255.
*/******************************************************************/
*/* */
*/* Program still in development but the object of this */
*/* Program is to provide a sort of "XTREE FOR UNIX" */
*/* from SAP. */
*/* */
*/* At present you must supply a starting point for the UNIX */
*/* directory (as I don't know how to navigate UNIX from */
*/* scratch) */
*/* Only data set browse is possible */
*/* */
*/* Final program will attempt to be an "XTREE" clone for */
*/* UNIX with full directory search and data set edit functions. */
*/* */
*/* Display UNIX directories */
*/* Double click directory to get data set names */
*/* Double click again to get data set contents. */
*/* (Note - Data set contents may not be viewable) */
*/* */
*/* Jim Hawthorne Aug 1994 */
*/* */
*/* */
*/******************************************************************/
DATA: SAP_YES(1) VALUE 'X' ,
SAP_NO(1) VALUE ' ' ,
SRT(1) VALUE 'T',
NO_CS VALUE ' ', " no MUST_ContainString
ALL_GEN VALUE '*' , " generic filename - select all
STRLEN LIKE SY-FDPOS.
DATA: H_LIST_INDEX TYPE P, " hide with each data line; otherwise 0
FCODE(4) TYPE C.
DATA: BEGIN OF SEARCHPOINTS OCCURS 10,
DIRNAME(75) TYPE C, " name of directory.
SP_NAME(75) TYPE C, " name of entry. (may end with *)
SP_CS(10) TYPE C, " ContainsString pattern for name.
END OF SEARCHPOINTS.
DATA: GLOBALDIRECTORY(75) TYPE C.
DATA: BEGIN OF FILE,
DIRNAME(75) TYPE C, " name of directory. (possibly truncated.)
NAME(75) TYPE C, " name of entry. (possibly truncated.)
TYPE(10) TYPE C, " type of entry.
LEN(4) TYPE P, " length in bytes.
OWNER(8) TYPE C, " owner of the entry.
MTIME(6) TYPE P, " last modification date, seconds since 1970
MODE(9) TYPE C, " like "rwx-r-x--x": protection mode.
USEABLE(1) TYPE C,
SUBRC(4) TYPE C,
ERRNO(3) TYPE C,
ERRMSG(40) TYPE C,
MOD_DATE TYPE D,
MOD_TIME(8) TYPE C, " hh:mm:ss
SEEN(1) TYPE C,
CHANGED(1) TYPE C,
END OF FILE.
DATA: BEGIN OF FILE_KEY,
DIRNAME(75) TYPE C, " name of directory. (possibly truncated.)
NAME(75) TYPE C, " name of entry. (possibly truncated.)
END OF FILE_KEY.
DATA: BEGIN OF FILE_LIST OCCURS 100,
DIRNAME(75) TYPE C, " name of directory. (possibly truncated.)
NAME(75) TYPE C, " name of entry. (possibly truncated.)
TYPE(10) TYPE C, " type of entry.
LEN(4) TYPE P, " length in bytes.
OWNER(8) TYPE C, " owner of the entry.
MTIME(6) TYPE P, " last modification date, seconds since 1970
MODE(9) TYPE C, " like "rwx-r-x--x": protection mode.
USEABLE(1) TYPE C,
SUBRC(4) TYPE C,
ERRNO(3) TYPE C,
ERRMSG(40) TYPE C,
MOD_DATE TYPE D,
MOD_TIME(8) TYPE C, " hh:mm:ss
SEEN(1) TYPE C,
CHANGED(1) TYPE C,
END OF FILE_LIST.
DATA: TIMEZONE_SEC(5) TYPE P, " seconds local time is later than GMT
TIMEZONE_NAME(7) TYPE C.
***********************************************************************
* *
* Define a meaningful selection screen *
* *
***********************************************************************
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(60) TEXT-023. "Enter UNIX directory to start
SELECTION-SCREEN END OF LINE.
PARAMETERS: DIRX(70) TYPE C LOWER CASE OBLIGATORY
DEFAULT '/usr/sap'.
SELECTION-SCREEN SKIP 1.
FIELD-SYMBOLS: <STRING>.
*/******************************************************************/
*/* */
*/* SAP 's authority check / security is a joke. If */
*/* you are messing about with UNIX anyway you will have */
*/* access at at least ADM level. This is more than enough */
*/* to bypass any SAP security - what I would like is an */
*/* ACF2 / RACF like system for R3 */
*/* This is where the call to external security (if and when it */
*/* exists) should be made. To avoid by-passing external */
*/* security the ABAP should accept a security key (encrypted */
*/* and */
*/* */
*/******************************************************************/
*authority-check object 'S_TOOLS_EX_A' " SAP all will allow access
*id 'AUTH' field 'S_TOOLS_EX_A'.
*if sy-subrc <> 0.
* message s202 with 'Got you !!!!'.
*else.
SET PF-STATUS 'L000'.
* prepare time zone correction.
CALL 'C_GET_TIMEZONE' ID 'NAME' FIELD TIMEZONE_NAME
ID 'SEC' FIELD TIMEZONE_SEC.
TIMEZONE_SEC = 0 - SY-TZONE.
IF SY-DAYST = 'X'.
SUBTRACT 3600 FROM TIMEZONE_SEC.
ENDIF.
*/******************************************************************/
*/* */
*/* Get directories - This list is not exhaustive but */
*/* should suffice. */
*/* */
*/* Note also that certain directories may be restricted */
*/* for read access at the UNIX level. This program can only */
*/* access directories for which it has read access at least. */
*/* This is outside SAP's conntrol. */
*/* */
*/* */
*/******************************************************************/
SRT = 'N'.
SORT FILE_LIST BY NAME ASCENDING MTIME DESCENDING.
PERFORM SHOW_FILE_LIST.
* LEAVE TO LIST-PROCESSING. "R 3.0 avoid recursion Jim H
ENDFORM. "GET_DIRECTORY.
FORM USER_INPUT.
DATA CURPAGE LIKE SY-CPAGE.
CASE SY-PFKEY.
WHEN 'L100'.
CASE FCODE.
WHEN 'DIRL'.
PERFORM SHOW_DIR_LIST.
WHEN 'ATTR'.
IF H_LIST_INDEX > 0.
PERFORM SHOW_FILE_DETAILS.
ELSE.
MESSAGE S208. " Cursor befand sich au?erhalb der Liste
ENDIF.
WHEN 'DISP'.
IF H_LIST_INDEX > 0.
READ TABLE FILE_LIST INDEX H_LIST_INDEX.
IF FILE_LIST-DIRNAME <> GLOBALDIRECTORY.
PERFORM SHOW_FILE_CONTENTS.
IF FILE_LIST-TYPE(1) = 'D' OR FILE_LIST-TYPE(1) = 'd'.
CASE FILE_LIST-NAME.
WHEN '.'. "stay where ever you are
WHEN '..'. "go up
* JH CODE
STRLEN = STRLEN( SEARCHPOINTS-DIRNAME ).
IF STRLEN > 1. "never go higher than root
STRLEN = STRLEN - 1.
ASSIGN SEARCHPOINTS-DIRNAME+STRLEN(1) TO <STRING>.
WHILE <STRING> <> '/' AND STRLEN > 0.
STRLEN = STRLEN - 1.
ASSIGN SEARCHPOINTS-DIRNAME+STRLEN(1) TO <STRING>.
ENDWHILE.
IF STRLEN = 0. "never go higher than root
STRLEN = 1.
ENDIF.
WRITE SPACE TO SEARCHPOINTS-DIRNAME+STRLEN.
ENDIF.
*jh END
WHEN OTHERS. "go down
STRLEN = STRLEN( SEARCHPOINTS-DIRNAME ).
IF STRLEN > 1. "never go higher than root
IF SY-OPSYS <> 'VMS'.
WRITE '/' TO SEARCHPOINTS-DIRNAME+STRLEN.
STRLEN = STRLEN + 1.
ENDIF.
ENDIF.
WRITE FILE_LIST-NAME TO SEARCHPOINTS-DIRNAME+STRLEN.
ENDCASE.
PERFORM GET_DIRECTORY. "here we go again
ELSE.
MODIFY CURRENT LINE
FIELD VALUE FILE_LIST-SEEN FROM SAP_YES
FILE_LIST-CHANGED FROM SAP_NO.
* MOVE SAP_YES TO SY-LISEL+2(1).
* MOVE SAP_NO TO SY-LISEL+4(1).
* MODIFY LINE SY-CUROW OF CURRENT PAGE.
MOVE SAP_YES TO FILE_LIST-SEEN.
MOVE SAP_NO TO FILE_LIST-CHANGED.
MODIFY FILE_LIST INDEX H_LIST_INDEX.
ENDIF.
ENDIF.
ELSE.
MESSAGE S208. " Cursor befand sich au?erhalb der Liste
ENDIF.
* -> L100 + UPDA
WHEN 'UPDA'.
PERFORM UPDATE_FILE_LIST.
CURPAGE = SY-CPAGE.
PERFORM SHOW_FILE_LIST.
SCROLL LIST INDEX SY-LSIND TO PAGE CURPAGE.
WHEN 'NAME'.
SRT = 'N'.
SORT FILE_LIST BY NAME ASCENDING MTIME DESCENDING.
PERFORM SHOW_FILE_LIST.
WHEN 'TIME'.
SRT = 'T'.
SORT FILE_LIST BY MTIME DESCENDING NAME ASCENDING.
PERFORM SHOW_FILE_LIST.
ENDCASE.
CLEAR H_LIST_INDEX.
WHEN 'L200'.
CASE FCODE.
WHEN 'ATTR'.
PERFORM SHOW_FILE_DETAILS.
* -> L200 + DIRL
WHEN 'DIRL'.
PERFORM SHOW_DIR_LIST.
ENDCASE.
ENDCASE.
ENDFORM.
FORM FILL_FILE_LIST USING A_DIR_NAME A_GENERIC_NAME A_MUST_CS.
DATA: ERRCNT(2) TYPE P VALUE 0.
CALL 'C_DIR_READ_FINISH' " just to be sure
ID 'ERRNO' FIELD FILE_LIST-ERRNO
ID 'ERRMSG' FIELD FILE_LIST-ERRMSG.
CALL 'C_DIR_READ_START' ID 'DIR' FIELD A_DIR_NAME
ID 'FILE' FIELD A_GENERIC_NAME
ID 'ERRNO' FIELD FILE-ERRNO
ID 'ERRMSG' FIELD FILE-ERRMSG.
IF SY-SUBRC <> 0.
MESSAGE I204 WITH SY-SUBRC 'C_DIR_READ_START' "$ <- CALL $($,$,..)
' ' A_DIR_NAME.
MESSAGE I204 WITH SY-SUBRC 'C_DIR_READ_START...' "$ <- CALL $($,$,..
FILE-ERRNO FILE-ERRMSG.
ENDIF.
DO.
CLEAR FILE.
CALL 'C_DIR_READ_NEXT'
ID 'TYPE' FIELD FILE-TYPE
ID 'NAME' FIELD FILE-NAME
ID 'LEN' FIELD FILE-LEN
ID 'OWNER' FIELD FILE-OWNER
ID 'MTIME' FIELD FILE-MTIME
ID 'MODE' FIELD FILE-MODE
ID 'ERRNO' FIELD FILE-ERRNO
ID 'ERRMSG' FIELD FILE-ERRMSG.
FILE-DIRNAME = A_DIR_NAME.
MOVE SY-SUBRC TO FILE-SUBRC.
CASE SY-SUBRC.
WHEN 0.
CLEAR: FILE-ERRNO, FILE-ERRMSG.
CASE FILE-TYPE(1).
WHEN 'F'. " normal file.
PERFORM FILENAME_USEABLE USING FILE-NAME FILE-USEABLE.
WHEN 'f'. " normal file.
PERFORM FILENAME_USEABLE USING FILE-NAME FILE-USEABLE.
WHEN OTHERS. " directory, device, fifo, socket,...
MOVE SAP_NO TO FILE-USEABLE.
ENDCASE.
IF FILE-LEN = 0.
MOVE SAP_NO TO FILE-USEABLE.
ENDIF.
WHEN 1.
EXIT.
WHEN OTHERS. " SY-SUBRC >= 2
ADD 1 TO ERRCNT.
IF ERRCNT > 10.
EXIT.
ENDIF.
IF SY-SUBRC = 5.
MOVE: '???' TO FILE-TYPE,
'???' TO FILE-OWNER,
'???' TO FILE-MODE.
ELSE.
ENDIF.
MOVE SAP_NO TO FILE-USEABLE.
ENDCASE.
PERFORM P6_TO_DATE_TIME(RSTR0400) USING FILE-MTIME
TIMEZONE_SEC
FILE-MOD_TIME
FILE-MOD_DATE.
* * Does the filename contains the requested pattern?
* * Then store it, else forget it.
IF A_MUST_CS = NO_CS.
MOVE-CORRESPONDING FILE TO FILE_LIST.
APPEND FILE_LIST.
ELSE.
IF FILE-NAME CS A_MUST_CS.
MOVE-CORRESPONDING FILE TO FILE_LIST.
APPEND FILE_LIST.
ENDIF.
ENDIF.
ENDDO.
CALL 'C_DIR_READ_FINISH'
ID 'ERRNO' FIELD FILE_LIST-ERRNO
ID 'ERRMSG' FIELD FILE_LIST-ERRMSG.
IF SY-SUBRC <> 0.
WRITE: / 'C_DIR_READ_FINISH', 'SUBRC', SY-SUBRC.
ENDIF.
IF SRT = 'T'.
SORT FILE_LIST BY MTIME DESCENDING NAME ASCENDING.
ELSE.
SORT FILE_LIST BY NAME ASCENDING MTIME DESCENDING.
ENDIF.
ENDFORM.
FORM UPDATE_FILE_LIST.
DATA: DISAPPEARED(2) TYPE P.
CLEAR DISAPPEARED.
LOOP AT FILE_LIST.
CALL 'C_DIR_READ_START' ID 'DIR' FIELD FILE_LIST-DIRNAME
ID 'FILE' FIELD FILE_LIST-NAME
ID 'ERRNO' FIELD FILE-ERRNO
ID 'ERRMSG' FIELD FILE-ERRMSG.
IF SY-SUBRC <> 0.
MESSAGE I204 WITH SY-SUBRC 'C_DIR_READ_START' "$ <- CALL $($,$,..)
' ' FILE_LIST-NAME.
MESSAGE I204 WITH SY-SUBRC 'C_DIR_READ_START...' "$ <- CALL $($,$,
FILE-ERRNO FILE-ERRMSG.
ENDIF.
CLEAR FILE.
CALL 'C_DIR_READ_NEXT'.
MOVE SY-SUBRC TO FILE-SUBRC.
IF SY-SUBRC <> 0.
IF SY-SUBRC = 1. " File is not in directory
DELETE FILE_LIST.
ADD 1 TO DISAPPEARED.
ELSE.
IF SY-SUBRC <> FILE_LIST-SUBRC.
MESSAGE I204 WITH SY-SUBRC 'C_DIR_READ_NEXT' ' ' "$ <- CALL $(
FILE_LIST-NAME.
"ELSE same error again.
ENDIF.
ENDIF.
ENDIF.
CALL 'C_DIR_READ_NEXT' .
IF SY-SUBRC <> 1. " Should be: no more files...
MESSAGE I204 WITH SY-SUBRC 'C_DIR_READ_NEXT' "$ <- CALL $($,$,..)
FILE_LIST-NAME '2nd_read'.
ENDIF.
CALL 'C_DIR_READ_FINISH'
ID 'ERRNO' FIELD FILE-ERRNO
ID 'ERRMSG' FIELD FILE-ERRMSG.
IF SY-SUBRC <> 0.
MESSAGE I204 WITH SY-SUBRC 'C_DIR_READ_FINISH' "$ <- CALL $($,$,..
FILE-ERRNO FILE-ERRMSG.
ENDIF.
ENDLOOP.
IF DISAPPEARED > 0.
MESSAGE I207 WITH DISAPPEARED. "$ data files have disappeared
ENDIF.
LOOP AT SEARCHPOINTS.
PERFORM SECOND_LOOP USING SEARCHPOINTS-DIRNAME
SEARCHPOINTS-SP_NAME
SEARCHPOINTS-SP_CS
.
ENDLOOP.
IF SRT = 'T'.
SORT FILE_LIST BY MTIME DESCENDING NAME ASCENDING.
ELSE.
SORT FILE_LIST BY NAME ASCENDING MTIME DESCENDING.
ENDIF.
ENDFORM.
*EJECT
FORM SECOND_LOOP USING A_DIR_NAME A_GENERIC_NAME A_MUST_CS.
DATA: ERRCNT(2) TYPE P.
CLEAR ERRCNT.
CALL 'C_DIR_READ_START' ID 'DIR' FIELD A_DIR_NAME
ID 'FILE' FIELD A_GENERIC_NAME
ID 'ERRNO' FIELD FILE-ERRNO
ID 'ERRMSG' FIELD FILE-ERRMSG.
IF SY-SUBRC <> 0.
MESSAGE I204 WITH SY-SUBRC 'C_DIR_READ_START' "$ <- CALL $($,$,..)
' ' A_DIR_NAME.
MESSAGE I204 WITH SY-SUBRC 'C_DIR_READ_START...' "$ <- CALL $($,$,..
FILE-ERRNO FILE-ERRMSG.
ENDIF.
DO.
CLEAR FILE.
CALL 'C_DIR_READ_NEXT'
ID 'TYPE' FIELD FILE-TYPE
ID 'NAME' FIELD FILE-NAME
ID 'LEN' FIELD FILE-LEN
ID 'OWNER' FIELD FILE-OWNER
ID 'MTIME' FIELD FILE-MTIME
ID 'MODE' FIELD FILE-MODE
ID 'ERRNO' FIELD FILE-ERRNO
ID 'ERRMSG' FIELD FILE-ERRMSG.
FILE-DIRNAME = A_DIR_NAME.
MOVE SY-SUBRC TO FILE-SUBRC.
IF FILE-SUBRC = 0.
CLEAR: FILE-ERRNO, FILE-ERRMSG.
ELSEIF FILE-SUBRC = 1.
EXIT.
ENDIF.
CLEAR FILE_LIST.
MOVE-CORRESPONDING file TO FILE_KEY.
READ TABLE FILE_LIST WITH KEY FILE_KEY.
IF SY-SUBRC = 0. " File was already in FILE_LIST.
IF FILE_LIST-TYPE <> FILE-TYPE OR
FILE_LIST-LEN <> FILE-LEN OR
FILE_LIST-OWNER <> FILE-OWNER OR
FILE_LIST-MTIME <> FILE-MTIME OR
FILE_LIST-MODE <> FILE-MODE OR
FILE_LIST-ERRNO <> FILE-ERRNO.
PERFORM P6_TO_DATE_TIME(RSTR0400) USING FILE-MTIME
TIMEZONE_SEC
FILE-MOD_TIME
FILE-MOD_DATE.
MOVE FILE_LIST-USEABLE TO FILE-USEABLE.
MOVE FILE_LIST-SEEN TO FILE-SEEN.
MOVE-CORRESPONDING FILE TO FILE_LIST.
MOVE SAP_YES TO FILE_LIST-CHANGED.
MODIFY FILE_LIST INDEX SY-TABIX.
ENDIF.
ELSE. " File ist not yet in FILE_LIST.
IF FILE-SUBRC <> 0.
ADD 1 TO ERRCNT.
IF ERRCNT > 10.
EXIT.
ENDIF.
IF FILE-SUBRC = 5.
MOVE: '???' TO FILE-TYPE,
'???' TO FILE-OWNER,
'???' TO FILE-MODE.
ELSE.
MESSAGE I204 WITH FILE-SUBRC 'C_DIR_READ_NEXT' "$ <- CALL $($,
' ' FILE-NAME.
ENDIF.
MOVE SAP_NO TO FILE-USEABLE.
ELSE.
PERFORM FILENAME_USEABLE USING FILE-NAME FILE-USEABLE.
ENDIF.
IF FILE-LEN = 0.
MOVE SAP_NO TO FILE-USEABLE.
ENDIF.
PERFORM P6_TO_DATE_TIME(RSTR0400) USING FILE-MTIME TIMEZONE_SEC
FILE-MOD_TIME
FILE-MOD_DATE.
* * Does the filename contains the requested pattern?
* * Then store it, else forget it.
IF A_MUST_CS = NO_CS.
MOVE-CORRESPONDING FILE TO FILE_LIST.
APPEND FILE_LIST.
ELSE.
IF FILE-NAME CS A_MUST_CS.
MOVE-CORRESPONDING FILE TO FILE_LIST.
APPEND FILE_LIST.
ENDIF.
ENDIF.
ENDIF.
ENDDO.
CALL 'C_DIR_READ_FINISH'
ID 'ERRNO' FIELD FILE-ERRNO
ID 'ERRMSG' FIELD FILE-ERRMSG.
IF SY-SUBRC <> 0.
WRITE: / 'C_DIR_READ_FINISH', 'SUBRC', SY-SUBRC.
ENDIF.
--------------------------------------------------------------------------------
Text elements
I 001 Name...........
I 002 Type...........
I 003 Length.........
I 004 Creator........
I 005 Last change....
I 006 Mode...........
I 007 Usable.........
I 008 Error number...
I 009 Error message..
I 010 Usable
I 011 Viewed
I 012 Changed
I 013 Name
I 014 Length
I 015 Creator
I 016 Last change
I 017 Name:
I 018 Unable to display this file
I 019 Directory......
I 020 Beg.of name
I 021 Model
I 022 Directory
I 023 Enter UNIX directory to start search from - Case sensitive.
R XTREE for UNIX
S DIRX Unix directory Case sensitive)
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.