SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Открытие заданной директории



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP
View previous topic :: View next topic  
Author Message
Рустам
Специалист
Специалист



Joined: 26 Dec 2007
Posts: 73

PostPosted: Tue Apr 08, 2008 10:30 am    Post subject: Открытие заданной директории Reply with quote

Такое задание, на селекционном экране поле для ввода пути к файлу. Если пользователь ввел начальный путь или он задан из варианта, нужно, чтобы по нажатию F4 открылось заданная директория с заданным фильтром.
PARAMETERS: p_file LIKE rlgrap-filename DEFAULT 'c:\work\*.xls'.

Сейчас же открывается корень диска C: и доступны все файлы для выбора.
Back to top
View user's profile Send private message
vga
Мастер
Мастер


Age: 170
Joined: 04 Oct 2007
Posts: 1218
Location: Санкт-Петербург

PostPosted: Tue Apr 08, 2008 7:18 pm    Post subject: Reply with quote

Code:
DATA: rc            TYPE I,
      user_action   TYPE I,
      filetable     TYPE FILETABLE,
      wa_filetable  TYPE LINE OF FILETABLE,
      result        TYPE C,
      s_path        TYPE STRING,
      l_drive       TYPE PCFILE-DRIVE,
      l_path        TYPE PCFILE-PATH,
      s_filter      TYPE STRING.

PARAMETERS: p_path TYPE PCFILE-PATH LOWER CASE.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
  CLEAR: rc.
  REFRESH: filetable.
  DATA: progname TYPE sy-repid,
        dynnum   TYPE sy-dynnr.
  DATA: dynpfields LIKE dynpread OCCURS 1 WITH HEADER LINE.

  progname = sy-cprog.
  dynnum   = sy-dynnr.

*-------------------------------

  REFRESH dynpfields.
  CLEAR: dynpfields.

  dynpfields-fieldname = 'P_PATH'.
  APPEND dynpfields.

  CALL FUNCTION 'DYNP_VALUES_READ'
    EXPORTING
      dyname               = progname
      dynumb               = dynnum
    TABLES
      dynpfields           = dynpfields
    EXCEPTIONS
      invalid_abapworkarea = 01
      invalid_dynprofield  = 02
      invalid_dynproname   = 03
      invalid_dynpronummer = 04
      invalid_request      = 05
      no_fielddescription  = 06
      undefind_error       = 07.

  IF NOT dynpfields[] IS INITIAL.
    READ TABLE dynpfields INDEX 1.
  ENDIF.

  l_path = dynpfields-fieldvalue.

  CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
       EXPORTING
         COMPLETE_FILENAME = l_path
       IMPORTING
         DRIVE             = l_drive
         EXTENSION         = s_filter
         PATH              = l_path
       EXCEPTIONS
         INVALID_DRIVE     = 1
         INVALID_EXTENSION = 2
         INVALID_NAME      = 3
         INVALID_PATH      = 4
       .
  IF NOT s_filter IS INITIAL.
    CONCATENATE '*.' s_filter INTO s_filter.
  ENDIF.
  CONCATENATE l_drive ':' l_path INTO s_path.
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title            = 'Gui upload'
      with_encoding           = 'X'
      initial_directory       = s_path
      file_filter             = s_filter
      default_filename        = s_filter
      default_extension       = 'Excel files http://*.XLS'
    CHANGING
      file_table              = filetable
      rc                      = rc
      user_action             = user_action
    EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      OTHERS                  = 5.
  IF sy-subrc NE 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

  ELSEIF user_action EQ 0.
    READ TABLE filetable INTO wa_filetable INDEX 1.
    s_path = wa_filetable-filename.
    CALL METHOD cl_gui_frontend_services=>file_exist
      EXPORTING
        file                 = s_path
      RECEIVING
        result               = result
      EXCEPTIONS
        cntl_error           = 1
        error_no_gui         = 2
        wrong_parameter      = 3
        not_supported_by_gui = 4
        OTHERS               = 5.
    IF sy-subrc NE 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ELSEIF result EQ 'X'.
      p_path = s_path.
    ELSE.
      MESSAGE 'file does not exist' TYPE 'E'.
    ENDIF.

  ENDIF.
  IF user_action NE CL_GUI_FRONTEND_SERVICES=>action_ok.
    CLEAR: p_path. "if user action is cancelled or something else
    EXIT.
  ENDIF.
Back to top
View user's profile Send private message Blog Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.