Skip to content

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.

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. The NO_BATCH exception fires if called from a background job.

Signature

Importing

Parameter Type Default Notes
FILENAME STRING — Full path on the frontend machine. Required.
FILETYPE CHAR10 'ASC' 'ASC' for text, 'BIN' for binary.
HAS_FIELD_SEPARATOR CHAR01 SPACE 'X' to split fields automatically (ASC only).
HEADER_LENGTH I 0 Bytes to read into HEADER before data (BIN).
READ_BY_LINE CHAR01 'X' 'X' = one row per line; SPACE = full file in one row.
DAT_MODE CHAR01 SPACE 'X' for DAT file format (field separator is tab).
CODEPAGE ABAP_ENCODING SPACE Target code page. Empty = system default.
IGNORE_CERR ABAP_BOOL ABAP_TRUE Ignore character conversion errors.
REPLACEMENT ABAP_REPL '#' Replacement character for unconvertible chars.
CHECK_BOM CHAR01 SPACE 'X' to detect and strip a UTF BOM automatically.
VIRUS_SCAN_PROFILE VSCAN_PROFILE — Optional virus scan profile.
NO_AUTH_CHECK CHAR01 SPACE 'X' to skip authorization check (use with care).

Exporting

Parameter Type Notes
FILELENGTH I Total file size in bytes.
HEADER XSTRING File header bytes when HEADER_LENGTH > 0.

Tables

Parameter Notes
DATA_TAB Output lines (ASC) or raw byte chunks (BIN). Untyped — declare as STANDARD TABLE OF string for text.

Changing

Parameter Type Notes
ISSCANPERFORMED CHAR01 Set to 'X' by the FM if a virus scan was performed.

Exceptions

Exception When raised
FILE_OPEN_ERROR File could not be opened
FILE_READ_ERROR Error reading file contents
NO_BATCH Called from a background job
GUI_REFUSE_FILETRANSFER SAP GUI rejected the transfer
INVALID_TYPE FILETYPE value not recognised
NO_AUTHORITY Missing authorisation
UNKNOWN_ERROR Unexpected error
BAD_DATA_FORMAT Data format mismatch
HEADER_NOT_ALLOWED Header requested in incompatible mode
SEPARATOR_NOT_ALLOWED Field separator used in incompatible mode
HEADER_TOO_LONG Header exceeds allowed length
UNKNOWN_DP_ERROR Unknown data provider error
ACCESS_DENIED Access to file denied
DP_OUT_OF_MEMORY Data provider out of memory
DISK_FULL Target disk full
DP_TIMEOUT Data provider timeout

Example — upload a CSV and split each line

REPORT z_csv_upload.

DATA: lt_raw   TYPE STANDARD TABLE OF string,
      lv_len   TYPE i,
      lv_file  TYPE string.

PARAMETERS p_file TYPE ibipparms-path.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  = sy-repid
      dynpro_number = sy-dynnr
      field_name    = 'P_FILE'
    IMPORTING
      file_name     = p_file.

START-OF-SELECTION.

  lv_file = p_file.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = lv_file
      filetype                = 'ASC'
    IMPORTING
      filelength              = lv_len
    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.

  WRITE: / |{ lv_len } bytes read, { lines( lt_raw ) } lines.|.

  " Skip header row and split each CSV line
  DELETE lt_raw INDEX 1.

  LOOP AT lt_raw INTO DATA(lv_line).
    DATA(lv_col1) = lv_line.
    DATA(lv_col2) = lv_line.
    DATA(lv_col3) = lv_line.
    SPLIT lv_line AT ',' INTO lv_col1 lv_col2 lv_col3.
    WRITE: / lv_col1, lv_col2, lv_col3.
  ENDLOOP.

Common pitfalls

  • Line length limit (ASC): each line in DATA_TAB is 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 contains raw bytes. You need TEXT_CONVERT_XLS_TO_SAP or similar to interpret them.
  • CRLF on Windows files: in ASC mode, carriage returns (CR) may appear at the end of each line. Strip them with REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>cr_lf IN lv_line WITH space if downstream comparisons fail.
  • UTF-8 BOM: pass CHECK_BOM = 'X' to strip the BOM automatically instead of handling it manually.
  • Client filtering: does not apply — this FM reads from the frontend filesystem, not the database.

See also

Comments