实现代码:
*&双层设置ALV
*&---------------------------------------------------------------------*
REPORT ZALV02.
TYPE-POOLS:SLIS.
TYPES: BEGIN OF ty_pmapprove,
INSTID like eban-banfn,
*……………..
expand TYPE xfeld, "这句话是关键,扩展节点
END OF ty_pmapprove.
DATA: it_wflist TYPE STANDARD TABLE OF ty_pmapprove.
data: wa_wflist TYPE ty_pmapprove.
types: begin of ty_eban,
INSTID like eban-banfn,
BNFPO like eban-BNFPO,
LOEKZ like eban-LOEKZ,
* ………………
END OF ty_eban.
data: ty_wflist TYPE STANDARD TABLE OF ty_eban.
CONSTANTS:
cns_vbak TYPE slis_tabname VALUE 'IT_WFLIST', " 第一层表头
cns_vbap TYPE slis_tabname VALUE 'TY_WFLIST'. "第二层项目
*FORM FRM_ALV_HEAD1 .
DATA:
l_rec_layout TYPE slis_layout_alv, "ALV layout setting
l_rec_keyinfo TYPE slis_keyinfo_alv, "Key information
l_h_tbl_sort TYPE slis_sortinfo_alv, "Sort key
l_tbl_sort TYPE slis_t_sortinfo_alv,"Sort table
l_h_tbl_fieldcat TYPE slis_fieldcat_alv,"Field catalog work area
l_tbl_fieldcat TYPE slis_t_fieldcat_alv." Field catalog
* Set layout
l_rec_layout-group_change_edit = 'X'.
l_rec_layout-colwidth_optimize = 'X'.
l_rec_layout-zebra = 'X'.
l_rec_layout-detail_popup = 'X'.
l_rec_layout-get_selinfos = 'X'.
l_rec_layout-expand_FIELDNAME = 'EXPAND'.
l_h_tbl_sort-tabname = 'IT_WFLIST'.
l_h_tbl_sort-fieldname = 'INSTID'.
l_h_tbl_sort-up = 'X'.
APPEND l_h_tbl_sort TO l_tbl_sort.
l_h_tbl_sort-tabname = 'TY_WFLIST'.
l_h_tbl_sort-fieldname = 'INSTID'.
l_h_tbl_sort-up = 'X'.
APPEND l_h_tbl_sort TO l_tbl_sort.
l_h_tbl_sort-tabname = 'TY_WFLIST'.
l_h_tbl_sort-fieldname = 'BNFPO'.
l_h_tbl_sort-up = 'X'.
APPEND l_h_tbl_sort TO l_tbl_sort.
*******表头************
l_h_tbl_fieldcat-tabname = cns_vbak.
l_h_tbl_fieldcat-fieldname = 'INSTID'.
l_h_tbl_fieldcat-seltext_l = '采购申请号'.
APPEND l_h_tbl_fieldcat TO l_tbl_fieldcat.
CLEAR l_h_tbl_fieldcat.
*…………………………………………………
l_h_tbl_fieldcat-tabname = cns_vbak.
l_h_tbl_fieldcat-fieldname = 'WI_STAT1'.
l_h_tbl_fieldcat-seltext_l = '当前状态'.
APPEND l_h_tbl_fieldcat TO l_tbl_fieldcat.
CLEAR l_h_tbl_fieldcat.
******第二层项目***********
l_h_tbl_fieldcat-tabname = cns_vbap.
l_h_tbl_fieldcat-fieldname = 'BNFPO'.
l_h_tbl_fieldcat-seltext_l = '采购申请行项目'.
APPEND l_h_tbl_fieldcat TO l_tbl_fieldcat.
CLEAR l_h_tbl_fieldcat.
l_h_tbl_fieldcat-tabname = cns_vbap.
l_h_tbl_fieldcat-fieldname = 'LOEKZ'.
l_h_tbl_fieldcat-seltext_l = '删除标识'.
APPEND l_h_tbl_fieldcat TO l_tbl_fieldcat.
CLEAR l_h_tbl_fieldcat.
l_h_tbl_fieldcat-tabname = cns_vbap.
l_h_tbl_fieldcat-fieldname = 'MATNR'.
l_h_tbl_fieldcat-seltext_l = '物料编码'.
APPEND l_h_tbl_fieldcat TO l_tbl_fieldcat.
* …………………………………
l_rec_keyinfo-header01 = 'INSTID'.
l_rec_keyinfo-item01 = 'INSTID'.
l_rec_keyinfo-item02 = 'BNFPO'.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_callback_user_command = 'USER_COMMAND'
is_layout = l_rec_layout
it_fieldcat = l_tbl_fieldcat
it_sort = l_tbl_sort
i_tabname_header = cns_vbak
i_tabname_item = cns_vbap
is_keyinfo = l_rec_keyinfo
i_save = 'A'
TABLES
t_outtab_header = IT_WFLIST
t_outtab_item = TY_WFLIST
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.
*ENDFORM. " FRM_ALV_HEAD1