代码参考的
*&---------------------------------------------------------------------*
*& 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
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = V_REPID
I_INTERNAL_TABNAME = 'ITEMTAB'
I_INCLNAME = V_REPID
I_BYPASSING_BUFFER = 'X'
I_BUFFER_ACTIVE = ' '
CHANGING
CT_FIELDCAT = I_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
GS_KEYINFO-HEADER01 = 'EBELN'.
GS_KEYINFO-ITEM01 = 'EBELN'.
G_TABNAME_HEADER = 'HEADERTAB'.
G_TABNAME_ITEM = 'ITEMTAB'.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = V_REPID
IT_FIELDCAT = I_FIELDCAT
I_SAVE = 'A'
I_TABNAME_HEADER = G_TABNAME_HEADER
I_TABNAME_ITEM = G_TABNAME_ITEM
IS_KEYINFO = GS_KEYINFO
I_BYPASSING_BUFFER = 'X'
I_BUFFER_ACTIVE = ' '
TABLES
T_OUTTAB_HEADER = HEADERTAB
T_OUTTAB_ITEM = ITEMTAB
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.