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

Parameter Direction Type Notes
I_LINE_HEADER IMPORTING CHAR1 Pass 'X' to skip the first row (header row).
I_TAB_RAW_DATA IMPORTING TRUXS_T_TEXT_DATA Raw binary content from GUI_UPLOAD with FILETYPE='BIN'.
I_FILENAME IMPORTING STRING Original filename — used for format detection (.xls vs .xlsx).
E_INTERNAL_TABLE EXPORTING STANDARD TABLE Output — one row per Excel row, typed to your target structure.

Example — full two-step upload flow

REPORT z_xls_server_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_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.

START-OF-SELECTION.

  " Step 1 — move raw bytes from frontend to server
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename   = p_file
      filetype   = 'BIN'
    TABLES
      data_tab   = lt_raw
    EXCEPTIONS
      OTHERS     = 1.

  IF sy-subrc <> 0.
    MESSAGE 'File upload failed.' TYPE 'E'.
  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'.
  ENDIF.

  " Step 3 — process results
  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. 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.
  • Merged cells and formulas: merged cells are returned as empty for all but the top-left cell. Formula cells return an empty value (the formula result is not evaluated). 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. Always align the spreadsheet layout with your type definition.
  • BIN output from GUI_UPLOAD is TRUXS_T_TEXT_DATA: declare lt_raw as that type, not a generic string table. A type mismatch causes a short dump at the CALL FUNCTION statement.
  • 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