Get file from local directory on value request


Sometimes we need to upload file a text file to be uploaded to SAP system. jadi saya copy sedikit potongan program yang dapat digunakan untuk mengambil file dari local directory pada saat F4 ditekan (on value request), yaitu cukup menggunakan satu function saja pada saat event At Selection-Screen on Value Request.

TABLES: rlgrap.
SELECT-OPTIONS: s_file FOR rlgrap-filename NO INTERVALS NO-EXTENSION.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_file-low.
  PERFORM f_help_for_file CHANGING s_file-low.

*&---------------------------------------------------------------------*
*&      Form  f_help_for_file
*&---------------------------------------------------------------------*
FORM f_help_for_file  CHANGING s_file-low.

  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
      static    = 'X'
    CHANGING
      file_name = s_file-low.

ENDFORM.                    " F_HELP_FOR_FILE
Advertisements

2 comments

  1. Why don’t you use CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG or CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG instead?

  2. Hi Dominik Tylczyński,

    Thank you for sharing. and yes, you can use those method.
    Here is some simple code using this method :

    REPORT  ydoktestc.
    
    *&---------------------------------------------------------------------*
    *&      Data Declaration
    *&---------------------------------------------------------------------*
    DATA: t_tabname TYPE filetable,
          d_rc TYPE i.
    *&---------------------------------------------------------------------*
    *&      Selection screen
    *&---------------------------------------------------------------------*
    PARAMETERS p_file LIKE rlgrap-filename DEFAULT 'D:\' OBLIGATORY.
    
    *&---------------------------------------------------------------------*
    *&      Events
    *&---------------------------------------------------------------------*
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      CALL METHOD cl_gui_frontend_services=>file_open_dialog
        EXPORTING
          window_title            = 'Select File'
          default_filename        = '*.xls'
          initial_directory       = 'C:\'
          multiselection          = ' '  "No multiple selection
        CHANGING
          file_table              = t_tabname
          rc                      = d_rc
        EXCEPTIONS
          file_open_dialog_failed = 1
          cntl_error              = 2
          error_no_gui            = 3
          not_supported_by_gui    = 4.
    
      READ TABLE t_tabname INTO p_file INDEX d_rc.
    

    Thank you for sharing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s