ALV Blocked List Display

+ -
Requirement: Develop a blocked list ALV to display list of materials for a material type and also display material descriptions in another grid.

Analysis: For this requirement, we need to add one input parameter for material type, we need to get materials from MARA, and from MAKT and display in two list ALV`s using ALV blocked display.

Blocked list ALV is used to display multiple ALV`s on the same screen with blocks.

List of Function Modules used for blocked list ALV

  • REUSE_ALV_BLOCK_LIST_INIT
  • REUSE_ALV_BLOCK_LIST_APPEND
  • REUSE_ALV_BLOCK_LIST_DISPLAY

REUSE_ALV_BLOCK_LIST_INIT: is used to initialize blocked list ALV.

REUSE_ALV_BLOCK_LIST_APPEND: is used to add blocked list ALV's(we can add multiple).

REUSE_ALV_BLOCK_LIST_DISPLAY: is used to display blocked list ALV.

Follow the below steps to create blocked list ALV

Create a program in SE38, add data declarations

Create a report program in SE38 and add data declarations for MARA table, MAKT table. Add an input parameter for material type input.

ALV blocked list display

TYPES: BEGIN OF TY_MARA, "user defined type for mara
        MATNR TYPE MARA-MATNR,
        MTART TYPE MARA-MTART,
        MBRSH TYPE MARA-MBRSH,
        MATKL TYPE MARA-MATKL,
        MEINS TYPE MARA-MEINS,
      END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA, "mara internal table
       WA_MARA TYPE TY_MARA. "mara work area
TYPES: BEGIN OF TY_MAKT, "user defined type for MAKT
        MATNR TYPE MAKT-MATNR,
        SPRAS TYPE MAKT-SPRAS,
        MAKTX TYPE MAKT-MAKTX,
      END OF TY_MAKT.
DATA : IT_MAKT TYPE TABLE OF TY_MAKT, "makt internal table
       WA_MAKT TYPE TY_MAKT.
PARAMETERS : P_MTART TYPE MARA-MTART. "material type input

Build Field catalog for MARA and MAKT tables

Build field catalog for MARA and MAKT tables.
DATA : T_FCAT TYPE SLIS_T_FIELDCAT_ALV. "field catalog for MARA table
DATA : W_FCAT LIKE LINE OF T_FCAT.
DATA : T_FCAT_MAKT TYPE SLIS_T_FIELDCAT_ALV. "makt field catalog
DATA : W_FCAT_MAKT LIKE LINE OF T_FCAT_MAKT.

***build fcat for MARA
  W_FCAT-COL_POS       = '1'. "coloum position
  W_FCAT-FIELDNAME     = 'MATNR'. "column name
  W_FCAT-TABNAME       = 'IT_MARA'. "table
  W_FCAT-REF_TABNAME   = 'MARA'. "table
  W_FCAT-REF_FIELDNAME = 'MATNR'. "referance field, it will show descriptions automatically
  APPEND W_FCAT TO T_FCAT.
  CLEAR W_FCAT.

  W_FCAT-COL_POS       = '2'.
  W_FCAT-FIELDNAME     = 'MTART'.
  W_FCAT-TABNAME       = 'IT_MARA'.
  W_FCAT-REF_TABNAME   = 'MARA'.
  W_FCAT-REF_FIELDNAME = 'MTART'.
  APPEND W_FCAT TO T_FCAT.
  CLEAR W_FCAT.

  W_FCAT-COL_POS       = '3'.
  W_FCAT-FIELDNAME     = 'MBRSH'.
  W_FCAT-TABNAME       = 'IT_MARA'.
  W_FCAT-REF_TABNAME   = 'MARA'.
  W_FCAT-REF_FIELDNAME = 'MBRSH'.
  APPEND W_FCAT TO T_FCAT.
  CLEAR W_FCAT.

  W_FCAT-COL_POS       = '4'.
  W_FCAT-FIELDNAME     = 'MATKL'.
  W_FCAT-TABNAME       = 'IT_MARA'.
  W_FCAT-REF_TABNAME   = 'MARA'.
  W_FCAT-REF_FIELDNAME = 'MATKL'.
  APPEND W_FCAT TO T_FCAT.
  CLEAR W_FCAT.

  W_FCAT-COL_POS       = '5'.
  W_FCAT-FIELDNAME     = 'MEINS'.
  W_FCAT-TABNAME       = 'IT_MARA'.
  W_FCAT-REF_TABNAME   = 'MARA'.
  W_FCAT-REF_FIELDNAME = 'MEINS'.
  APPEND W_FCAT TO T_FCAT.
  CLEAR W_FCAT.

