REPORT z_alv_block_list.
* Type-pools
TYPE-POOLS: slis.
* Data declarations.
DATA: BEGIN OF t_vbak OCCURS 0,
vbeln TYPE vbeln,
bstnk TYPE vbak-bstnk,
erdat TYPE vbak-erdat,
kunnr TYPE vbak-kunnr,
END OF t_vbak.
DATA: BEGIN OF t_vbap OCCURS 0,
vbeln TYPE vbeln,
matnr TYPE vbap-matnr,
netpr TYPE vbap-netpr,
waerk TYPE vbap-waerk,
kwmeng TYPE vbap-kwmeng,
meins TYPE vbap-meins,
END OF t_vbap.
DATA: t_fieldcatalog1 TYPE slis_t_fieldcat_alv.
DATA: t_fieldcatalog2 TYPE slis_t_fieldcat_alv.
DATA: v_repid TYPE syrepid.
DATA: s_layout TYPE slis_layout_alv.
DATA: v_tabname TYPE slis_tabname.
DATA: t_events TYPE slis_t_event.
* start-of-selection event.
START-OF-SELECTION.
v_repid = sy-repid.
* Get the fieldcatalog for the first block
PERFORM get_fieldcat1 CHANGING t_fieldcatalog1.
* Get the fieldcatalog for the second block
PERFORM get_fieldcat2 CHANGING t_fieldcatalog2.
* Get the data for the first block
SELECT vbeln bstnk erdat kunnr UP TO 10 ROWS
INTO TABLE t_vbak
FROM vbak WHERE vbeln > '0060000100'.
* Get the data for the second block
SELECT vbeln matnr netpr waerk kwmeng meins UP TO 10 ROWS
INTO TABLE t_vbap
FROM vbap WHERE vbeln > '0060000100'.
* init
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
i_callback_program = v_repid.
* First block
v_tabname = 'ITAB1'.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = s_layout
it_fieldcat = t_fieldcatalog1
i_tabname = v_tabname
it_events = t_events
TABLES
t_outtab = t_vbak.
* Second block
v_tabname = 'ITAB2'.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = s_layout
it_fieldcat = t_fieldcatalog2
i_tabname = v_tabname
it_events = t_events
TABLES
t_outtab = t_vbap.
*Display
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
.
*---------------------------------------------------------------------*
* FORM GET_FIELDCAT1 *
*---------------------------------------------------------------------*
* Get the field catalog for the first block *
*---------------------------------------------------------------------*
FORM get_fieldcat1 CHANGING lt_fieldcatalog TYPE slis_t_fieldcat_alv.
DATA: s_fieldcatalog TYPE slis_fieldcat_alv.
* Order number
s_fieldcatalog-col_pos = '1'.
s_fieldcatalog-fieldname = 'VBELN'.
s_fieldcatalog-tabname = 'T_VBAK'.
s_fieldcatalog-ref_tabname = 'VBAK'.
s_fieldcatalog-ref_fieldname = 'VBELN'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
* Customer purchase order.
s_fieldcatalog-col_pos = '2'.
s_fieldcatalog-fieldname = 'BSTNK'.
s_fieldcatalog-tabname = 'T_VBAK'.
s_fieldcatalog-ref_tabname = 'VBAK'.
s_fieldcatalog-ref_fieldname = 'BSTNK'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
* Creation date.
s_fieldcatalog-col_pos = '3'.
s_fieldcatalog-fieldname = 'ERDAT'.
s_fieldcatalog-tabname = 'T_VBAK'.
s_fieldcatalog-ref_tabname = 'VBAK'.
s_fieldcatalog-ref_fieldname = 'ERDAT'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
* Customer
s_fieldcatalog-col_pos = '4'.
s_fieldcatalog-fieldname = 'KUNNR'.
s_fieldcatalog-tabname = 'T_VBAK'.
s_fieldcatalog-ref_tabname = 'VBAK'.
s_fieldcatalog-ref_fieldname = 'KUNNR'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
ENDFORM.
*---------------------------------------------------------------------*
* FORM GET_FIELDCAT2 *
*---------------------------------------------------------------------*
* Get the field catalog for the second block *
*---------------------------------------------------------------------*
FORM get_fieldcat2 CHANGING lt_fieldcatalog TYPE slis_t_fieldcat_alv.
DATA: s_fieldcatalog TYPE slis_fieldcat_alv.
* Order number
s_fieldcatalog-col_pos = '1'.
s_fieldcatalog-fieldname = 'VBELN'.
s_fieldcatalog-tabname = 'T_VBAP'.
s_fieldcatalog-ref_tabname = 'VBAP'.
s_fieldcatalog-ref_fieldname = 'VBELN'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
* Material number
s_fieldcatalog-col_pos = '2'.
s_fieldcatalog-fieldname = 'MATNR'.
s_fieldcatalog-tabname = 'T_VBAP'.
s_fieldcatalog-ref_tabname = 'VBAP'.
s_fieldcatalog-ref_fieldname = 'MATNR'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
* Net price
s_fieldcatalog-col_pos = '3'.
s_fieldcatalog-fieldname = 'NETPR'.
s_fieldcatalog-tabname = 'T_VBAP'.
s_fieldcatalog-ref_tabname = 'VBAP'.
s_fieldcatalog-ref_fieldname = 'NETPR'.
s_fieldcatalog-cfieldname = 'WAERK'.
s_fieldcatalog-ctabname = 'T_VBAP'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
* Currency.
s_fieldcatalog-col_pos = '4'.
s_fieldcatalog-fieldname = 'WAERK'.
s_fieldcatalog-tabname = 'T_VBAP'.
s_fieldcatalog-ref_tabname = 'VBAP'.
s_fieldcatalog-ref_fieldname = 'WAERK'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
* Quantity
s_fieldcatalog-col_pos = '5'.
s_fieldcatalog-fieldname = 'KWMENG'.
s_fieldcatalog-tabname = 'T_VBAP'.
s_fieldcatalog-ref_tabname = 'VBAP'.
s_fieldcatalog-ref_fieldname = 'KWMENG'.
s_fieldcatalog-qfieldname = 'MEINS'.
s_fieldcatalog-qtabname = 'T_VBAP'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
* UOM
s_fieldcatalog-col_pos = '6'.
s_fieldcatalog-fieldname = 'MEINS'.
s_fieldcatalog-tabname = 'T_VBAP'.
s_fieldcatalog-ref_tabname = 'VBAP'.
s_fieldcatalog-ref_fieldname = 'MEINS'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
ENDFORM.
运行结果: