How to get programatically the file path from a di

2019-07-10 09:55发布

问题:

The transaction AL11 returns a mapping of "directory parameters" to file paths on the application server AFAIK. The trouble with transaction AL11 is that its program only calls c modules, there's almost no trace of select statements or function calls to analize there.

I want the ability to do this dynamically, in my code, like for instance a function module that took "DATA_DIR" as input and "E:\usr\sap\IDS\DVEBMGS00\data" as output.

This thread is about a similar topic, but it doesn't help.

Some other guy has the same problem, and he explains it quite well here.

回答1:

I strongly suspect that the only way to get these values is through the kernel directly. some of them can vary depending on the application server, so you probably won't be able to find them in the database. You could try this:

TYPE-POOLS abap.

TYPES: BEGIN OF t_directory,
         log_name TYPE dirprofilenames,
         phys_path TYPE dirname_al11,
       END OF t_directory.

DATA: lt_int_list    TYPE TABLE OF abaplist,
      lt_string_list TYPE list_string_table,
      lt_directories TYPE TABLE OF t_directory,
      ls_directory   TYPE t_directory.

FIELD-SYMBOLS: <l_line> TYPE string.

START-OF-SELECTION-OR-FORM-OR-METHOD-OR-WHATEVER.
* get the output of the program as string table
  SUBMIT rswatch0 EXPORTING LIST TO MEMORY AND RETURN.
  CALL FUNCTION 'LIST_FROM_MEMORY'
    TABLES
      listobject = lt_int_list.
  CALL FUNCTION 'LIST_TO_ASCI'
    EXPORTING
      with_line_break   = abap_true
    IMPORTING
      list_string_ascii = lt_string_list
    TABLES
      listobject        = lt_int_list.

* remove the separators and the two header lines
  DELETE lt_string_list WHERE table_line CO '-'.
  DELETE lt_string_list INDEX 1.
  DELETE lt_string_list INDEX 1.

* parse the individual lines
  LOOP AT lt_string_list ASSIGNING <l_line>.
*   If you're on a newer system, you can do this in a more elegant way using regular expressions
    CONDENSE <l_line>.
    SHIFT <l_line> LEFT DELETING LEADING '|'.
    SHIFT <l_line> RIGHT DELETING TRAILING '|'.
    SPLIT <l_line>+1 AT '|' INTO ls_directory-log_name ls_directory-phys_path.
    APPEND ls_directory TO lt_directories.
  ENDLOOP.


回答2:

Try the following

data : dirname type  DIRNAME_AL11.
CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_DATA'
                   ID 'VALUE' FIELD dirname.

Alternatively if you wanted to use your own parameters(AL11->configure) then read these out of table user_dir.