Showing posts with label SAP GUI. Show all posts
Showing posts with label SAP GUI. Show all posts

May 28, 2026

F4 Help to Get File from AL11 in Selection Screen

To provide F4 value help for files on the application server (AL11), the most effective way is to use specific SAP function modules within your ABAP code. Since standard search help doesn't automatically browse application server directories, you must implement the logic in the AT SELECTION-SCREEN ON VALUE-REQUEST event.

Recommended Function Modules
For browsing and selecting files directly from the application server, you can use these common modules:
  • /SAPDMC/LSM_F4_SERVER_FILE: This is widely used to open a pop-up that allows users to navigate the SAP AL11 directories and select a file.
  • F4_DXFILENAME_TOPRECURSION: Another standard function module specifically designed for search help on application server files.
Implementation Example
To add this help to a selection screen parameter (e.g., p_file), use the following logic in your report:

abap
PARAMETERS: p_file TYPE string.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
    IMPORTING
      serverfile       = p_file
    EXCEPTIONS
      canceled_by_user = 1
      OTHERS           = 2.

Key Considerations
  • Permissions: Ensure the user has the necessary authorizations (e.g., S_DATASET) to access the specific AL11 directory paths.
  • Directory-only Help: If you only need to select a directory (not a specific file), you can call the program RSWATCH0 or use F4IF_INT_TABLE_VALUE_REQUEST after fetching directory lists via EPS_GET_DIRECTORY_LISTING.
  • Presentation Server Difference: For files on your local PC (Presentation Server), use CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG instead

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

Nov 10, 2010

SAPGUI shortcuts

Introduction
SAPGUI shortcuts are files located on a computer with SAPGUI for Windows installed, which are used to login directly to a SAP system, or run directly a SAP transaction, or entering okcode commands on modal dialogs.


How to create a SAPGUI shortcut

There are 4 ways to create a SAPGUI shortcut:
Approach 1:
  • Click on the Create shortcut icon on a the toolbar in a SAPGUI session
  • In the popup window, enter the values you need  
  • See SAP Library and note 103019 in Links chapter below for more information. The TYPE field may be Report, Transaction or System Command (this late one is useful for entering /H in popup windows)
  • A shortcut on the Desktop (or the location you entered) will be created
Approach 2:
  • From desktop, choose Create SAP Shortcut using contextual menu and enter file name with extension .sap
  • Then choose Modify in the SAP Shortcut contextual menu and enter Shortcut attributes as above
Approach 3:
  • Create a text file with .SAP extension on the desktop with this kind of content (replace the values with your local ones):
    [System]
    Name=YD1
    Description=04 - **** Solman ****
    Client=100
    [User]
    Name=ALBERT
    Language=
    [Function]
    Title=Debug
    Command=/H
    Type=SystemCommand
    [Configuration]
    WorkDir=C:\Documents and Settings\albert\SapWorkDir
    [Options]
    Reuse=1
    The parameters are more or less explained in note 103019 below, as the sapshcut.exe parameters have the same names.
Approach 4:
  • It is also possible to create a shortcut file from an ABAP program by calling SWN_CREATE_SHORTCUT function module, and save the text to a file (using GUI_DOWNLOAD function module). See the wiki in the Links below.


How to execute a SAPGUI shortcut

There are 3 ways to execute a SAPGUI shortcut:
  • Double-click the .SAP file from Windows desktop or Windows explorer
  • You may execute a .SAP file by sapsh.exe before 4.5 and sapshcut.exe after 4.5
  • Drag and drop the .SAP file to an existing SAPGUI session window. It is especially useful for system commands (okcode commands) that need to be entered on a modal window (popup) as the okcode field is protected, like /H, /RON, /ROFF, etc.
    • Locate the window of your SAP popup window:
    • Display desktop by Windows-D key, then drag (do not drop) the shortcut to the window
    • Drag the shortcut to the popup window: 
             
    • Drop it: