Skip to content

TEXT_CONVERT_XLS_TO_SAP

Server-side Excel-to-internal-table conversion — no OLE, no Excel required on the frontend.

Purpose

TEXT_CONVERT_XLS_TO_SAP parses an XLS or XLSX binary — already uploaded as a raw-byte table — directly on the application server. Because no OLE call is involved and no Microsoft Excel installation is required, this FM works in background jobs and RFC destinations. The typical flow is: GUI_UPLOAD with FILETYPE='BIN' to move raw bytes from the frontend → TEXT_CONVERT_XLS_TO_SAP to convert them into a typed internal table.

Comparison with ALSM_EXCEL_TO_INTERNAL_TABLE

ALSM_EXCEL_TO_INTERNAL_TABLE uses OLE and runs on the frontend — it needs Excel installed and fails in background. TEXT_CONVERT_XLS_TO_SAP runs on the server, handles larger files faster, and supports background scheduling.

Signature

Importing

Parameter Type Default Notes
I_FIELD_SEPERATOR CHAR01 Column delimiter used in the raw data. Optional.
I_LINE_HEADER CHAR01 Pass 'X' to skip the first row (header row).
I_TAB_RAW_DATA TRUXS_T_TEXT_DATA Raw binary content from GUI_UPLOAD with FILETYPE='BIN'. Required.
I_FILENAME RLGRAP-FILENAME Filename including extension — used for format detection (.xls vs .xlsx). Optional.
I_STEP I 1 Processing step. 1 = full conversion; 2 = skip upload step.
I_FILENAME_LONG CHAR0256 Alternative to I_FILENAME for paths longer than 128 characters. Optional.

Tables

Parameter Type Notes
I_TAB_CONVERTED_DATA STANDARD TABLE Output — one row per Excel row, typed to your target structure.

Exceptions

Exception When raised
CONVERSION_FAILED Parsing failed — wrong format, corrupt file, or column mismatch.

Example — full two-step upload flow

REPORT z_xls_server_upload.

TYPES: BEGIN OF ty_material,
         matnr TYPE matnr,
         maktx TYPE maktx,
         meins TYPE meins,
       END OF ty_material.

DATA: lt_raw  TYPE truxs_t_text_data,
      lt_mat  TYPE STANDARD TABLE OF ty_material,
      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.

  " Step 1 — upload raw bytes from frontend to server
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = lv_file
      filetype                = 'BIN'
    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
      OTHERS                  = 7.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno.
    RETURN.
  ENDIF.

  " Step 2 — parse Excel on the server into a typed table
  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_line_header        = 'X'
      i_tab_raw_data       = lt_raw
      i_filename           = p_file
    TABLES
      i_tab_converted_data = lt_mat
    EXCEPTIONS
      conversion_failed    = 1
      OTHERS               = 2.

  IF sy-subrc <> 0.
    MESSAGE 'Excel conversion failed.' TYPE 'E'.
    RETURN.
  ENDIF.

  LOOP AT lt_mat INTO DATA(ls_mat).
    WRITE: / ls_mat-matnr, ls_mat-maktx, ls_mat-meins.
  ENDLOOP.

Cell value length

The FM maps each Excel cell to a field in your target structure positionally. If a cell value is longer than the corresponding field it is truncated without error. Test with your longest real data values before going live.

Common pitfalls

  • Format detection relies on the filename extension: pass I_FILENAME with the correct .xls or .xlsx extension. Passing an empty string or wrong extension can cause CONVERSION_FAILED.
  • p_file is ibipparms-path, GUI_UPLOAD expects STRING: assign to an intermediate lv_file TYPE string before the GUI_UPLOAD call. I_FILENAME of this FM accepts RLGRAP-FILENAME (CHAR128), so p_file can be passed directly.
  • Merged cells and formulas: merged cells are returned as empty for all but the top-left cell. Formula cells return an empty value — replace formulas with static values before uploading.
  • Column count must match the target structure: the FM maps columns positionally. If the Excel has more or fewer columns than your ABAP type, results shift silently.
  • Background use: TEXT_CONVERT_XLS_TO_SAP itself runs on the server, but the GUI_UPLOAD step still needs a frontend session. To run end-to-end in background, upload the file first via a dialog report and store it in the database, then process it in the scheduled job.

See also

Comments