Skip to content

REUSE_ALV_GRID_DISPLAY

Display an internal table as an ALV grid — the classic, function-module-based approach.


Purpose

REUSE_ALV_GRID_DISPLAY is the original ALV display function module, present in virtually all existing ABAP reports. It accepts a field catalog or a DDIC structure name and an internal table, then renders a full interactive grid with sorting, filtering, totals, and layout management.

Legacy vs. modern

This FM is still perfectly functional and mandatory knowledge for maintaining legacy code. For new development, use CL_SALV_TABLE instead — it requires no PERFORM callbacks and is easier to test.


Signature (key parameters)

Parameter Type Direction Description
I_CALLBACK_PROGRAM SY-REPID Importing Report name — always pass SY-REPID
I_CALLBACK_USER_COMMAND SLIS_FORMNAME Importing Name of FORM to handle toolbar actions
I_STRUCTURE_NAME DD02L-TABNAME Importing DDIC structure — builds field catalog automatically. Only use when your internal table is typed directly from that DDIC structure.
IT_FIELDCAT SLIS_T_FIELDCAT_ALV Importing Manual field catalog. Required when using a local type.
I_DEFAULT CHAR1 Importing 'X' = show default layout button
I_SAVE CHAR1 Importing 'A' = allow saving layouts
T_OUTTAB STANDARD TABLE Tables The data — pass your internal table here

TABLES, not EXPORTING

T_OUTTAB is a TABLES parameter (pass-by-reference). Do not pass it under EXPORTING.


Choosing between I_STRUCTURE_NAME and IT_FIELDCAT

Situation Use
Your internal table is typed directly from a DDIC table/structure (e.g. TYPE STANDARD TABLE OF mara) I_STRUCTURE_NAME
Your internal table uses a local type (TYPES: BEGIN OF ...) IT_FIELDCAT

Using i_structure_name = 'MARA' when your table is a local type is wrong — ALV will try to derive columns from the DDIC structure, which won't match your fields.


Examples

Full program — local type + join + manual field catalog

Use this pattern whenever you select specific columns or join tables into a local structure.

REPORT zalv_material_list.

TYPES: BEGIN OF ty_row,
         matnr TYPE mara-matnr,
         meins TYPE mara-meins,
         maktx TYPE makt-maktx,
       END OF ty_row.

DATA: gt_data TYPE STANDARD TABLE OF ty_row,
      gt_fcat TYPE slis_t_fieldcat_alv,
      gs_fcat TYPE slis_fieldcat_alv.

START-OF-SELECTION.

  SELECT mara~matnr mara~meins makt~maktx
    FROM mara
    INNER JOIN makt ON mara~matnr = makt~matnr
    INTO CORRESPONDING FIELDS OF TABLE gt_data
    UP TO 100 ROWS
    WHERE makt~spras = sy-langu.

  " Build field catalog — one entry per column
  CLEAR gs_fcat.
  gs_fcat-fieldname = 'MATNR'.
  gs_fcat-tabname   = 'GT_DATA'.
  gs_fcat-seltext_m = 'Material'.
  gs_fcat-key       = 'X'.
  APPEND gs_fcat TO gt_fcat.

  CLEAR gs_fcat.
  gs_fcat-fieldname = 'MEINS'.
  gs_fcat-tabname   = 'GT_DATA'.
  gs_fcat-seltext_m = 'Unit'.
  APPEND gs_fcat TO gt_fcat.

  CLEAR gs_fcat.
  gs_fcat-fieldname = 'MAKTX'.
  gs_fcat-tabname   = 'GT_DATA'.
  gs_fcat-seltext_m = 'Description'.
  APPEND gs_fcat TO gt_fcat.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = sy-repid
      it_fieldcat        = gt_fcat
    TABLES
      t_outtab           = gt_data
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

Using I_STRUCTURE_NAME (DDIC-typed table)

Only valid when your internal table is typed directly from the DDIC structure you name. ALV derives the full column list from the structure — no field catalog needed.

REPORT zalv_mara_simple.

DATA gt_mara TYPE STANDARD TABLE OF mara.

START-OF-SELECTION.

  SELECT *
    FROM mara
    INTO TABLE gt_mara
    UP TO 100 ROWS.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = sy-repid
      i_structure_name   = 'MARA'
    TABLES
      t_outtab           = gt_mara
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

Handling user commands (toolbar / double-click)

REPORT zalv_with_callback.

TYPES: BEGIN OF ty_row,
         matnr TYPE mara-matnr,
         meins TYPE mara-meins,
         maktx TYPE makt-maktx,
       END OF ty_row.

DATA: gt_data TYPE STANDARD TABLE OF ty_row,
      gt_fcat TYPE slis_t_fieldcat_alv,
      gs_fcat TYPE slis_fieldcat_alv.

START-OF-SELECTION.

  SELECT mara~matnr mara~meins makt~maktx
    FROM mara
    INNER JOIN makt ON mara~matnr = makt~matnr
    INTO CORRESPONDING FIELDS OF TABLE gt_data
    UP TO 100 ROWS
    WHERE makt~spras = sy-langu.

  CLEAR gs_fcat.
  gs_fcat-fieldname = 'MATNR'. gs_fcat-tabname = 'GT_DATA'.
  gs_fcat-seltext_m = 'Material'. gs_fcat-key = 'X'.
  APPEND gs_fcat TO gt_fcat.

  CLEAR gs_fcat.
  gs_fcat-fieldname = 'MEINS'. gs_fcat-tabname = 'GT_DATA'.
  gs_fcat-seltext_m = 'Unit'.
  APPEND gs_fcat TO gt_fcat.

  CLEAR gs_fcat.
  gs_fcat-fieldname = 'MAKTX'. gs_fcat-tabname = 'GT_DATA'.
  gs_fcat-seltext_m = 'Description'.
  APPEND gs_fcat TO gt_fcat.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = sy-repid
      i_callback_user_command = 'USER_COMMAND'
      it_fieldcat             = gt_fcat
    TABLES
      t_outtab                = gt_data
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

FORM user_command USING r_ucomm     TYPE sy-ucomm
                        rs_selfield TYPE slis_selfield.
  CASE r_ucomm.
    WHEN '&IC1'.  " double-click
      READ TABLE gt_data INDEX rs_selfield-tabindex
                         ASSIGNING FIELD-SYMBOL(<ls_row>).
      IF sy-subrc = 0.
        MESSAGE |Material: { <ls_row>-matnr }| TYPE 'I'.
      ENDIF.
  ENDCASE.
ENDFORM.

Common pitfalls

  • Wrong SELECT clause order: in ABAP SQL with a JOIN, use table-qualified column names (mara~matnr, not just matnr). Clause order must be: SELECT ... FROM ... JOIN ... INTO ... UP TO ... WHERE.
  • I_STRUCTURE_NAME with a local type: if your table is a local TYPES: BEGIN OF ..., you must build IT_FIELDCAT manually. I_STRUCTURE_NAME only makes sense when the table is typed from that exact DDIC structure.
  • TABNAME in the field catalog: set it to the name of your internal table variable (e.g. 'GT_DATA'), not a DDIC table name.
  • Missing column texts: without SELTEXT_M/SELTEXT_L, ALV shows the raw field name as the column header. Always set at least SELTEXT_M.
  • I_STRUCTURE_NAME vs. IT_FIELDCAT: pass one or the other. IT_FIELDCAT takes precedence if both are supplied.

New development

Avoid REUSE_ALV_GRID_DISPLAY in new reports. Use CL_SALV_TABLE, which has no PERFORM callbacks and works cleanly in OO contexts.


See also

Comments