Field Catalog in SAP ALV

The field catalog is a table which contains information on the fields to be displayed on the ALV output.

First we need to build a field catalog before displaying any output in the ALV. We have the following three ways to build a field catalog.

The third option is used in the following cases.

  • We want to display all the fields from the DDIC structure but want to modify certain attributes like descriptions etc.
  • We want to display most of the fields i.e. we want to hide certain fields.
  • Add new fields.

To generate a field catalog semi-automatically:

  • Declare an internal table of type SLIS_T_FIELDCAT_ALV.
  • Call function module REUSE_ALV_FIELDCATALOG_MERGE and pass the DDIC structure of the output table and the internal table for the field catalog. The function module generates the field catalog and fills the internal table accordingly.
  • Read the rows you want to change, and adapt the fields accordingly. If your output table contains more fields than are stored in the Data Dictionary, you must append one row for each new field to the field catalog.

Example Program

TYPE-POOLS: slis.  " SLIS contains all the ALV data types

*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*

DATA: BEGIN OF wa_sbook,
      status(4).
      INCLUDE STRUCTURE sbook.
DATA: END OF wa_sbook.
DATA: it_sbook     TYPE TABLE OF sbook.
DATA: it_fieldcat  TYPE slis_t_fieldcat_alv,
      wa_fieldcat  TYPE slis_fieldcat_alv.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.

*Fetch data from the database
  SELECT * UP TO 10 ROWS FROM sbook INTO TABLE it_sbook.

*Build field catalog
  wa_fieldcat-fieldname  = 'STATUS'.    " Fieldname in the data table
  wa_fieldcat-seltext_m  = 'Status'.    " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.

*Merge Field Catalog
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
   EXPORTING
     i_structure_name             = 'SBOOK'
   CHANGING
      ct_fieldcat                 = it_fieldcat
   EXCEPTIONS
     inconsistent_interface       = 1
     program_error                = 2
     OTHERS                       = 3.

*Pass data and field catalog to ALV function module to display ALV list
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      it_fieldcat   = it_fieldcat
    TABLES
      t_outtab      = it_sbook
    EXCEPTIONS
      program_error = 1
      OTHERS        = 2.

Output

generate-field-catalog

Status column is added to the field catalog along all the fields of structure SBOOK.


7 Comments

  1. There is probably little mistake (because ALV fills first “Status” line). Repair: add OCCURS 0 to line: DATA: BEGIN OF wa_sbook, delete/comment line: DATA: it_sbook TYPE TABLE OF sbook.

  2. how can i give data to my tables(personal info,address,communication details) with help of sceen painter and insert statements.

  3. Hi,

    Below is the correct code to declare it_sbook.

    DATA : IT_SBOOK like TABLE OF wa_sbook .

Comments are closed.