-
ALV (ABAP List Viewer) is used to display reports in a structured, interactive way.
-
A Block List means you display multiple ALV lists one below another in the same output.
-
Example: You want to show
MARA
(Material Master general data) and then, beneath it,MARC
(Plant-specific data) in the same report. -
This is done using the
REUSE_ALV_BLOCK_LIST_*
function modules.
Steps to Create ALV Block List
-
Initialize block list →
REUSE_ALV_BLOCK_LIST_INIT
. -
Add multiple reports (MARA, MARC, etc.) →
REUSE_ALV_BLOCK_LIST_APPEND
. -
Display →
REUSE_ALV_BLOCK_LIST_DISPLAY
.
*&---------------------------------------------------------------------*
*& Report ZTEST_PROGRAM_2
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ztest_program_2.
TYPE-POOLS: slis.
DATA: it_mara TYPE TABLE OF mara,
it_marc TYPE TABLE OF marc.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv.
DATA : lt_events TYPE slis_t_event.
"--- Main processing
START-OF-SELECTION.
"--- Fetch Data
SELECT * FROM mara UP TO 20 ROWS INTO TABLE it_mara.
SELECT * FROM marc UP TO 20 ROWS INTO TABLE it_marc.
"Initialize ALV Block List
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
i_callback_program = sy-repid.
"Prepare field catalog for MARA
PERFORM build_fieldcat USING 'MARA' it_fieldcat.
"Append MARA list
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = VALUE slis_layout_alv( colwidth_optimize = 'X' )
it_fieldcat = it_fieldcat
it_events = lt_events
i_tabname = 'MARA'
i_text = 'Material Master - MARA'
TABLES
t_outtab = it_mara.
CLEAR it_fieldcat.
"Prepare field catalog for MARC
PERFORM build_fieldcat USING 'MARC' it_fieldcat.
"Append MARC list
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = VALUE slis_layout_alv( colwidth_optimize = 'X' )
it_fieldcat = it_fieldcat
i_tabname = 'MARC'
i_text = 'Plant Data - MARC'
it_events = lt_events
TABLES
t_outtab = it_marc.
"Display ALV Block List
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'.
"--- Create field catalog helper form
FORM build_fieldcat USING p_table TYPE string
p_fieldcat TYPE slis_t_fieldcat_alv.
DATA ls_fcat TYPE slis_fieldcat_alv.
CLEAR ls_fcat.
IF p_table = 'MARA'.
ls_fcat-fieldname = 'MATNR'. ls_fcat-seltext_m = 'Material'. APPEND ls_fcat TO p_fieldcat.
ls_fcat-fieldname = 'MTART'. ls_fcat-seltext_m = 'Material Type'. APPEND ls_fcat TO p_fieldcat.
ls_fcat-fieldname = 'MBRSH'. ls_fcat-seltext_m = 'Industry'. APPEND ls_fcat TO p_fieldcat.
ELSEIF p_table = 'MARC'.
ls_fcat-fieldname = 'MATNR'. ls_fcat-seltext_m = 'Material'. APPEND ls_fcat TO p_fieldcat.
ls_fcat-fieldname = 'WERKS'. ls_fcat-seltext_m = 'Plant'. APPEND ls_fcat TO p_fieldcat.
ls_fcat-fieldname = 'DISMM'. ls_fcat-seltext_m = 'MRP Type'. APPEND ls_fcat TO p_fieldcat.
ENDIF.
ENDFORM.
Output: