May 28, 2026

Sample Code of Using CL_GU_FRONTEND_SERVICES=>FILE_OPEN_DIALOG

The CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG method is the standard object-oriented way in ABAP to trigger a file selection popup on a user's local machine. It replaces older function modules like WS_FILENAME_GET

Basic Sample Code
This example demonstrates how to call the dialog and retrieve the selected file path to populate a selection screen parameter


abap
REPORT z_file_dialog_demo.

DATA: lt_file_table TYPE filetable, " Table to store selected files
      lv_rc         TYPE i.         " Return code

PARAMETERS: p_file TYPE localfile. " Selection screen parameter

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  " Call the File Open Dialog
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title            = 'Select your Excel File'
      default_extension       = '*.xlsx'
      file_filter             = 'Excel Files (*.XLSX)|*.XLSX|All Files (*.*)|*.*'
      multiselection          = abap_false " Set to 'X' to allow multiple files
    CHANGING
      file_table              = lt_file_table
      rc                      = lv_rc
    EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      OTHERS                  = 5.

  IF sy-subrc = 0 AND lv_rc > 0.
    " Retrieve the first selected file path
    READ TABLE lt_file_table INTO DATA(ls_file) INDEX 1.
    IF sy-subrc = 0.
      p_file = ls_file-filename.
    ENDIF.
  ENDIF.


Key Parameters Explained
  • window_title: The text that appears at the top of the popup window.
  • default_extension: Sets the initial file type the dialog looks for (e.g., .txt or .xlsx).
  • file_filter: Controls the "Files of type" dropdown. Use the format Description (*.ext)|*.ext.
  • multiselection: Set to abap_true ('X') if you want the user to be able to select multiple files at once.
  • file_table: A table of type FILETABLE that will hold the paths of the selected files.
  • rc: A return code that typically indicates the number of files selected by the user. 
Common Use Cases
  • F4 Help: Often used within the AT SELECTION-SCREEN ON VALUE-REQUEST event to provide a browse button for a file path input field.
  • Multi-File Selection: Unlike some older function modules, this method natively supports selecting several files at once for batch processing.
  • File Uploading: Typically followed by a call to CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD to bring the selected file's data into an internal SAP table


Ref:

https://community.sap.com/t5/application-development-and-automation-discussions/cl-gui-frontend-services-gt-file-open-dialog-initial-directory-ignored/td-p/416130

https://community.sap.com/t5/application-development-and-automation-discussions/file-open-dialog-no-extension/td-p/12747028

No comments :