*---------------------------- 例一 ------------------------------------
report z_barry_alv_header.
tables : t001.
type-pools: slis.
data : w_repid like sy-repid.
types : begin of ty_comp.
include structure t001.
types : end of ty_comp.
data: wa_layout type slis_layout_alv.
data: it_fieldcat type slis_t_fieldcat_alv,
wa_fieldcat type slis_fieldcat_alv.
data : it_comp type table of ty_comp.
initialization.
w_repid = sy-repid.
start-of-selection.
select * from t001 into table it_comp.
end-of-selection.
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = w_repid
i_internal_tabname = 'IT_COMP'
i_structure_name = 'T001'
i_inclname = w_repid
changing
ct_fieldcat = it_fieldcat[]
exceptions
inconsistent_interface = 1
program_error = 2
others = 3.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = w_repid
i_callback_html_top_of_page = 'HTML_TOP_OF_PAGE'
is_layout = wa_layout
it_fieldcat = it_fieldcat
i_html_height_top = 20 "HTML框的高度
tables
t_outtab = it_comp
exceptions
program_error = 1
others = 2.
*&---------------------------------------------------------------------*
*& Form html_top_of_page
*&---------------------------------------------------------------------*
form html_top_of_page using document type ref to cl_dd_document.
data: text type sdydo_text_element.
text = 'Company Code Data'.
call method document->add_text
exporting
text = text
sap_style = 'HEADING'.
call method document->new_line.
call method document->new_line.
text = 'User Name : '.
call method document->add_text
exporting
text = text
sap_emphasis = 'Strong'.
call method document->add_gap
exporting
width = 2.
text = sy-uname.
call method document->add_text
exporting
text = text
sap_style = 'Key'.
call method document->add_gap
exporting
width = 10.
text = 'Date : '.
call method document->add_text
exporting
text = text
sap_emphasis = 'Strong'.
call method document->add_gap
exporting
width = 2.
text = sy-datum.
call method document->add_text
exporting
text = text
sap_style = 'Key'.
call method document->add_gap
exporting
width = 10.
text = 'Time : '.
call method document->add_text
exporting
text = text
sap_emphasis = 'Strong'.
call method document->add_gap
exporting
width = 2.
text = sy-uzeit.
call method document->add_text
exporting
text = text
sap_style = 'Key'.
call method document->new_line.
endform. "HTML_TOP_OF_PAGE
*------------------------ 例二:ALV的HTML抬头内容根据ALV事件更改 ---------------------------------
report z_barry_alv_header .
tables : t001.
type-pools: slis.
data : w_repid like sy-repid.
types : begin of ty_comp.
include structure t001.
types : end of ty_comp.
data: wa_layout type slis_layout_alv.
data: it_fieldcat type slis_t_fieldcat_alv,
wa_fieldcat type slis_fieldcat_alv.
data : it_comp type table of ty_comp with header line.
initialization.
w_repid = sy-repid.
start-of-selection.
select * from t001 into table it_comp.
it_comp-butxt = '双击ALV的行'.
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = w_repid
i_internal_tabname = 'IT_COMP'
i_structure_name = 'T001'
i_inclname = w_repid
changing
ct_fieldcat = it_fieldcat[]
exceptions
inconsistent_interface = 1
program_error = 2
others = 3.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = w_repid
i_callback_html_top_of_page = 'HTML_TOP_OF_PAGE'
i_callback_user_command = 'USER_COMMAND'
is_layout = wa_layout
it_fieldcat = it_fieldcat
tables
t_outtab = it_comp
exceptions
program_error = 1
others = 2.
*&---------------------------------------------------------------------*
*& Form html_top_of_page
*&---------------------------------------------------------------------*
form html_top_of_page using w_doc type ref to cl_dd_document.
data: code(255) type c .
data: sdydo_html_table type sdydo_html_line occurs 0.
data: wa like line of sdydo_html_table.
call method w_doc->set_document_background
exporting
picture_id = 'ENJOYSAP_LOGO'.
clear code.
refresh w_doc->html_table.
wa-line = '<HTML><BODY bottommargin="0" background="005.jpg">' &
'<SPAN Style="FONT-SIZE: 15pt; COLOR: black; FONT-FAMILY: 黑体; ">' &
'<B>测试ALVHeader显示HTML</b></SPAN><br><br><br>'.
append wa to w_doc->html_table.
concatenate '<SPAN Style="FONT-SIZE: 12pt; COLOR: #FF6400; FONT-FAMILY: 黑体; "> <B>'
it_comp-butxt '</b></SPAN><br><br><br>' into wa-line.
append wa to w_doc->html_table.
wa-line = '<embed src="D:\sxl\kita\yshq.mp3" autostart=true></BODY></HTML>'.
append wa to w_doc->html_table.
endform. "HTML_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
case r_ucomm.
when '&IC1'.
read table it_comp index rs_selfield-tabindex.
when 'EXIT'.
leave program.
endcase.
endform. "user_com
评论