***build fcat for MAKT
  W_FCAT_MAKT-COL_POS       = '1'.
  W_FCAT_MAKT-FIELDNAME     = 'MATNR'.
  W_FCAT_MAKT-TABNAME       = 'IT_MAKT'.
  W_FCAT_MAKT-REF_TABNAME   = 'MAKT'.
  W_FCAT_MAKT-REF_FIELDNAME = 'MATNR'.
  APPEND W_FCAT_MAKT TO T_FCAT_MAKT.
  CLEAR W_FCAT_MAKT.
  W_FCAT_MAKT-COL_POS       = '2'.
  W_FCAT_MAKT-FIELDNAME     = 'SPRAS'.
  W_FCAT_MAKT-TABNAME       = 'IT_MAKT'.
  W_FCAT_MAKT-REF_TABNAME   = 'MAKT'.
  W_FCAT_MAKT-REF_FIELDNAME = 'SPRAS'.
  APPEND W_FCAT_MAKT TO T_FCAT_MAKT.
  CLEAR W_FCAT_MAKT.
  W_FCAT_MAKT-COL_POS       = '3'.
  W_FCAT_MAKT-FIELDNAME     = 'MAKTX'.
  W_FCAT_MAKT-TABNAME       = 'IT_MAKT'.
  W_FCAT_MAKT-REF_TABNAME   = 'MAKT'.
  W_FCAT_MAKT-REF_FIELDNAME = 'MAKTX'.
  APPEND W_FCAT_MAKT TO T_FCAT_MAKT.
  CLEAR W_FCAT_MAKT.

Initialize Blocked List ALV

Initialize blocked list ALV using Function Module REUSE_ALV_BLOCK_LIST_INIT.
*  * init
  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT' "initialize Block List ALV
    EXPORTING
      I_CALLBACK_PROGRAM = SY-REPID.

Add lists to blocked list ALV

Add all ALV lists with field catalogs
  DATA S_EVENTS TYPE SLIS_T_EVENT.
  DATA S_LAYOUT TYPE SLIS_LAYOUT_ALV.
  S_LAYOUT-ZEBRA = 'X'. "display zebra colours(alternate colours on rows)
**Add MARA list
  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND' "append ALV lists
    EXPORTING
      IS_LAYOUT   = S_LAYOUT "set layout
      IT_FIELDCAT = T_FCAT "set field catalog
      I_TABNAME   = 'IT_MARA' "table
      IT_EVENTS   = S_EVENTS "events
*     IT_SORT     =
*     I_TEXT      = ' '
    TABLES
      T_OUTTAB    = IT_MARA "out put table
*   EXCEPTIONS
*     PROGRAM_ERROR                    = 1
*     MAXIMUM_OF_APPENDS_REACHED       = 2
*     OTHERS      = 3
    .
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.
**add MAKT list
  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND' "append ALV lists
    EXPORTING
      IS_LAYOUT   = S_LAYOUT "set layout
      IT_FIELDCAT = T_FCAT_MAKT "set field catalog
      I_TABNAME   = 'IT_MAKT' "table
      IT_EVENTS   = S_EVENTS "events
*     IT_SORT     =
*     I_TEXT      = ' '
    TABLES
      T_OUTTAB    = IT_MAKT "out put table
