1.定义变量
DATA : gt_events TYPE slis_t_event ."定义事件内表
* slis_alv_event. " 定义事件内表的行结构,传值时候用.
2. 定义内表事件,将头部显示事件注册到REUSE_ALV_GRID_DISPLAY方法中
PERFORM set_slis_events CHANGING gt_events .
FORM set_slis_events CHANGING ct_events TYPE slis_t_event.
FIELD-SYMBOLS: <ls_event> TYPE slis_alv_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 4
IMPORTING
et_events = ct_events
EXCEPTIONS
list_type_wrong = 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.
DELETE ct_events WHERE name NE 'TOP_OF_PAGE'.
LOOP AT ct_events ASSIGNING <ls_event>.
CONCATENATE 'HANDLE_' <ls_event>-name INTO <ls_event>-form.
ENDLOOP.
ENDFORM. " set_slis_events
"将top_of_page 以外的事件全部删除,拼凑出 HANDLE_TOP_OF_PAGE 事件.
DELETE gt_events WHERE ( name NE 'TOP_OF_PAGE' AND name NE 'USER_COMMAND' ).
"留下多个事件的方法.将gt_events事件注册到REUSE_ALV_GRID_DISPLAY方法中.
it_events = gt_events
3.写handle_top_of_page 事件,填写表头信息.
FORM HANDLE_TOP_OF_PAGE.
DATA: lr_content TYPE REF TO cl_salv_form_element.
*... (1) create the information to be displayed by using
* the ALV Form elements
PERFORM create_alv_form_content_top CHANGING lr_content.
*... (2) Sending the information to the ALV
* Once the inforation to be displayed has been
* created the information has to be sent to the ALV
* This is done by calling the static method
* CL_SALV_FORM_CONTENT=>SET( <content> ) with the content
* which is to be displayed.
* Alternativly the function module REUSE_ALV_COMMENTARY_WRITE
* can still be used.
cl_salv_form_content=>set( lr_content ).
ENDFORM. "HANDLE_TOP-OF-PAGE
4.实现这个form的方法create_alv_form_content_top的这个方法,将内容传入参数lr_content.
FORM create_alv_form_content_top CHANGING cr_content TYPE REF TO cl_salv_form_element.
DATA: lr_grid TYPE REF TO cl_salv_form_layout_grid,
lr_flow TYPE REF TO cl_salv_form_layout_flow,
l_text(500) TYPE c.
*... create a grid
CREATE OBJECT lr_grid.
lr_flow = lr_grid->create_flow(
row = 1
column = 1 ).
l_text = 'name:'.
*create text in cell
lr_flow->create_text( text = l_text ).
lr_flow = lr_grid->create_flow(
row = 1
column = 2 ).
l_text = 'zhangchao' .
lr_flow->create_text( text = l_text ).
cr_content = lr_grid.
ENDFORM. " create_alv_form_content_top
" 先创建对象lr_grid定位输出对象lr_flow的地址 , 由lr_flow这个对象的create_text方法创建l_text 输出内容的字符串.
"最后将lr_grid 对象赋给cr_content ,传入事件中。