方法一:
*&---------------------------------------------------------------------*
*& Report Z_BARRY_ALV_HEADER *
*& *
*&---------------------------------------------------------------------*
*& *
*&---------------------------------------------------------------------*
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 = 10 "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
方法二:
REPORT z_barry_alv_toolbar .
CONSTANTS: gc_grid_title(20) TYPE c VALUE '带自定义工具栏的ALV GRID模版'.
TYPE-POOLS: slis.
DATA: gd_fieldcat TYPE slis_t_fieldcat_alv.
DATA: sla TYPE slis_layout_alv ,
ivariant LIKE disvariant,
i_repid LIKE sy-repid .
DATA : gt_events TYPE slis_t_event.
DATA: itab_event TYPE slis_t_event,
fld_event TYPE slis_alv_event,
fld_head TYPE slis_listheader,
itab_listhead TYPE slis_t_listheader.
DATA: BEGIN OF itab OCCURS 0,
f(10) TYPE c,
END OF itab.
*PARAMETERS: P_ .
*SELECT-OPTIONS: S_ .
START-OF-SELECTION.
PERFORM getdata.
PERFORM fixdata.
PERFORM outdata.
*&---------------------------------------------------------------------*
*& Form GETDATA
*&---------------------------------------------------------------------*
FORM getdata.
itab-f = 'Test data'.
APPEND itab.
ENDFORM. " GETDATA
*&---------------------------------------------------------------------*
*& Form FIXDATA
*&---------------------------------------------------------------------*
FORM fixdata.
ENDFORM. " FIXDATA
*&---------------------------------------------------------------------*
*& Form outdata
*&---------------------------------------------------------------------*
FORM outdata.
PERFORM fieldcat_init .
sla-colwidth_optimize = 'X'.
sla-zebra = 'X'.
i_repid = sy-repid.
SET TITLEBAR '100' WITH gc_grid_title.
PERFORM frm_alv_header.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = i_repid
it_fieldcat = gd_fieldcat[]
i_save = 'A'
is_variant = ivariant
is_layout = sla
i_callback_user_command = 'USER_COMMAND'
i_callback_pf_status_set = 'SET_STATUS'
it_events = gt_events
TABLES
t_outtab = itab[].
ENDFORM. " outdata
*---------------------------------------------------------------------*
* FORM fieldcat_init *
*---------------------------------------------------------------------*
FORM fieldcat_init .
PERFORM frm_catlg_set USING: 'F' 'Test Filed' .
ENDFORM. "fieldcat_init
*---------------------------------------------------------------------*
* FORM frm_catlg_set *
*---------------------------------------------------------------------*
FORM frm_catlg_set USING p_field
p_text.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
ls_fieldcat-fieldname = p_field.
ls_fieldcat-seltext_l = p_text.
APPEND ls_fieldcat TO gd_fieldcat .
CLEAR ls_fieldcat .
ENDFORM. "frm_catlg_set
*&--------------------------------------------------------------------*
*& Form user_command
*&--------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
READ TABLE itab INDEX rs_selfield-tabindex.
CASE r_ucomm.
WHEN '&IC1'. "双击
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDFORM. "user_com
*&--------------------------------------------------------------------*
*& Form set_status
*&--------------------------------------------------------------------*
FORM set_status USING rt_extab TYPE slis_t_extab.
CLEAR rt_extab.
REFRESH rt_extab.
* APPEND '&ALL' TO rt_extab .
* APPEND '&SAL' TO rt_extab .
SET PF-STATUS 'STANDARD' EXCLUDING rt_extab . "copy from "SAPLKKBL" STANDARD GUI status
ENDFORM. "set_status
**********************************************
FORM frm_alv_header.
*Title
fld_head-typ = 'H'.
fld_head-info = 'HEIHEI'.
APPEND fld_head TO itab_listhead.
CLEAR fld_head.
*PROGRAM ID:
fld_head-typ = 'S'.
fld_head-key = 'KEY'.
fld_head-info = 'INFO '.
APPEND fld_head TO itab_listhead.
CLEAR fld_head.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = gt_events
EXCEPTIONS
list_type_wrong = 1.
IF sy-subrc <> 0.
MESSAGE 'ERROR' TYPE 'E' .
ENDIF.
READ TABLE gt_events WITH KEY name = slis_ev_top_of_page
INTO fld_event.
IF sy-subrc = 0.
fld_event-form = 'FRM_TOP_OF_PAGE'.
APPEND fld_event TO gt_events .
ENDIF.
ENDFORM. " FRM_ALV_HEADER
*&--------------------------------------------------------------------*
*& Form FRM_TOP_OF_PAGE
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM frm_top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = itab_listhead
i_logo = 'TEST_BTZ' "OAER
i_end_of_list_grid = ''.
ENDFORM. " FRM_TOP_OF_PAGE
注:如果需要根据ALV事件更改HTML内容,参考:
阅读(594) | 评论(0) | 转发(0) |