‎2008 Jan 04 9:04 AM
Hi,
i'm looking for a function module or class method for getting all files (or with a filter) from a directory on the application server. I have found the function EPS_GET_DIRECTORY_LISTING and RZL_READ_DIR_LOCAL, but both are not working for files with names longer than 32. And my filenames are at least 50 characters long.
Anyone ?
regards,
Hans
‎2008 Jan 04 9:29 AM
Hans,
try sth like this:
FUNCTION Y_GET_DIRECTORY_LISTING_HP_UX.
*"----
-
""Lokale Schnittstelle:
*" IMPORTING
*" VALUE(DIR) LIKE RLGRAP-FILENAME OPTIONAL
*" VALUE(FILE_MASK) LIKE RLGRAP-FILENAME DEFAULT SPACE
*" EXPORTING
*" VALUE(DIR_NAME) LIKE RLGRAP-FILENAME
*" VALUE(FILE_COUNTER) LIKE EPSF-EPSFILSIZ
*" VALUE(COMMAND) LIKE RLGRAP-FILENAME
*" TABLES
*" DIR_LIST
*" EXCEPTIONS
*" DIR_NOT_EXIST
*" NO_AUTHORIZATION
*" READ_DIRECTORY_FAILED
*" EMPTY_DIRECTORY_LIST
*" FALSE_OS
*"----
-
DATA: NAME like rlgrap-filename.
data: lv_mgr_user type as4user.
DATA: BEGIN OF TABL OCCURS 0, "Table for system-call
LINE type string,
END OF TABL.
authority check
call function 'TMS_CI_GET_USER_INFO'
IMPORTING
ev_mgr_user = lv_mgr_user.
call function 'TR_AUTHORITY_CHECK_ADMIN'
EXPORTING
iv_user = lv_mgr_user
iv_adminfunction = 'EPS1'
EXCEPTIONS
others = 1.
IF SY-SUBRC <> 0.
RAISE NO_AUTHORIZATION.
ENDIF.
*nur für HP-UX und AIX
if sy-OPSYS <> 'HP-UX'.
raise false_os.
endif.
dir_name = dir.
concatenate dir_name file_mask into name separated by '/'.
concatenate 'ls' name into command separated by space.
CALL 'SYSTEM' ID 'COMMAND' FIELD COMMAND
ID 'TAB' FIELD TABL-SYS.
dir_list[] = tabl[].
describe table dir_list lines file_counter.
IF FILE_COUNTER > 0.
SORT DIR_LIST.
ELSE.
RAISE EMPTY_DIRECTORY_LIST.
ENDIF.
ENDFUNCTION.
greetings Andreas
‎2008 Jan 04 9:35 AM
Hi Andreas,
thanks for your reply. It seems that are no standard SAP functions to do this job ?
I believe that we don't have a HPUX system but Linux. Is it still working ?
But i'm going to try it
regards,
Hans
‎2008 Jan 04 9:56 AM
The system command doesn't return a proper result.
I'm going to try to rewrite the function RZL_READ_DIR_LOCAL for filename with lenght 128 or so.
Hans
‎2008 Jan 04 10:02 AM
...or try without these line:
raise false_os.
A.
Edited by: Andreas Mann on Jan 4, 2008 11:04 AM
‎2008 Jan 04 10:29 AM
‎2008 Jan 04 11:10 AM
Hai,
You can use function module TMP_GUI_DIRECTORY_LIST_FILES
Sample Code:
data:
DIR_NAME LIKE RLGRAP-FILENAME,
FILE_MASK TYPE C DEFAULT SPACE,
file_table TYPE sdokpath OCCURS 0 WITH HEADER LINE,
dir_table TYPE sdokpath OCCURS 0 WITH HEADER LINE,
fullpath TYPE sdokpath.
REFRESH file_paths.
CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES'
EXPORTING
directory = dir_name
filter = file_mask
IMPORTING
FILE_COUNT =
DIR_COUNT =
TABLES
file_table = file_table
dir_table = dir_table
EXCEPTIONS
cntl_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
*No_file_exists
ENDIF.
IF ( NOT dir_name CP '*\' ).
CONCATENATE dir_name '\' INTO dir_name.
ENDIF.
LOOP AT file_table.
CONCATENATE dir_name file_table-pathname INTO fullpath.
APPEND fullpath TO file_paths.
ENDLOOP.
LOOP AT dir_table.
CONCATENATE dir_name dir_table-pathname INTO fullpath.
APPEND fullpath TO file_paths.
ENDLOOP.
___________________________________________________________________________________
Or
You can use function module 'RZL_READ_DIR_LOCAL'.
Sample code:
data: begin of itab occurs 0,
rec(1000) type c,
end of itab.
data: wa(1000) type c.
data: p_file type localfile.
data: ifile type table of salfldir with header line.
parameters: p_path type salfile-longname
default '/usr/sap/TST/DVEBMGS01/data/'.
call function 'RZL_READ_DIR_LOCAL'
exporting
name = p_path
tables
file_tbl = ifile
exceptions
argument_error = 1
not_found = 2
others = 3.
loop at ifile.
format hotspot on.
write:/ ifile-name.
hide ifile-name.
format hotspot off.
endloop.
at line-selection.
concatenate p_path ifile-name into p_file.
clear itab. refresh itab.
open dataset p_file for input in text mode.
if sy-subrc = 0.
do.
read dataset p_file into wa.
if sy-subrc 0.
exit.
endif.
itab-rec = wa.
append itab.
enddo.
endif.
close dataset p_file.
loop at itab.
write:/ itab.
endloop.
Note: for unicode (ECC 6.0), we have to add "ENCODING DEFAULT" with "open dataset ".
‎2008 Jan 04 11:19 AM