*   EXCEPTIONS
*     PROGRAM_ERROR                    = 1
*     MAXIMUM_OF_APPENDS_REACHED       = 2
*     OTHERS      = 3
    .
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.

Display Blocked List

Display blocked list ALV using Function module REUSE_ALV_BLOCK_LIST_DISPLAY.
  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY' . "display blocked list

Full and Final Code to display blocked list ALV

REPORT ZSAPN_ALV_BLOCKEDLIST.
TYPES: BEGIN OF TY_MARA, "user defined type for mara
        MATNR TYPE MARA-MATNR,
        MTART TYPE MARA-MTART,
        MBRSH TYPE MARA-MBRSH,
        MATKL TYPE MARA-MATKL,
        MEINS TYPE MARA-MEINS,
      END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA, "mara internal table
       WA_MARA TYPE TY_MARA. "mara work area
DATA : T_FCAT TYPE SLIS_T_FIELDCAT_ALV. "field catalog for MARA table
DATA : W_FCAT LIKE LINE OF T_FCAT.

TYPES: BEGIN OF TY_MAKT, "user defined type for MAKT
        MATNR TYPE MAKT-MATNR,
        SPRAS TYPE MAKT-SPRAS,
        MAKTX TYPE MAKT-MAKTX,
      END OF TY_MAKT.
DATA : IT_MAKT TYPE TABLE OF TY_MAKT, "makt internal table
       WA_MAKT TYPE TY_MAKT.
DATA : T_FCAT_MAKT TYPE SLIS_T_FIELDCAT_ALV. "makt field catalog
DATA : W_FCAT_MAKT LIKE LINE OF T_FCAT_MAKT.
PARAMETERS : P_MTART TYPE MARA-MTART. "material type input

START-OF-SELECTION.

  SELECT MATNR
         MTART
         MBRSH
         MATKL
         MEINS FROM MARA "get MARA data
    INTO TABLE IT_MARA UP TO 10 ROWS WHERE MTART = P_MTART.
  IF NOT IT_MARA IS INITIAL .
    SELECT MATNR
           SPRAS
           MAKTX FROM MAKT INTO TABLE IT_MAKT "get makt data
      FOR ALL ENTRIES IN IT_MARA WHERE MATNR = IT_MARA-MATNR.
  ENDIF.
***build fcat for MARA
  W_FCAT-COL_POS       = '1'. "coloum position
  W_FCAT-FIELDNAME     = 'MATNR'. "column name
  W_FCAT-TABNAME       = 'IT_MARA'. "table
  W_FCAT-REF_TABNAME   = 'MARA'. "table
  W_FCAT-REF_FIELDNAME = 'MATNR'. "referance field, it will show descriptions automatically
  APPEND W_FCAT TO T_FCAT.
  CLEAR W_FCAT.

  W_FCAT-COL_POS       = '2'.
  W_FCAT-FIELDNAME     = 'MTART'.
  W_FCAT-TABNAME       = 'IT_MARA'.
  W_FCAT-REF_TABNAME   = 'MARA'.
  W_FCAT-REF_FIELDNAME = 'MTART'.
  APPEND W_FCAT TO T_FCAT.
  CLEAR W_FCAT.

  W_FCAT-COL_POS       = '3'.
  W_FCAT-FIELDNAME     = 'MBRSH'.
  W_FCAT-TABNAME       = 'IT_MARA'.
  W_FCAT-REF_TABNAME   = 'MARA'.
  W_FCAT-REF_FIELDNAME = 'MBRSH'.
  APPEND W_FCAT TO T_FCAT.
  CLEAR W_FCAT.

  W_FCAT-COL_POS       = '4'.
  W_FCAT-FIELDNAME     = 'MATKL'.
  W_FCAT-TABNAME       = 'IT_MARA'.
  W_FCAT-REF_TABNAME   = 'MARA'.
  W_FCAT-REF_FIELDNAME = 'MATKL'.
  APPEND W_FCAT TO T_FCAT.
  CLEAR W_FCAT.

  W_FCAT-COL_POS       = '5'.
  W_FCAT-FIELDNAME     = 'MEINS'.
  W_FCAT-TABNAME       = 'IT_MARA'.
  W_FCAT-REF_TABNAME   = 'MARA'.
  W_FCAT-REF_FIELDNAME = 'MEINS'.
  APPEND W_FCAT TO T_FCAT.
  CLEAR W_FCAT.

