Skip to end of metadata
Go to start of metadata

This snippet shows how can you create f4 help for choosing files on the application server and Presentation server depending on the choice made in the dialog screen.For F4 help of presentation server files, the static method file_save_dialog of the class cl_gui_frontend_services is called and for files listing on the application server, the function module 'F4_DXFILENAME_TOPRECURSION' is used.

The Screen has 2 radiobuttons ( p_appserver & p_frontend ) and an input field for the file name with the full path. The flow logic is as follows :

*Screen number        100
process before output.
  MODULE pbo_100.
  MODULE status_0100.

process after input.
  MODULE user_command_0100.

process on value-request.
  field file_name module f4_help_file.
 
*&---------------------------------------------------------------------*
*& Report Z_FILE_POPUP_TST *
*& *
*&---------------------------------------------------------------------*
REPORT z_file_popup_tst .
DATA: p_appserver TYPE c,
      p_frontend TYPE c.
DATA: ok_code LIKE sy-ucomm.
DATA: p_app TYPE c VALUE 'X',
      p_lc TYPE c.
DATA : file_name LIKE rlgrap-filename.

CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module f4_help_file INPUT
*&---------------------------------------------------------------------*
MODULE f4_help_file INPUT.
  DATA: fname TYPE string,
        fpath TYPE string,
        fpath_full TYPE string.
  DATA: c_fnh_mask TYPE dxfields-filemask VALUE '.',
        search_dir TYPE dxfields-longpath VALUE '/sapglobal/users',
        file_path LIKE dxfields-longpath.

  IF p_lc IS NOT INITIAL.
    CALL METHOD cl_gui_frontend_services=>file_save_dialog
      EXPORTING
        window_title         = 'Choose a location'
      CHANGING
        filename             = fname
        path                 = fpath
        fullpath             = fpath_full
      EXCEPTIONS
        cntl_error           = 1
        error_no_gui         = 2
        not_supported_by_gui = 3
        OTHERS               = 4.
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF.
      IF sy-subrc = 0.
        file_name = fpath.
      ENDIF.
    ENDIF.
    IF p_app IS NOT INITIAL.
      CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
        EXPORTING
          i_location_flag = 'A'
          i_server        = ' '
          i_path          = search_dir
          filemask        = c_fnh_mask
          fileoperation   = 'R'
        IMPORTING
          o_path          = file_path
        EXCEPTIONS
          rfc_error       = 1
          OTHERS          = 2.
      IF sy-subrc EQ 0.
        file_name = file_path.
      ENDIF.
    ENDIF.
  ENDMODULE. " f4_help_file INPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'MAIN_0100'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  DATA save_ok LIKE sy-ucomm.
  save_ok = ok_code.
  CLEAR ok_code.
  CASE save_ok.
    WHEN 'BACK' OR 'EXIT'.
      LEAVE PROGRAM.
    WHEN 'RADIO'.
      IF p_appserver = 'X'.
        p_app = 'X'.
        CLEAR p_lc.
      ENDIF.
      IF p_frontend = 'X'.
        p_lc = 'X'.
        CLEAR p_app.
      ENDIF.
  ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module pbo_100 OUTPUT
*&---------------------------------------------------------------------*
MODULE pbo_100 OUTPUT.
ENDMODULE. " pbo_100 OUTPUT