SAP obsolete functions (2) – CL_GUI_FRONTEND_SERVICES

CL_GUI_FRONTEND_SERVICES

This class give you a collection of static method in order to access to the Frontend Services such as:

  • File functions
  • Directory functions
  • Registry
  • Environment
  • Write to / read from clipboard
  • Upload / download files
  • Execute programs / open documents
  • Query functions, such as Windows directory, Windows version, and so on
  • Standard dialogs (open, save, directory selection)

FILE_OPEN_DIALOG & FILE_SAVE_DIALOG

Determination of a file name on the presentation server using a file selection dialog.

WS_FILENAME_GET is the obsolete function used for this scope, it has two operation modes: Open and Save

In Open mode

CALL FUNCTION ‘WS_FILENAME_GET’
EXPORTING
* DEF_FILENAME = ‘ ‘
* DEF_PATH = ‘ ‘
* MASK = ‘ ‘

MODE = ‘O’
* TITLE = ‘ ‘
IMPORTING
FILENAME = lv_filename
*
RC =
*
EXCEPTIONS
*
INV_WINSYS = 1
*
NO_BATCH = 2
*
SELECTION_CANCEL = 3
*
SELECTION_ERROR = 4
*
OTHERS = 5
.

In ECC is necessary to use method FILE_OPEN_DIALOG

DATA: lt_file_table TYPE filetable,
ls_file_table
TYPE file_table,
lv_filename TYPE string,
lv_rc TYPE i.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
* EXPORTING
* WINDOW_TITLE =
* DEFAULT_EXTENSION =
* DEFAULT_FILENAME =
* FILE_FILTER =
* WITH_ENCODING =
* INITIAL_DIRECTORY =
* MULTISELECTION =

CHANGING
FILE_TABLE = lt_file_table
RC = lv_rc
* USER_ACTION =
* FILE_ENCODING =
* EXCEPTIONS
* FILE_OPEN_DIALOG_FAILED = 1
* CNTL_ERROR = 2
* ERROR_NO_GUI = 3
* NOT_SUPPORTED_BY_GUI = 4
* OTHERS = 5

.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ELSE.
CHECK lv_rc = 1.
READ TABLE lt_file_table INTO ls_file_table INDEX 1.
CHECK sy-subrc = 0.
MOVE ls_file_table-filename TO lv_filename.
ENDIF.

Or you can use this code in order to avoid CHECK statement

IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ELSE.
IF lv_rc > 0.
READ TABLE lt_file_table INTO ls_file_table INDEX 1.
MOVE ls_file_table-filename TO lv_filename.
ENDIF.
ENDIF.

In Save mode

CALL FUNCTION ‘WS_FILENAME_GET’
EXPORTING
* DEF_FILENAME = ‘ ‘
* DEF_PATH = ‘ ‘
* MASK = ‘ ‘

MODE = ‘S’
* TITLE = ‘ ‘
IMPORTING
FILENAME = lv_filename
*
RC =
*
EXCEPTIONS
*
INV_WINSYS = 1
*
NO_BATCH = 2
*
SELECTION_CANCEL = 3
*
SELECTION_ERROR = 4
*
OTHERS = 5
.

In ECC is necessary to use method FILE_SAVE_DIALOG

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
* EXPORTING
* WINDOW_TITLE =
* DEFAULT_EXTENSION =
* DEFAULT_FILENAME =

* FILE_FILTER =
* INITIAL_DIRECTORY =

* PROMPT_ON_OVERWRITE = ‘X’

CHANGING
FILENAME = lv_filename
PATH = lv_path
FULLPATH = lv_fullpath
* USER_ACTION =
* FILE_ENCODING =
* EXCEPTION
* CNTL_ERROR = 1
* ERROR_NO_GUI = 2
* NOT_SUPPORTED_BY_GUI = 3
* OTHERS = 4
.

This new method give to you the possibility also to gather information about the PATH and the FULLPATH.

EXECUTE

Any (non-SAP) program (for example, editor, table calculation, etc.) can be started on the presentation server.

WS_EXECUTE is now obsolete and it is suggested to do not use it anymore.

CALL FUNCTION ‘WS_EXECUTE’
* EXPORTING
* DOCUMENT = ‘ ‘
* CD = ‘ ‘
* COMMANDLINE = ‘ ‘
* INFORM = ‘ ‘
* PROGRAM = ‘ ‘
* STAT = ‘ ‘
* WINID = ‘ ‘
* OSMAC_SCRIPT = ‘ ‘
* OSMAC_CREATOR = ‘ ‘
* WIN16_EXT = ‘ ‘
* EXEC_RC = ‘ ‘
* IMPORTING
* RBUFF =
* EXCEPTIONS
* FRONTEND_ERROR = 1
* NO_BATCH = 2
* PROG_NOT_FOUND = 3
* ILLEGAL_OPTION = 4
* GUI_REFUSE_EXECUTE = 5
* OTHERS = 6
.

