来自Application Server Directory ABAP的自定义搜索帮助

时间:2018-12-30 07:43:54

标签: sap abap

我需要为要从应用程序服务器目录中检索到的用户和数据的提供者客户搜索帮助。

以下是目录和文件类型的详细信息。

  • 应用程序服务器目录:/ usr / sap / tmp /
  • 文件扩展名.txt 应该仅在搜索帮助中可用。

自定义搜索帮助应显示目录名称和扩展名为.txt的文件。
用户应该不能从任何其他目录中选择文件。

搜索帮助输出示例:

Directory Name    File Name
--------------    --------------
/usr/sap/tmp/     file_name1.txt
/usr/sap/tmp/     file_name2.txt
/usr/sap/tmp/     file_name3.txt

以下链接很有帮助,但我的要求没有得到满足。

https://archive.sap.com/discussions/thread/285999

  • F4_FILENAME
  • cl_gui_frontend_services =>目录浏览
  • / SAPDMC / LSM_F4_SERVER_FILE

https://archive.sap.com/discussions/thread/715635

  • F4_DXFILENAME_TOPRECURSION

有没有哪个人有更好的解决方案?

致谢

乌马尔·阿卜杜拉

2 个答案:

答案 0 :(得分:1)

功能模块/SAPDMC/LSM_F4_SERVER_FILE不能满足您的要求吗?

编辑:
为了使用户无法从其他目录中选择任何内容,可以在函数调用周围编写包装,以确保选择了正确的目录。
可能不是理想的解决方案,但不需要任何开发工作。

CONSTANTS:
lco_directory TYPE char30 VALUE '/usr/sap/tmp/',
lco_filemask  TYPE char5  VALUE '*'.

DATA:
lv_filename TYPE rlgrap-filename,
lv_path     TYPE string.

WHILE 1 NE 2.
  CLEAR: lv_filename, lv_path.
  CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
    EXPORTING
      directory        = lco_directory
      filemask         = lco_filemask
    IMPORTING
      serverfile       = lv_filename
    EXCEPTIONS
      canceled_by_user = 1
      OTHERS           = 2.
  IF sy-subrc = 0 AND sy-ucomm NE 'CANC' AND lv_filename IS NOT INITIAL.
    CALL FUNCTION 'TRINT_SPLIT_FILE_AND_PATH'
      EXPORTING
        full_name = lv_filename
     IMPORTING
       file_path  = lv_path
     EXCEPTIONS
       x_error    = 1
       OTHERS     = 2 .
    IF sy-subrc = 0 AND lv_path NE lco_directory.
*     Wrong directory was chosen
      MESSAGE 'Invalid directory' TYPE 'S' DISPLAY LIKE 'W'.
    ELSE.
*     Directory is ok
      EXIT.
    ENDIF.
  ELSE.
*   Action cancelled
    CLEAR: lv_filename, lv_path.
    EXIT.
  ENDIF.
ENDWHILE.

答案 1 :(得分:1)

我已经为需求创建了自定义逻辑。我想分享。

REPORT YUA_LIST_DIRECTORY.



CLASS ff_intf DEFINITION.
  PUBLIC SECTION.

    METHODS: listdirectory IMPORTING iv_dir TYPE c
                           EXPORTING ev_ldir TYPE c ev_file TYPE c ,
             get_file_list IMPORTING iv_ldir TYPE c  iv_today TYPE c.

      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.


    DATA:    BEGIN OF gs_file,

                directory(500) TYPE c, " name of directory.
                name(75) TYPE c, " name of entry." (possibly truncated.)
                type(10) TYPE c, " type of entry: directory, file
                len(16) 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
                errno(3) TYPE c,
                errmsg(40) TYPE c,
                mod_date TYPE d,
                mod_time(8) TYPE c, " hh:mm:ss
                subrc LIKE sy-subrc,

              END OF gs_file.

    DATA:
          ls_file LIKE gs_file,
          pt_file LIKE TABLE OF gs_file.



    CLASS-METHODS: p6_to_date_time_tz IMPORTING iv_time TYPE p EXPORTING ev_time TYPE c ev_date TYPE d.

ENDCLASS.                    "ff_intf DEFINITION




