CL_GUI_FRONTEND_SERVICES¶
Client-side file and OS services — download/upload files, browse directories, and open file selection dialogs on the user's PC.
Purpose¶
CL_GUI_FRONTEND_SERVICES provides static methods for interacting with the frontend (the user's PC) from an ABAP dialog session. All methods run on the client side via the SAP GUI communication layer.
Dialog sessions only
These methods fail silently or dump in background jobs — there is no GUI. Use server-side OPEN DATASET / CLOSE DATASET for server file access.
Key methods¶
| Method | Description |
|---|---|
GUI_DOWNLOAD |
Write data to a local file |
GUI_UPLOAD |
Read a local file into ABAP |
FILE_OPEN_DIALOG |
Show a file-picker dialog → returns selected path |
DIRECTORY_BROWSE |
Show a folder-picker dialog |
FILE_EXIST |
Check if a local file exists |
FILE_DELETE |
Delete a local file |
Examples¶
Download an internal table as CSV¶
REPORT z_frontend_csv_download.
START-OF-SELECTION.
" Read some data
SELECT carrid connid price currency
FROM sflight
INTO TABLE @DATA(lt_flights)
UP TO 10 ROWS.
" Build CSV lines (semicolon-delimited, common in European Excel)
DATA lt_lines TYPE STANDARD TABLE OF string.
APPEND 'CARRID;CONNID;PRICE;CURRENCY' TO lt_lines. " header row
LOOP AT lt_flights INTO DATA(ls_flight).
APPEND |{ ls_flight-carrid };{ ls_flight-connid };{ ls_flight-price };{ ls_flight-currency }|
TO lt_lines.
ENDLOOP.
" Download
cl_gui_frontend_services=>gui_download(
EXPORTING
filename = 'C:\temp\flights.csv'
filetype = 'ASC'
CHANGING
data_tab = lt_lines
EXCEPTIONS
file_write_error = 1
OTHERS = 2 ).
IF sy-subrc = 0.
MESSAGE 'CSV downloaded to C:\temp\flights.csv' TYPE 'S'.
ELSE.
MESSAGE 'Download failed' TYPE 'E'.
ENDIF.
Upload a CSV file into a string table¶
REPORT z_frontend_csv_upload.
START-OF-SELECTION.
DATA: lt_files TYPE filetable,
lv_rc TYPE i,
lv_filename TYPE string.
" Show file picker dialog
cl_gui_frontend_services=>file_open_dialog(
EXPORTING
window_title = 'Select CSV file'
default_extension = 'csv'
file_filter = 'CSV files (*.csv)|*.csv|All files (*.*)|*.*|'
CHANGING
file_table = lt_files
rc = lv_rc
EXCEPTIONS
OTHERS = 1 ).
IF lv_rc <> 1 OR lt_files IS INITIAL.
MESSAGE 'No file selected' TYPE 'W'.
RETURN.
ENDIF.
lv_filename = lt_files[ 1 ]-filename.
" Upload the file
DATA lt_lines TYPE STANDARD TABLE OF string.
cl_gui_frontend_services=>gui_upload(
EXPORTING
filename = lv_filename
filetype = 'ASC'
CHANGING
data_tab = lt_lines
EXCEPTIONS
OTHERS = 1 ).
IF sy-subrc <> 0.
MESSAGE 'Upload failed' TYPE 'E'.
RETURN.
ENDIF.
" Process lines (skip header row)
LOOP AT lt_lines INTO DATA(lv_line) FROM 2.
DATA lt_fields TYPE STANDARD TABLE OF string.
SPLIT lv_line AT ';' INTO TABLE lt_fields.
" lt_fields[ 1 ] = CARRID, lt_fields[ 2 ] = CONNID, etc.
WRITE: / lv_line.
ENDLOOP.
Download a binary file (xstring → local file)¶
REPORT z_frontend_binary_download.
START-OF-SELECTION.
" Create a small ZIP in memory (see CL_ABAP_ZIP page for details)
DATA(lo_zip) = NEW cl_abap_zip( ).
DATA(lo_conv) = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' ).
lo_conv->write( data = 'Hello,World' ).
lo_zip->add( name = 'test.csv' content = lo_conv->get_buffer( ) ).
DATA(lx_zip) = lo_zip->save( ).
" Convert xstring to binary table for download
DATA lt_rawdata TYPE STANDARD TABLE OF x255.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING buffer = lx_zip
TABLES binary_tab = lt_rawdata.
" Download binary file
cl_gui_frontend_services=>gui_download(
EXPORTING
filename = 'C:\temp\export.zip'
filetype = 'BIN'
CHANGING
data_tab = lt_rawdata
EXCEPTIONS
OTHERS = 1 ).
IF sy-subrc = 0.
MESSAGE 'ZIP downloaded to C:\temp\export.zip' TYPE 'S'.
ELSE.
MESSAGE 'Download failed' TYPE 'E'.
ENDIF.
See also¶
CL_ABAP_ZIP— create ZIP archives to downloadCL_ABAP_CONV_OUT_CE— encoding conversion before downloadDYNPRO_SEND_IN_BACKGROUND— dump when called in background