Now you have to use method EXECUTE that it is really simple to use.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE
* EXPORTING
* DOCUMENT =
* APPLICATION =
* PARAMETER =
* DEFAULT_DIRECTORY =
* MAXIMIZED =
* MINIMIZED =
* SYNCHRONOUS =
* OPERATION = ‘OPEN’
* EXCEPTIONS
* CNTL_ERROR = 1
* ERROR_NO_GUI = 2
* BAD_PARAMETER = 3
* FILE_NOT_FOUND = 4
* PATH_NOT_FOUND = 5
* FILE_EXTENSION_UNKNOWN = 6
* ERROR_EXECUTE_FAILED = 7
* SYNCHRONOUS_FAILED = 8
* NOT_SUPPORTED_BY_GUI = 9
* OTHERS = 10
.

GUI_DOWNLOAD & GUI_UPLOAD

WS_DOWNLOAD and WS_UPLOAD are obsolete functions module for storing SAP data in a file or retrieving data from a file in the file system of the presentation server.

CALL FUNCTION ‘WS_DOWNLOAD’
* EXPORTING
*   BIN_FILESIZE                  = ‘ ‘
*   CODEPAGE                      = ‘ ‘
*   FILENAME                      = ‘ ‘
*   FILETYPE                      = ‘ASC’
*   MODE                          = ‘ ‘
*   WK1_N_FORMAT                  = ‘ ‘
*   WK1_N_SIZE                    = ‘ ‘
*   WK1_T_FORMAT                  = ‘ ‘
*   WK1_T_SIZE                    = ‘ ‘
*   COL_SELECT                    = ‘ ‘
*   COL_SELECTMASK                = ‘ ‘
*   NO_AUTH_CHECK                 = ‘ ‘
* IMPORTING
*   FILELENGTH                    =

TABLES
DATA_TAB                      = lt_datatab
*   FIELDNAMES                    =
* EXCEPTIONS
*   FILE_OPEN_ERROR               = 1
*   FILE_WRITE_ERROR              = 2
*   INVALID_FILESIZE              = 3
*   INVALID_TYPE                  = 4
*   NO_BATCH                      = 5
*   UNKNOWN_ERROR                 = 6
*   INVALID_TABLE_WIDTH           = 7
*   GUI_REFUSE_FILETRANSFER       = 8
*   CUSTOMER_ERROR                = 9
*   NO_AUTHORITY                  = 10
*   OTHERS                        = 11

.

CALL FUNCTION ‘WS_UPLOAD’
* EXPORTING
*   CODEPAGE                      = ‘ ‘
*   FILENAME                      = ‘ ‘
*   FILETYPE                      = ‘ASC’
*   HEADLEN                       = ‘ ‘
*   LINE_EXIT                     = ‘ ‘
*   TRUNCLEN                      = ‘ ‘
*   USER_FORM                     = ‘ ‘
*   USER_PROG                     = ‘ ‘
*   DAT_D_FORMAT                  = ‘ ‘
* IMPORTING
*   FILELENGTH                    =

TABLES
DATA_TAB                      =
* EXCEPTIONS
*   CONVERSION_ERROR              = 1
*   FILE_OPEN_ERROR               = 2
*   FILE_READ_ERROR               = 3
*   INVALID_TYPE                  = 4
*   NO_BATCH                      = 5
*   UNKNOWN_ERROR                 = 6
*   INVALID_TABLE_WIDTH           = 7
*   GUI_REFUSE_FILETRANSFER       = 8
*   CUSTOMER_ERROR                = 9
*   NO_AUTHORITY                  = 10
*   OTHERS                        = 11

.

Now you ave to use method or function module GUI_DOWNLOAD and GUI_UPLOAD

CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
EXPORTING
*    BIN_FILESIZE              =
FILENAME                  = lv_filename
*    FILETYPE                  = ‘ASC’
*    APPEND                    = SPACE
*    WRITE_FIELD_SEPARATOR     = SPACE
*    HEADER                    = ’00’
*    TRUNC_TRAILING_BLANKS     = SPACE
*    WRITE_LF                  = ‘X’
*    COL_SELECT                = SPACE
*    COL_SELECT_MASK           = SPACE
*    DAT_MODE                  = SPACE
*    CONFIRM_OVERWRITE         = SPACE
*    NO_AUTH_CHECK             = SPACE
*    CODEPAGE                  = SPACE
*    IGNORE_CERR               = ABAP_TRUE
*    REPLACEMENT               = ‘#’
*    WRITE_BOM                 = SPACE
*    TRUNC_TRAILING_BLANKS_EOL = ‘X’
*    WK1_N_FORMAT              = SPACE
*    WK1_N_SIZE                = SPACE
*    WK1_T_FORMAT              = SPACE
*    WK1_T_SIZE                = SPACE
*  IMPORTING
*    FILELENGTH                =

CHANGING
DATA_TAB                  = lt_datatab
*  EXCEPTIONS
*    FILE_WRITE_ERROR          = 1
*    NO_BATCH                  = 2
*    GUI_REFUSE_FILETRANSFER   = 3
*    INVALID_TYPE              = 4
*    NO_AUTHORITY              = 5
*    UNKNOWN_ERROR             = 6
*    HEADER_NOT_ALLOWED        = 7
*    SEPARATOR_NOT_ALLOWED     = 8
*    FILESIZE_NOT_ALLOWED      = 9
*    HEADER_TOO_LONG           = 10
*    DP_ERROR_CREATE           = 11
*    DP_ERROR_SEND             = 12
*    DP_ERROR_WRITE            = 13
*    UNKNOWN_DP_ERROR          = 14
*    ACCESS_DENIED             = 15
*    DP_OUT_OF_MEMORY          = 16
*    DISK_FULL                 = 17
*    DP_TIMEOUT                = 18
*    FILE_NOT_FOUND            = 19
*    DATAPROVIDER_EXCEPTION    = 20
*    CONTROL_FLUSH_ERROR       = 21
*    NOT_SUPPORTED_BY_GUI      = 22
*    ERROR_NO_GUI              = 23
*    others                    = 24

.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
*  EXPORTING
*    FILENAME                = SPACE
*    FILETYPE                = ‘ASC’
*    HAS_FIELD_SEPARATOR     = SPACE
*    HEADER_LENGTH           = 0
*    READ_BY_LINE            = ‘X’
*    DAT_MODE                = SPACE
*    CODEPAGE                = SPACE
*    IGNORE_CERR             = ABAP_TRUE
*    REPLACEMENT             = ‘#’
*    VIRUS_SCAN_PROFILE      =
*  IMPORTING
*    FILELENGTH              =
*    HEADER                  =

CHANGING
DATA_TAB                = lt_datatab
*  EXCEPTIONS
*    FILE_OPEN_ERROR         = 1
*    FILE_READ_ERROR         = 2
*    NO_BATCH                = 3
*    GUI_REFUSE_FILETRANSFER = 4
*    INVALID_TYPE            = 5
*    NO_AUTHORITY            = 6
*    UNKNOWN_ERROR           = 7
*    BAD_DATA_FORMAT         = 8
*    HEADER_NOT_ALLOWED      = 9
*    SEPARATOR_NOT_ALLOWED   = 10
*    HEADER_TOO_LONG         = 11
*    UNKNOWN_DP_ERROR        = 12
*    ACCESS_DENIED           = 13
*    DP_OUT_OF_MEMORY        = 14
*    DISK_FULL               = 15
*    DP_TIMEOUT              = 16
*    NOT_SUPPORTED_BY_GUI    = 17
*    ERROR_NO_GUI            = 18
*    others                  = 19

.

To be continue…

6 thoughts on “SAP obsolete functions (2) – CL_GUI_FRONTEND_SERVICES”

  1. You only give obvious answers to easy questions.
    Try reading a directory with last-modification-date of every file. It is not possible as far as I know.
    Try to solve the problem by executing the DIR command with redirecting output to a temporary file. The method EXECUTE is not able to do dos commands or to redirect output.
    Try to find out if the clinet PC is running windows. CL_GUI_FRONTEND_SERVICES=>M_PLATFORM is PRIVATE.

    I am pissed
    Sorry, not your fault.

  2. You’re right, this is only a starting point to the most common use cases.

    To determine the user operating system have you tryed CL_GUI_FRONTEND_SERVICES=>GET_PLATFORM?

    I repeat this is only a starting point then you have to evaluate case by case.

    For the other questions I don’t remember right now I have to investigate.

    Regards,
    Ivan

  3. Hey there…love the blog.

    Am I understanding correctly that CL_GUI_FRONTEND_SERVICES is for interacting through the sap gui on the local system?
    What is the comparable FM/Class for the backend. For example, what if I wanted to call an executable on the server?

Leave a Reply