GUI_UPLOAD¶
Transfer a file from the user's PC to an ABAP internal table.
Purpose¶
GUI_UPLOAD reads any text or binary file from the frontend machine and returns it as an internal table. For text (ASC) mode each row in DATA_TAB holds one line of the file. For binary (BIN) mode each row holds a chunk of raw bytes. It's the general-purpose upload FM for CSV, tab-delimited, and other flat files — reach for it whenever ALSM_EXCEL_TO_INTERNAL_TABLE is overkill or unavailable.
Frontend only — no background support
GUI_UPLOAD requires an active SAP GUI session. It cannot be used in batch jobs, scheduled reports, or RFC destinations that have no frontend connection.
Signature¶
| Parameter | Direction | Type | Notes |
|---|---|---|---|
FILENAME |
IMPORTING | STRING |
Full path on the frontend machine. |
FILETYPE |
IMPORTING | CHAR10 |
'ASC' for text (default), 'BIN' for binary. |
HAS_FIELD_SEPARATOR |
IMPORTING | CHAR1 |
Pass 'X' to split columns into DATA_TAB automatically (ASC only). |
SEPARATOR |
IMPORTING | CHAR1 |
Column separator used when HAS_FIELD_SEPARATOR = 'X' (default: tab). |
HEADER_LENGTH |
IMPORTING | INT4 |
Number of bytes to read into HEADER_TAB before the data (BIN). |
DATA_TAB |
TABLES | STRING |
Output lines (ASC) or raw byte chunks (BIN). |
HEADER_TAB |
TABLES | STRING |
Optional — receives the file header bytes when HEADER_LENGTH > 0. |
Example — upload a CSV and split each line¶
REPORT z_csv_upload.
PARAMETERS p_file TYPE string.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-repid
dynpro_number = syst-dynnr
IMPORTING
file_name = p_file.
TYPES: BEGIN OF ty_row,
col1 TYPE string,
col2 TYPE string,
col3 TYPE string,
END OF ty_row.
DATA: lt_raw TYPE STANDARD TABLE OF string,
lt_rows TYPE STANDARD TABLE OF ty_row,
ls_row TYPE ty_row.
START-OF-SELECTION.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = p_file
filetype = 'ASC'
TABLES
data_tab = lt_raw
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
OTHERS = 17.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno.
ENDIF.
" Skip header row and split each CSV line
DELETE lt_raw INDEX 1.
LOOP AT lt_raw INTO DATA(lv_line).
SPLIT lv_line AT ',' INTO ls_row-col1 ls_row-col2 ls_row-col3.
APPEND ls_row TO lt_rows.
ENDLOOP.
LOOP AT lt_rows INTO ls_row.
WRITE: / ls_row-col1, ls_row-col2, ls_row-col3.
ENDLOOP.
BIN mode for Excel uploads
To upload an Excel file, use FILETYPE = 'BIN' and pass the resulting DATA_TAB to TEXT_CONVERT_XLS_TO_SAP for parsing. See TEXT_CONVERT_XLS_TO_SAP for the full two-step flow.
Common pitfalls¶
- Line length limit (ASC): each line in
DATA_TABis truncated at 1023 characters. Files with longer lines silently lose the overflow. Use BIN mode and parse manually if you expect wide lines. - BIN mode output:
DATA_TAB-LINEcontains raw bytes inX(hex) format, not printable characters. You needTEXT_CONVERT_XLS_TO_SAPor similar to interpret the bytes. - No batch: the exception
NO_BATCHfires when the FM is called from a background job. Checksy-batchbefore calling and provide an alternative server-side read if needed. - CRLF handling: in ASC mode on Windows files, carriage returns (
\r) may be appended to each line. Strip them withREPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>cr_lf IN lv_line WITH ...if downstream comparisons fail. - File encoding: the FM reads bytes as-is. UTF-8 files with a BOM will have
EF BB BFat the start of the first line. Strip the BOM explicitly if it causes parse errors.
See also¶
F4_FILENAME— file-picker dialog to get the path before uploadingALSM_EXCEL_TO_INTERNAL_TABLE— simpler Excel upload (OLE-based, no BIN step needed)TEXT_CONVERT_XLS_TO_SAP— server-side XLS parser for the BIN output- Tutorial: How to upload an Excel file