Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Function/method for getting directory list

h_senden2
Active Contributor
0 Likes
1,543

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

7 REPLIES 7
Read only

andreas_mann3
Active Contributor
0 Likes
1,147

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

Read only

0 Likes
1,147

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

Read only

0 Likes
1,147

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

Read only

0 Likes
1,147

...or try without these line:

raise false_os.

A.

Edited by: Andreas Mann on Jan 4, 2008 11:04 AM

Read only

0 Likes
1,147

Andreas,

i had tried that already. Didn't work

Hans

Read only

Former Member
0 Likes
1,147

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 ".

Read only

h_senden2
Active Contributor
0 Likes
1,147

problem solved