ALV Report with Field Catalog SAP ABAP

What is a field catalog in SAP ALV reports? Using field catalog and field catalog merge in SAP ALV reports

+ -

Field Catalog

Field catalog is an internal table which is used to pass a list of fields to display in ALV report, we can set different properties to fields which are going to display in ALV.

Type Group

It is a data dictionary object which contains all the reusable user-defined types.

Example for a type group is SLIS, which contains all the user-defined types for developing ALV reports.

TYPE-POOLS is a keyword which is used to assign the type-group to a ALV report .

Syntax : 
TYPE-POOLS SLIS . "TO USE FIELD CATALOG WE HAVE TO INCLUDE SLIS TYPE-POOLS
DATA : <IT_FCAT> TYPE SLIS_T_FIELDCAT_ALV . "INTERNAL TABLE FOR FIELD CATALOG
DATA : <WA_FCAT> TYPE SLIS_FIELDCAT_ALV  . " WORK AREA FOR FIELD CATLOG

Options/properties of field catalog.

  WA_FCAT-COL_POS = '1' . "Specify position of a field
  WA_FCAT-FIELDNAME = 'MATNR' . "Specify field name
  WA_FCAT-TABNAME = 'IT_MARA' . "Specify internal table name
  WA_FCAT-SELTEXT_M = 'MATERIALNO' . "Specify text to display column header
  WA_FCAT-KEY = 'X' . "Specify if it is a key field
  APPEND WA_FCAT TO IT_FCAT . "Append to field catalog internal table

Useful resource Using append in SAP ABAP and also Using Clear in SAP ABAP

Requirement: Develop an ALV report to display Material no (MATNR), Material type (MTART), Industry Sector (MBRSH) and Basic Unit Of measure (MEINS) for a range of material input (Select-Options).

To develop above report, we have to use field catalog (because we have to display four fields only from MARA) and we have to pass field catalog parameter to Function Module REUSE_ALV_GIRD_DISPLAY.

REPORT ZSAPN_ALV_FCAT.
TABLES : MARA.
TYPE-POOLS SLIS .

TYPES : BEGIN OF TY_MARA,  "User defined internal table type
        MATNR TYPE MARA-MATNR,
        MTART TYPE MARA-MTART,
        MBRSH TYPE MARA-MBRSH,
        MEINS TYPE MARA-MEINS,
      END OF TY_MARA.

DATA : IT_MARA TYPE TABLE OF TY_MARA .
DATA : WA_MARA TYPE TY_MARA .

DATA : IT_FCAT TYPE SLIS_T_FIELDCAT_ALV .
DATA : WA_FCAT LIKE LINE OF IT_FCAT .
SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.

START-OF-SELECTION .
  PERFORM GET_DATA .
  PERFORM CREATE_FCAT.

END-OF-SELECTION .
  PERFORM DISP_ALV .

*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_DATA .
  SELECT MATNR MTART MBRSH MEINS FROM MARA
      INTO TABLE IT_MARA
      WHERE MATNR IN S_MATNR.
  .
ENDFORM.                    " GET_DATA
*&---------------------------------------------------------------------*
*&      Form  DISP_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISP_ALV .
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM = SY-REPID
      IT_FIELDCAT        = IT_FCAT "PASS FIELD CATALOG TO ALV
    TABLES
      T_OUTTAB           = IT_MARA.


ENDFORM.                    " DISP_ALV
*&---------------------------------------------------------------------*
*&      Form  CREATE_FCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM CREATE_FCAT .
  WA_FCAT-COL_POS = '1' .
  WA_FCAT-FIELDNAME = 'MATNR' .
  WA_FCAT-TABNAME = 'IT_MARA' .
  WA_FCAT-SELTEXT_M = 'MATERIALNO' .
  WA_FCAT-KEY = 'X' .
  APPEND WA_FCAT TO IT_FCAT .
  CLEAR WA_FCAT .

  WA_FCAT-COL_POS = '2' .
  WA_FCAT-FIELDNAME = 'MTART' .
  WA_FCAT-TABNAME = 'IT_MARA' .
  WA_FCAT-SELTEXT_M = 'MATERIALTYPE' .
*  WA_FCAT-NO_OUT = 'X' .
  WA_FCAT-HOTSPOT = 'X' .
  APPEND WA_FCAT TO IT_FCAT .
  CLEAR WA_FCAT .

  WA_FCAT-COL_POS = '3' .
  WA_FCAT-FIELDNAME = 'MBRSH' .
  WA_FCAT-REF_FIELDNAME = 'MBRSH' .
  WA_FCAT-REF_TABNAME = 'MARA' .
*  WA_FCAT-TABNAME = 'IT_MARA' .
*  WA_FCAT-SELTEXT_M = 'INDSECTOR' .
*  WA_FCAT-EDIT = 'X' .
  APPEND WA_FCAT TO IT_FCAT .
  CLEAR WA_FCAT .

  WA_FCAT-COL_POS = '4' .
  WA_FCAT-FIELDNAME = 'MEINS' .
  WA_FCAT-TABNAME = 'IT_MARA' .
  WA_FCAT-SELTEXT_M = 'MAT.UNITS' .
  WA_FCAT-EMPHASIZE = 'C610'.
  APPEND WA_FCAT TO IT_FCAT .
  CLEAR WA_FCAT .

ENDFORM.                    " CREATE_FCAT

Field Catalog Merge Not Recommended
Field Catalog can be generated in two ways, one is manual with field catalog internal table and another one is with automatic field catalog generation...like below one, but this one uses old syntax, this one is obsolete and is not recommended.
*&---------------------------------------------------------------------*
*& Report  ZALV_WITH_FCAT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZALV_WITH_FCAT_MERGE.

TYPE-POOLS SLIS .

DATA : BEGIN OF I_MARA OCCURS 0,
        MATNR LIKE MARA-MATNR,
        MTART LIKE MARA-MTART,
        MBRSH LIKE MARA-MBRSH,
        MEINS LIKE MARA-MEINS,
      END OF I_MARA.



DATA : I_FCAT TYPE SLIS_T_FIELDCAT_ALV .
DATA : WA_FCAT LIKE LINE OF I_FCAT .

START-OF-SELECTION .
  PERFORM GET_DATA .
  PERFORM CREATE_FCAT_MERGE .

END-OF-SELECTION .
  PERFORM DISP_ALV .

*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_DATA .
  SELECT * FROM MARA
      INTO CORRESPONDING FIELDS OF TABLE I_MARA
       .
ENDFORM.                    " GET_DATA
*&---------------------------------------------------------------------*
*&      Form  DISP_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISP_ALV .
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM = SY-REPID
      IT_FIELDCAT        = I_FCAT
    TABLES
      T_OUTTAB           = I_MARA.


ENDFORM.                    " DISP_ALV
*&---------------------------------------------------------------------*
*&      Form  CREATE_FCAT_MERGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM CREATE_FCAT_MERGE .
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      I_PROGRAM_NAME     = SY-REPID
      I_INTERNAL_TABNAME = 'I_MARA'
      I_INCLNAME         = SY-REPID
    CHANGING
      CT_FIELDCAT        = I_FCAT.
ENDFORM.                    " CREATE_FCAT_MERGE

Learner Questions


No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question

    Was this lesson helpful to you? Yes No 61 People out of 64 think this lesson helpful


    Lesson Navigation

    ←Previous Chapter
    Next Chapter →