代码参考的
http://blog.sina.com.cn/s/blog_5ccd375b0100bia3.html
格式稍作整理:
*&---------------------------------------------------------------------*
*& Report YLM_0003
*&
*&---------------------------------------------------------------------*
*& created by lium
*& ALV Header Item 多层显示
*&---------------------------------------------------------------------*
REPORT YLM_0003
.
TABLES
: EKKO
, EKPO
.
SELECT-OPTIONS
: S_EBELN
FOR EKKO
-EBELN
.
TYPE-POOLS
: SLIS
.
DATA
:
BEGIN
OF HEADERTAB
OCCURS
0
,
EBELN
LIKE EKKO
-EBELN
,
BSTYP
LIKE EKKO
-BSTYP
,
BSART
LIKE EKKO
-BSART
,
STATU
LIKE EKKO
-STATU
,
END
OF HEADERTAB
.
DATA
:
BEGIN
OF ITEMTAB
OCCURS
0
,
EBELN
LIKE EKPO
-EBELN
,
EBELP
LIKE EKPO
-EBELP
,
MATNR
LIKE EKPO
-MATNR
,
WERKS
LIKE EKPO
-WERKS
,
MENGE
LIKE EKPO
-MENGE
,
NETPR
LIKE EKPO
-NETPR
,
PEINH
LIKE EKPO
-PEINH
,
NETWR
LIKE EKPO
-NETWR
,
END
OF ITEMTAB
.
DATA
: I_FIELDCAT
TYPE SLIS_T_FIELDCAT_ALV
.
DATA
: V_REPID
LIKE SY
-REPID
.
DATA
: G_TABNAME_HEADER
TYPE SLIS_TABNAME
,
G_TABNAME_ITEM
TYPE SLIS_TABNAME
,
GS_KEYINFO
TYPE SLIS_KEYINFO_ALV
.
START-OF-SELECTION
.
V_REPID
= SY
-REPID
.
SELECT EBELN BSTYP BSART STATU
INTO
TABLE HEADERTAB
FROM EKKO
WHERE EBELN
IN S_EBELN
.
IF
NOT HEADERTAB[]
IS
INITIAL
.
SELECT EBELN EBELP MATNR WERKS MENGE NETPR PEINH NETWR
INTO
TABLE ITEMTAB
FROM EKPO
FOR
ALL ENTRIES
IN HEADERTAB
WHERE EBELN
= HEADERTAB
-EBELN
.
ENDIF
.
CALL
FUNCTION
'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME
= V_REPID
I_INTERNAL_TABNAME
=
'HEADERTAB'
I_INCLNAME
= V_REPID
I_BYPASSING_BUFFER
=
'X'
I_BUFFER_ACTIVE
=
' '
CHANGING
CT_FIELDCAT
= I_FIELDCAT
EXCEPTIONS