(轉)ABAP--ALV_BLOCK_LIAST的函式使用

mmccking發表於2007-08-10
在一個輸出畫面中顯示兩個ALV List。[@more@]

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 = 'T_VBAK'.
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. "GET_FIELDCAT1
*---------------------------------------------------------------------*
* 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. "GET_FIELDCAT2

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8356764/viewspace-941815/,如需轉載,請註明出處,否則將追究法律責任。

相關文章