F4_FILENAME¶
Open the standard file-picker dialog on the user's desktop.
Purpose¶
F4_FILENAME triggers the OS file-open dialog, lets the user browse to a file, and writes the selected path back to an exporting parameter. Wire it to AT SELECTION-SCREEN ON VALUE-REQUEST and you get a proper F4 help on any file-path parameter — no custom dialog needed.
Dialog mode only
This FM calls the SAP GUI frontend. It will dump or return empty in background jobs and RFC calls that have no active GUI session.
Signature¶
| Parameter | Direction | Type | Notes |
|---|---|---|---|
PROGRAM_NAME |
IMPORTING | SY-REPID |
Pass syst-repid — identifies the calling program. |
DYNPRO_NUMBER |
IMPORTING | SY-DYNNR |
Pass syst-dynnr — the current screen number. |
FIELD_NAME |
IMPORTING | CHAR132 |
Name of the screen field as a string (e.g. 'P_FILE'). Case-insensitive but must match exactly. |
FILE_NAME |
EXPORTING | RLGRAP-FILENAME |
The path chosen by the user. Empty if the user cancels. |
Example — F4 help on a selection-screen parameter¶
REPORT z_file_picker.
PARAMETERS p_file TYPE rlgrap-filename.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-repid
dynpro_number = syst-dynnr
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
START-OF-SELECTION.
IF p_file IS INITIAL.
MESSAGE 'No file selected.' TYPE 'I'.
RETURN.
ENDIF.
" Continue with p_file ...
WRITE: / 'Selected:', p_file.
FIELD_NAME is optional in practice
Many programs omit FIELD_NAME or pass it empty — the dialog still opens and the selected path is returned via FILE_NAME. Pass the field name only if you need the FM to write back into the screen field directly.
Common pitfalls¶
- FIELD_NAME case: the parameter is case-insensitive at runtime, but it must spell the screen field name correctly. A typo means the path is not written back to the screen field.
- Cancel returns empty: if the user closes the dialog without selecting a file,
FILE_NAMEis returned as a space or unchanged. Always checkIS INITIALbefore using the value. - Background incompatibility: calling this FM in a background job raises a runtime error. Guard with
IF sy-batch = abap_falseif the same code path can run in both modes. - Path format is OS-specific: the returned path uses the format of the frontend OS (Windows backslashes). Don't assume UNIX paths even on a Linux application server.
See also¶
ALSM_EXCEL_TO_INTERNAL_TABLE— pass the result directly asFILENAMEGUI_UPLOAD— use the selected path to upload the file contents