SAP NetWeaver AS ABAP Release 751, ©Copyright 2017 SAP AG. All rights reserved.
ABAP - Keyword Documentation → ABAP - Reference → Data Interfaces and Communication Interfaces →Access to the Presentation Server
Programs that are executed in dialog and from SAP GUI can use the methods of the class CL_GUI_FRONTEND_SERVICES to access the current presentation server.
They can use
The function module GUI_IS_AVAILABLE can be used in advance to determine whether a SAP GUI is available.
Note
The methods of the class CL_GUI_FRONTEND_SERVICES replace older function modules with similar functions, such as GUI_UPLOAD, GUI_DOWNLOAD, WS_UPLOAD, or WS_DOWNLOAD.
Example
Writes to and reads a file on a presentation server with the operating system MS Windows. The directory is created on request. The SAP GUI availability prompt prevents runtime errors if the programs runs in the background.
DATA gui TYPE c LENGTH 1.
CALL FUNCTION 'GUI_IS_AVAILABLE'
IMPORTING
return = gui.
IF gui IS INITIAL.
RETURN.
ENDIF.
DATA(dir) = `C:\temp\my_temp\`.
DATA(name) = `myfile.dat`.
IF cl_gui_frontend_services=>directory_exist( dir ) = abap_false.
DATA rc TYPE i.
cl_gui_frontend_services=>directory_create(
EXPORTING
directory = dir
CHANGING
rc = rc
EXCEPTIONS
OTHERS = 4 ).
IF sy-subrc <> 0 OR
rc <> 0 OR
cl_gui_frontend_services=>directory_exist( dir ) = abap_false.
MESSAGE 'Directory could not be created' TYPE 'I' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
ENDIF.
DATA(file) = dir && name.
IF cl_gui_frontend_services=>file_exist( file ) = abap_true.
DATA ans TYPE c LENGTH 1.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
text_question = 'Overwrite existing file?'
text_button_1 = 'Yes'
text_button_2 = 'No'
IMPORTING
answer = ans.
ENDIF.
TYPES data_line TYPE x LENGTH 255.
DATA data_tab TYPE STANDARD TABLE OF data_line WITH EMPTY KEY.
CALL TRANSFORMATION id SOURCE text = `Test data`
RESULT XML data_tab.
IF ans <> 2.
cl_gui_frontend_services=>gui_download(
EXPORTING
filename = file
filetype = 'BIN'
CHANGING
data_tab = data_tab
EXCEPTIONS
OTHERS = 4 ).
IF sy-subrc <> 0.
MESSAGE 'File could not be written' TYPE 'I' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
ENDIF.
...
CLEAR data_tab.
cl_gui_frontend_services=>gui_upload(
EXPORTING
filename = file
filetype = 'BIN'
CHANGING
data_tab = data_tab
EXCEPTIONS
OTHERS = 4 ).
IF sy-subrc <> 0.
MESSAGE 'File could not be read' TYPE 'I' DISPLAY LIKE 'E'.
RETURN.
ENDIF.