利用REUSE_ALV_HIERSEQ_LIST_DISPLAY进行多层输出(输出表结构的又一例)
1、在程序里包含SLIS
type-pools: slis.
2、声明主表和明细表
* Global structure of list
types: begin of t_table,
tabname like dd03l-tabname,
ddtext like dd02t-ddtext,
as4user like dd02l-as4user,
end of t_table.
types: begin of ud_struct,
position like dd03l-position,
tabname like dd03l-tabname,
fieldname like dd03l-fieldname,
ddtext like dd03t-ddtext,
keyflag like dd03l-keyflag,
rollname like dd03l-rollname,
domname like dd03l-domname,
datatype like dd03l-datatype,
ddleng like dd03l-leng,
checktable like dd03l-checktable,
decimals like dd03l-decimals,
eddtext like dd03t-ddtext,
dddtext like dd03t-ddtext,
end of ud_struct.
data: gt_outtabt type t_table occurs 0 with header line.
data: gt_outtabf type ud_struct occurs 0 with header line.
3、申明主表和明细表的名称变量
g_tabname_header type slis_tabname,
g_tabname_item type slis_tabname.
4、声明主表和明细表连接关键字变量
data: gs_keyinfo type slis_keyinfo_alv
5 、设置输出格式
6、具体完整样例
*&---------------------------------------------------------------------
*& Report ZGETTABLEFIELD *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
report zgettablefield .
* Data declaration
type-pools: slis.
* Global structure of list
types: begin of t_table,
tabname like dd03l-tabname,
ddtext like dd02t-ddtext,
as4user like dd02l-as4user,
end of t_table.
types: begin of ud_struct,
position like dd03l-position,
tabname like dd03l-tabname,
fieldname like dd03l-fieldname,
ddtext like dd03t-ddtext,
keyflag like dd03l-keyflag,
rollname like dd03l-rollname,
domname like dd03l-domname,
datatype like dd03l-datatype,
ddleng like dd03l-leng,
checktable like dd03l-checktable,
decimals like dd03l-decimals,
eddtext like dd03t-ddtext,
dddtext like dd03t-ddtext,
end of ud_struct.
tables: dd03l,dd02l.
data: gt_fieldcat type slis_t_fieldcat_alv.
data: gt_outtabt type t_table occurs 0 with header line.
data: gt_outtabf type ud_struct occurs 0 with header line.
data: gs_keyinfo type slis_keyinfo_alv,
g_tabname_header type slis_tabname,
g_tabname_item type slis_tabname.
data: g_repid like sy-repid.
data : begin of exclude occurs 5,
fcode like sy-ucomm,
end of exclude.
data p_ucomm like sy-ucomm.
select-options s_tname for dd02l-tabname default 'VBAK'.
*======================================================================*
* Initialization fieldcatalog
*======================================================================*
initialization.
g_repid = sy-repid.
g_tabname_header = 'GT_OUTTABT'.
g_tabname_item = 'GT_OUTTABF'.
* define keyinfo
clear gs_keyinfo.
gs_keyinfo-header01 = 'TABNAME'.
gs_keyinfo-item01 = 'TABNAME'.
gs_keyinfo-header02 = space.
gs_keyinfo-item02 = 'POSITION'.
*======================================================================*
* Ereignis : AT SELECTION-SCREEN OUTPUT (PBO-Zeitpunkt) *
*======================================================================*
at selection-screen output.
data exclude like rsexfcode occurs 0 with header line.
if sy-dynnr = 1000.
call function 'RS_SET_SELSCREEN_STATUS'
exporting
p_status = 'ZGETTBFD'
tables
p_exclude = exclude
exceptions
others = 1.
endif.
p_ucomm = space.
*======================================================================*
* Ereignis : AT SELECTION-SCREEN (PAI-Zeitpunkt) *
* letztes PAI-Ereignis *
*======================================================================*
at selection-screen.
p_ucomm = sy-ucomm.
case p_ucomm.
when 'STBL'.
set parameter id 'DTB' field s_tname.
* PERFORM AUTHORITY_CHECK USING 'SE11' .
call transaction 'SE11' and skip first screen.
endcase.
*======================================================================*
* Data selection
*======================================================================*
start-of-selection.
perform select_table tables gt_outtabt.
perform select_field tables gt_outtabf.
*======================================================================*
* Display list
*======================================================================*
end-of-selection.
perform fieldcat_init using gt_fieldcat[].
* CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
* EXPORTING
* i_callback_program = g_repid
* it_fieldcat = gt_fieldcat[]
* TABLES
* t_outtab = gt_outtabf.
call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
exporting
i_callback_program = g_repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* is_layout = gs_layout
it_fieldcat = gt_fieldcat[]
* IT_EXCLUDING =
* it_special_groups = gt_sp_group[]
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* i_default = g_default
* i_save = g_save
* is_variant = g_variant
* it_events = gt_events[]
* IT_EVENT_EXIT =
i_tabname_header = g_tabname_header
i_tabname_item = g_tabname_item
is_keyinfo = gs_keyinfo
* IS_PRINT =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
tables
t_outtab_header = gt_outtabt
t_outtab_item = gt_outtabf.
************************************************************************
* Form Name : fieldcat_init
* Created by : DEV01
* Created on :
* Form Description:
* Set field's output layout
*----------------------------------------------------------------------*
*parameter description
*----------------------------------------------------------------------*
* <--- rt_fieldcat: return field's information
*----------------------------------------------------------------------*
* Modification Log:
* Date Programmer Description
*----------------------------------------------------------------------*
************************************************************************
form fieldcat_init
using rt_fieldcat type slis_t_fieldcat_alv.
data: ls_fieldcat type slis_fieldcat_alv.
data: pos type i value 1.
clear ls_fieldcat.
ls_fieldcat-fieldname = 'TABNAME'.
ls_fieldcat-tabname = g_tabname_header.
ls_fieldcat-ref_fieldname = 'TABNAME'.
ls_fieldcat-ref_tabname = 'DD03T'.
ls_fieldcat-key = 'X'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
ls_fieldcat-fieldname = 'DDTEXT'.
ls_fieldcat-tabname = g_tabname_header.
ls_fieldcat-ref_fieldname = 'DDTEXT'.
ls_fieldcat-ref_tabname = 'DD02T'.
ls_fieldcat-key = 'X'.
append ls_fieldcat to rt_fieldcat.
* ls_fieldcat-fieldname = 'TABNAME'.
* ls_fieldcat-tabname = g_tabname_item.
* ls_fieldcat-ref_fieldname = 'TABNAME'.
* ls_fieldcat-ref_tabname = 'DD03T'.
* LS_FIELDCAT-KEY = 'X'.
* APPEND ls_fieldcat TO rt_fieldcat.
* CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'POSITION'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-ref_fieldname = 'POSITION'.
ls_fieldcat-ref_tabname = 'DD03L'.
ls_fieldcat-key = 'X'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
ls_fieldcat-fieldname = 'FIELDNAME'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-ref_fieldname = 'FIELDNAME'.
ls_fieldcat-ref_tabname = 'DD03T'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
ls_fieldcat-fieldname = 'DDTEXT'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-ref_fieldname = 'DDTEXT'.
ls_fieldcat-ref_tabname = 'DD03T'.
* LS_FIELDCAT-NO_OUT = 'X'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
ls_fieldcat-fieldname = 'KEYFLAG'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-ref_fieldname = 'KEYFLAG'.
ls_fieldcat-ref_tabname = 'DD03L'.
* LS_FIELDCAT-NO_OUT = 'X'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
ls_fieldcat-fieldname = 'DATATYPE'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-ref_fieldname = 'DATATYPE'.
ls_fieldcat-ref_tabname = 'DD03T'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
ls_fieldcat-fieldname = 'DDLENG'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-ref_fieldname = 'LENG'.
ls_fieldcat-ref_tabname = 'DD03L'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
ls_fieldcat-fieldname = 'DECIMALS'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-ref_fieldname = 'DECIMALS'.
ls_fieldcat-ref_tabname = 'DD03L'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
ls_fieldcat-fieldname = 'CHECKTABLE'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-ref_fieldname = 'CHECKTABLE'.
ls_fieldcat-ref_tabname = 'DD03L'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
ls_fieldcat-fieldname = 'ROLLNAME'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-ref_fieldname = 'ROLLNAME'.
ls_fieldcat-ref_tabname = 'DD03L'.
append ls_fieldcat to rt_fieldcat.
clear ls_fieldcat.
ls_fieldcat-fieldname = 'DOMNAME'.
ls_fieldcat-tabname = g_tabname_item.
ls_fieldcat-ref_fieldname = 'DOMNAME'.
ls_fieldcat-ref_tabname = 'DD03L'.
* LS_FIELDCAT-NO_OUT = 'X'.
append ls_fieldcat to rt_fieldcat.
endform. "fieldcat_init
************************************************************************
* Form Name : select_table
* Created by : DEV01
* Created on :
* Form Description:
* Get Table's information
*----------------------------------------------------------------------*
*parameter description
*----------------------------------------------------------------------*
* <---rt_outtab: return field's information
*----------------------------------------------------------------------*
* Modification Log:
* Date Programmer Description
*----------------------------------------------------------------------*
************************************************************************
form select_table tables rt_outtab like gt_outtabt[].
select dd02l~tabname dd02t~ddtext dd02l~as4user
into (rt_outtab-tabname,rt_outtab-ddtext,rt_outtab-as4user)
from dd02l left join dd02t
on dd02l~tabname = dd02t~tabname
and dd02l~as4local = dd02t~as4local
and dd02l~as4vers = dd02t~as4vers
and dd02t~ddlanguage = sy-langu
where dd02l~tabname in s_tname
and dd02l~as4local = 'A'
order by dd02l~tabname.
append rt_outtab.
endselect.
endform. "SELECT_DATA
************************************************************************
* Form Name : select_field
* Created by : DEV01
* Created on :
* Form Description:
* Get Table field's information
*----------------------------------------------------------------------*
*parameter description
*----------------------------------------------------------------------*
* <---rt_outtab: return field's information
*----------------------------------------------------------------------*
* Modification Log:
* Date Programmer Description
*----------------------------------------------------------------------*
************************************************************************
form select_field tables
rt_outtab like gt_outtabf[].
select dd03l~position dd03l~tabname
dd03l~fieldname
dd03t~ddtext
dd03l~keyflag
dd03l~rollname
dd03l~domname
dd03l~datatype
dd03l~leng
dd03l~checktable dd03l~decimals
dd04t~ddtext dd01t~ddtext
into (rt_outtab-position, rt_outtab-tabname,
rt_outtab-fieldname, rt_outtab-ddtext,
rt_outtab-keyflag,rt_outtab-rollname,
rt_outtab-domname,rt_outtab-datatype,
rt_outtab-ddleng,rt_outtab-checktable,
rt_outtab-decimals,
rt_outtab-eddtext,rt_outtab-dddtext)
from dd03l left join dd03t
on dd03l~tabname = dd03t~tabname
and dd03l~fieldname = dd03t~fieldname
and dd03t~ddlanguage = sy-langu
left join dd04t
on dd03l~rollname = dd04t~rollname
and dd04t~ddlanguage = sy-langu
left join dd01t
on dd03l~domname = dd01t~domname
and dd01t~ddlanguage = sy-langu
where dd03l~tabname in s_tname
order by dd03l~tabname dd03l~position.
if rt_outtab-ddtext = space.
if rt_outtab-eddtext = space.
rt_outtab-ddtext = rt_outtab-dddtext.
else.
rt_outtab-ddtext = rt_outtab-eddtext.
endif.
endif.
append rt_outtab.
endselect.
endform. "SELECT_DATA
*&---------------------------------------------------------------------*
*& Form FUNCTION_EXCLUDE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_EXCLUDE text *
*----------------------------------------------------------------------*
form function_exclude tables p_exclude structure exclude.
* data : rcode like sy-subrc.
* clear p_exclude.
* refresh p_exclude.
* exclude-fcode = 'EERW'.
* append exclude.
* exclude-fcode = 'EXIT'.
* append exclude.
endform. " FUNCTION_EXCLUDE
相关连接:http://blog.csdn.net/CompassButton/archive/2005/02/05/281435.aspx