*----------------------------------------------------------------------*
*       CLASS ff_intf IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS ff_intf IMPLEMENTATION.

  METHOD listdirectory.
    FIELD-SYMBOLS: <l_line> TYPE string.

    CONCATENATE 'FF' sy-datum '.txt' INTO ev_file. " file name

    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   = 'X' "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.

    READ TABLE lt_directories INTO ls_directory WITH KEY log_name = iv_dir .
    IF sy-subrc EQ 0.
      ev_ldir = ls_directory-phys_path.
    ENDIF.

  ENDMETHOD.                    "listdirectory

  METHOD get_file_list.

    DATA:
    l_counter TYPE i,
    l_counter_package TYPE i,
    l_char10(10),
    l_text(100),
    l_subrc LIKE sy-subrc,
    lv_cmptoday TYPE c LENGTH 11.
*-----------------------------------*
    DATA lv_compstr TYPE c LENGTH 5.

      lv_compstr = '*.TXT'.


    CONCATENATE '*' sy-datum+0(4)  sy-datum+4(2) sy-datum+6(2)   '*' INTO lv_cmptoday. " YYYYMMDD

    CALL 'C_DIR_READ_FINISH'
    ID 'ERRNO' FIELD ls_file-errno
    ID 'ERRMSG' FIELD ls_file-errmsg.

    CALL 'C_DIR_READ_START'
    ID 'DIR' FIELD iv_ldir " logical directory
    ID 'FILE' FIELD '*'
    ID 'ERRNO' FIELD ls_file-errno
    ID 'ERRMSG' FIELD ls_file-errmsg.

    IF sy-subrc <> 0.
      IF NOT ls_file-errmsg IS INITIAL.
        MESSAGE i034(/sapdmc/lsmw_obj_060) WITH ls_file-errmsg.
      ENDIF.
      EXIT.
    ENDIF.

    DO .

      CLEAR ls_file.
      CALL 'C_DIR_READ_NEXT'
      ID 'TYPE' FIELD ls_file-type
      ID 'NAME' FIELD ls_file-name
      ID 'LEN' FIELD ls_file-len
      ID 'OWNER' FIELD ls_file-owner
      ID 'MTIME' FIELD ls_file-mtime
      ID 'MODE' FIELD ls_file-mode
      ID 'ERRNO' FIELD ls_file-errno
      ID 'ERRMSG' FIELD ls_file-errmsg.
      l_subrc = sy-subrc.
      ls_file-subrc = sy-subrc.
      IF l_subrc = 1.
        EXIT.
      ELSEIF l_subrc = 5.
        ls_file-type = '???'.
        ls_file-owner = '???'.
        ls_file-mode = '???'.
      ENDIF.
      ls_file-directory = iv_ldir.
      ADD 1 TO l_counter.
      ADD 1 TO l_counter_package.
      IF l_counter_package = 100.
        l_text = '& Enteries Read'.
        l_char10 = l_counter.
        REPLACE '&' WITH l_char10 INTO l_text.
        CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
          EXPORTING
            text = l_text.
        l_counter_package = 0.
      ENDIF.

* Machine time into date/time of day convert

      IF iv_today EQ 'X'. " only files of current date
        CALL METHOD ff_intf=>p6_to_date_time_tz( EXPORTING iv_time = ls_file-mtime
                                IMPORTING ev_time = ls_file-mod_time ev_date = ls_file-mod_date ).

        IF ls_file-mod_date EQ sy-datum.
* Only the files, which fit the sample(mask)
          CASE ls_file-type(1).
            WHEN 'F' OR 'f'. " File
              IF ( ls_file-name CP lv_compstr ) AND ls_file-name+0(2) = 'FF' AND ls_file-name CP lv_cmptoday. " Only Text File to compare
                APPEND ls_file TO pt_file.
              ENDIF.
*      WHEN OTHERS.
*        APPEND ls_file TO pt_file.

          ENDCASE.
        ENDIF.

      ELSE.  " ALL files in directory