***build fcat for MAKT
  W_FCAT_MAKT-COL_POS       = '1'.
  W_FCAT_MAKT-FIELDNAME     = 'MATNR'.
  W_FCAT_MAKT-TABNAME       = 'IT_MAKT'.
  W_FCAT_MAKT-REF_TABNAME   = 'MAKT'.
  W_FCAT_MAKT-REF_FIELDNAME = 'MATNR'.
  APPEND W_FCAT_MAKT TO T_FCAT_MAKT.
  CLEAR W_FCAT_MAKT.
  W_FCAT_MAKT-COL_POS       = '2'.
  W_FCAT_MAKT-FIELDNAME     = 'SPRAS'.
  W_FCAT_MAKT-TABNAME       = 'IT_MAKT'.
  W_FCAT_MAKT-REF_TABNAME   = 'MAKT'.
  W_FCAT_MAKT-REF_FIELDNAME = 'SPRAS'.
  APPEND W_FCAT_MAKT TO T_FCAT_MAKT.
  CLEAR W_FCAT_MAKT.
  W_FCAT_MAKT-COL_POS       = '3'.
  W_FCAT_MAKT-FIELDNAME     = 'MAKTX'.
  W_FCAT_MAKT-TABNAME       = 'IT_MAKT'.
  W_FCAT_MAKT-REF_TABNAME   = 'MAKT'.
  W_FCAT_MAKT-REF_FIELDNAME = 'MAKTX'.
  APPEND W_FCAT_MAKT TO T_FCAT_MAKT.
  CLEAR W_FCAT_MAKT.
*  * init
  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT' "initialize Block List ALV
    EXPORTING
      I_CALLBACK_PROGRAM = SY-REPID.

  DATA S_EVENTS TYPE SLIS_T_EVENT.
  DATA S_LAYOUT TYPE SLIS_LAYOUT_ALV.
  S_LAYOUT-ZEBRA = 'X'.
  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND' "append ALV lists
    EXPORTING
      IS_LAYOUT   = S_LAYOUT "set layout
      IT_FIELDCAT = T_FCAT "set field catalog
      I_TABNAME   = 'IT_MARA' "table
      IT_EVENTS   = S_EVENTS "events
*     IT_SORT     =
*     I_TEXT      = ' '
    TABLES
      T_OUTTAB    = IT_MARA "out put table
*   EXCEPTIONS
*     PROGRAM_ERROR                    = 1
*     MAXIMUM_OF_APPENDS_REACHED       = 2
*     OTHERS      = 3
    .
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND' "append ALV lists
    EXPORTING
      IS_LAYOUT   = S_LAYOUT "set layout
      IT_FIELDCAT = T_FCAT_MAKT "set field catalog
      I_TABNAME   = 'IT_MAKT' "table
      IT_EVENTS   = S_EVENTS "events
*     IT_SORT     =
*     I_TEXT      = ' '
    TABLES
      T_OUTTAB    = IT_MAKT "out put table
*   EXCEPTIONS
*     PROGRAM_ERROR                    = 1
*     MAXIMUM_OF_APPENDS_REACHED       = 2
*     OTHERS      = 3
    .
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.
  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY' . "display blocked list

ALV blocked list Display

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 26 People out of 26 think this lesson helpful


    Lesson Navigation

    ←Previous Chapter
    Next Chapter →