Reputation: 250
So I tried EPS2_GET_DIRECTORY_LISTING and EPS_GET_DIRECTORY_LISTING. But the issue is, that inside the function, there is a check to verify whether the user has the necessary permssions for transports. The check performed is Function 'TR_AUTHORITY_CHECK_DISPLAY'.
I have no idea what it has to do with file permissions...
I started digging. Turns out in note https://me.sap.com/notes/0003221036 it's written, that the Function should not be used anymore since it lost support. But they don't specify a replacement.
Have you any suggestions what I might use here? I call the function with a path and file_mask, so the replacement needs to have such possibility also.
Either that, or someone can explain me that I need the Transport rights to use the function.
Upvotes: 0
Views: 112
Reputation: 13628
Of course, the easiest solution is to duplicate the function module and adapt the code as you wish.
Otherwise, if you don't want to depend on unofficial solutions, the only way I know to work with the server file system is to use the transaction code SM49
and the function module SXPG_COMMAND_EXECUTE
, which are meant to run direct commands on the server.
For instance, you may create a "server command" in SM49
(e.g. ZGET_DIRECTORY
) and configure it with ls
for UNIX-like systems, cmd /c dir
for Windows, etc.
You may invoke the command ZGET_DIRECTORY
by calling SXPG_COMMAND_EXECUTE
and convert the result in something close to EPS2_GET_DIRECTORY_LISTING
in order to reduce the number of adaptations of your custom programs using EPS2_GET_DIRECTORY_LISTING
.
Example for SM49
and ABAP code:
DATA exec_protocol TYPE TABLE OF btcxpm.
DATA status TYPE extcmdexex-status.
DATA exitcode TYPE extcmdexex-exitcode.
DATA(directory) = CONV sxpgcolist-parameters( '/tmp' ).
DATA(host) = CONV rfcdisplay-rfchost( sy-host ).
CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
EXPORTING commandname = 'ZGET_DIRECTORY'
additional_parameters = directory
operatingsystem = sy-opsys
targetsystem = host
IMPORTING status = status
exitcode = exitcode
TABLES exec_protocol = exec_protocol
EXCEPTIONS no_permission = 1
command_not_found = 2
parameters_too_long = 3
security_risk = 4
wrong_check_call_interface = 5
program_start_error = 6
program_termination_error = 7
x_error = 8
parameter_expected = 9
too_many_parameters = 10
illegal_command = 11
wrong_asynchronous_parameters = 12
cant_enq_tbtco_entry = 13
jobcount_generation_error = 14
OTHERS = 15.
IF sy-subrc <> 0 OR status = 'E'.
" handle the error
ELSE.
CASE sy-opsys.
WHEN 'UNIX' OR 'Linux'.
" Convert the output of "ls -la" into EPS2FILI format
" https://man7.org/linux/man-pages/man1/ls.1.html
TYPES output_eps2_get_directory_list TYPE STANDARD TABLE OF eps2fili WITH EMPTY KEY.
" -rw-rw---- 1 l4xadm sapsys 317674 2024-11-04 15:24:30.297148558 +0000 ABAON-BA
" https://unix.stackexchange.com/questions/103114/what-do-the-fields-in-ls-al-output-mean
TYPES:
BEGIN OF ls_output_fields,
file_type_mode TYPE c LENGTH 10, " type of entry - (file), d (directory), s (system), etc. + rwxrwxrwx
count_hard_links TYPE c LENGTH 4,
owner_name TYPE c LENGTH 8,
owner_group TYPE c LENGTH 8,
size_bytes TYPE string,
last_modif_date_iso TYPE string,
file_name TYPE c LENGTH 200, " possibly truncated
END OF ls_output_fields.
TYPES formatted_ls_output TYPE STANDARD TABLE OF ls_output_fields WITH EMPTY KEY.
" Delete the "total" line
DELETE exec_protocol INDEX 1.
DATA(output_eps2_get_directory_list) = VALUE output_eps2_get_directory_list( ).
LOOP AT exec_protocol REFERENCE INTO DATA(exec_output_line).
DATA(ls_output_fields) = VALUE ls_output_fields( ).
FIND REGEX '^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+\s+\S+\s+\S+)\s+(.*)$' ##REGEX_POSIX
IN exec_output_line->message
SUBMATCHES
ls_output_fields-file_type_mode
ls_output_fields-count_hard_links
ls_output_fields-owner_name
ls_output_fields-owner_group
ls_output_fields-size_bytes
ls_output_fields-last_modif_date_iso
ls_output_fields-file_name.
IF '-' = substring( val = ls_output_fields-file_type_mode
len = 1 ).
INSERT VALUE eps2fili( name = ls_output_fields-file_name
size = ls_output_fields-size_bytes
mtim = CONV #( ls_output_fields-last_modif_date_iso )
owner = ls_output_fields-owner_name )
INTO TABLE output_eps2_get_directory_list.
ENDIF.
ENDLOOP.
ENDCASE.
SORT output_eps2_get_directory_list BY name.
ENDIF.
NB: SM69
is an alias of SM49
.
Upvotes: 1