* Only the files, which fit the sample(mask)
        CASE ls_file-type(1).
          WHEN 'F' OR 'f'. " File
            IF ( ls_file-name CP lv_compstr ) AND ls_file-name+0(2) = 'FF'. " Only Text File to compare and PODEL & Today
              APPEND ls_file TO pt_file.
            ENDIF.
        ENDCASE.

      ENDIF.
    ENDDO.

    SORT pt_file BY type DESCENDING name DESCENDING.

    CALL 'C_DIR_READ_FINISH'
    ID 'ERRNO' FIELD ls_file-errno
    ID 'ERRMSG' FIELD ls_file-errmsg.

  ENDMETHOD.                    "get_file_list

  METHOD p6_to_date_time_tz.

    DATA: opcode TYPE x,
          unique, not_found,
          timestamp TYPE i,
          date TYPE d,
          time TYPE t,
          tz LIKE sy-zonlo,
          timestring(10),
          abapstamp(14),
          abaptstamp TYPE timestamp.

    timestamp =  iv_time.
    IF sy-zonlo = space.
* Der Benutzer hat keine Zeitzone gepflegt: nehme lokale des App. Srv.
      CALL FUNCTION 'TZON_GET_OS_TIMEZONE'
        IMPORTING
          ef_timezone   = tz
          ef_not_unique = unique
          ef_not_found  = not_found.
      IF unique = 'X' OR not_found = 'X'.          .
        tz = sy-tzone.
        CONCATENATE 'UTC+' tz INTO tz.
      ENDIF.
    ELSE.
      tz = sy-zonlo.
    ENDIF.
* wandle den Timestamp in ABAP Format um und lass den ABAP konvertieren
    opcode = 3.
    CALL 'RstrDateConv'
      ID 'OPCODE' FIELD opcode
      ID 'TIMESTAMP' FIELD timestamp
      ID 'ABAPSTAMP' FIELD abapstamp.
    abaptstamp = abapstamp.
    CONVERT TIME STAMP abaptstamp TIME ZONE tz INTO DATE date
      TIME time.
    IF sy-subrc <> 0.
      date = abapstamp(8).
      time = abapstamp+8.
    ENDIF.

    WRITE: time(2) TO timestring(2),
           ':' TO timestring+2(1),
           time+2(2) TO timestring+3(2),
           ':' TO timestring+5(1),
           time+4(2) TO timestring+6(2).
    MOVE timestring TO ev_time.
    MOVE date TO ev_date.

  ENDMETHOD.                    "P6_TO_DATE_TIME_TZ
ENDCLASS.



DATA lo_pi TYPE REF TO ff_intf.
DATA ls_pt LIKE LINE OF lo_pi->pt_file.
DATA v_csv TYPE c LENGTH 1 VALUE space.
DATA v_separator TYPE c LENGTH 2.

DATA: lt_file TYPE ztt_file,
      ls_file LIKE LINE OF lt_file,
      ls_ptfile LIKE LINE OF lo_pi->pt_file.



SELECTION-SCREEN: BEGIN OF BLOCK a WITH FRAME TITLE text-001.
PARAMETERS p_dir TYPE c LENGTH 50 DEFAULT '/usr/sap/tmp/'.
PARAMETERS: p_sfile LIKE rlgrap-filename.

SELECTION-SCREEN: END OF BLOCK a.

AT SELECTION-SCREEN OUTPUT.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_sfile.

  REFRESH lo_pi->pt_file.
  CALL METHOD lo_pi->get_file_list( EXPORTING iv_ldir = p_dir  iv_today = '' ). " Directory logical name.
  REFRESH lt_file.
  LOOP AT lo_pi->pt_file INTO ls_ptfile.
    MOVE ls_ptfile-directory TO ls_file-directory.
    MOVE ls_ptfile-name TO ls_file-fname.
    APPEND ls_file TO lt_file.
  ENDLOOP.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'FNAME'
      dynpprog        = sy-repid
      dynpnr          = sy-dynnr
      dynprofield     = 'so_tmpl-low'
      value_org       = 'S'
    TABLES
      value_tab       = lt_file
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.

   CASE sy-subrc.
     WHEN 1.
       MESSAGE 'Parameter Error' TYPE 'I' DISPLAY LIKE 'W'.
     WHEN 2.
       MESSAGE 'No values found' TYPE 'I' DISPLAY LIKE 'W'.
     WHEN 3.
       MESSAGE 'Error Processing help' TYPE 'I' DISPLAY LIKE 'W'.
   ENDCASE.




********************************* INITIALIZATION. ************************************

INITIALIZATION.

  CREATE OBJECT lo_pi.




********************************* START-OF-SELECTION ************************************

START-OF-SELECTION.



********************************* END-OF-SELECTION ************************************

END-OF-SELECTION.