Skip to content

ALSM_EXCEL_TO_INTERNAL_TABLE

Upload an Excel file from the frontend and get its cells in an internal table.

Purpose

Reads an .xls / .xlsx file selected on the user's PC and returns all cell values as a flat internal table — one row per cell, with row number, column number, and string value. It's the standard, dependency-free way to handle Excel uploads in classical ABAP (no SAP GUI scripting, no third-party tools).

Works for .xls and .xlsx

Despite the name containing "XLS", the FM handles both formats. Large .xlsx files (> ~5 MB) can be slow — for high-volume uploads prefer TEXT_CONVERT_XLS_TO_SAP or a custom file-based approach.

Signature

Parameter Direction Type Notes
FILENAME IMPORTING RLGRAP-FILENAME Full path on the frontend machine.
I_BEGIN_COL IMPORTING I First column to read (default: 1).
I_BEGIN_ROW IMPORTING I First row to read — set to 2 to skip the header.
I_END_COL IMPORTING I Last column to read.
I_END_ROW IMPORTING I Last row to read. 9999 is a safe max.
INTERN TABLES ALSMEX_TABLINE Output: one row per cell — fields ROW, COL, VALUE.

Structure of ALSMEX_TABLINE:

Field Type Description
ROW INT2 Row number (1-based)
COL INT2 Column number (1-based)
VALUE CHAR50 Cell value as string (max 50 chars)

Example — upload and process a material list

REPORT z_excel_upload.

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

DATA: lv_file    TYPE rlgrap-filename,
      lt_intern  TYPE STANDARD TABLE OF alsmex_tabline,
      lt_mat     TYPE STANDARD TABLE OF ty_material,
      ls_mat     TYPE ty_material.

" 1) Let the user pick a file
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.

PARAMETERS p_file TYPE rlgrap-filename.

START-OF-SELECTION.

  lv_file = p_file.

  " 2) Load the Excel
  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename     = lv_file
      i_begin_col  = 1
      i_begin_row  = 2     " skip header row
      i_end_col    = 3
      i_end_row    = 9999
    TABLES
      intern       = lt_intern
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 2
      OTHERS                  = 3.

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

  " 3) Pivot flat cell table into a structured table
  LOOP AT lt_intern INTO DATA(ls_cell).
    CASE ls_cell-col.
      WHEN 1. ls_mat-matnr = ls_cell-value.
      WHEN 2. ls_mat-maktx = ls_cell-value.
      WHEN 3.
        ls_mat-meins = ls_cell-value.
        APPEND ls_mat TO lt_mat.
        CLEAR ls_mat.
    ENDCASE.
  ENDLOOP.

  " 4) Process lt_mat ...
  LOOP AT lt_mat INTO ls_mat.
    WRITE: / ls_mat-matnr, ls_mat-maktx, ls_mat-meins.
  ENDLOOP.

Common pitfalls

Value truncation at 50 characters

ALSMEX_TABLINE-VALUE is CHAR50. Any cell value longer than 50 characters is silently cut. For longer text fields, use TEXT_CONVERT_XLS_TO_SAP or read the file as CSV.

Frontend path, not server path

FILENAME must be the path on the user's desktop (e.g. C:\Users\...). If your program runs in background or on the server, this FM won't work — use GUI_UPLOAD + parsing instead.

  • OLE dependency: the FM opens the file via OLE automation — Microsoft Excel (or a compatible viewer) must be installed on the frontend. If it isn't, UPLOAD_OLE fires.
  • Row/column index: both start at 1, not 0. I_BEGIN_ROW = 2 skips exactly one header row.
  • Empty cells: completely empty cells are not returned in INTERN. Your pivot loop must handle missing columns gracefully.
  • Performance on large files: OLE is slow. Files with > 5,000 rows take noticeable time. Set I_END_ROW to a reasonable cap and warn the user.

Alternatives

Scenario Better option
No Excel on frontend Upload as CSV via GUI_UPLOAD, parse manually
Large files TEXT_CONVERT_XLS_TO_SAP (server-side conversion)
Web Dynpro / Fiori CL_FDT_XL_SPREADSHEET or BTP-based approach
Values > 50 chars Use CSV + GUI_UPLOAD

See also

Comments