ALV的提供了事件的功能,通过事件功能可以设置ALV的页眉页脚,GUI Status,用户自定义功能,功能触发前后动作。
通过Function ‘REUSE_ALV_EVENT_NAMES_GET’可以取得ALV提供的所以事件。下面是ALV的所有事件:
SLIS_EV_CALLER_EXIT_AT_START
SLIS_EV_USER_COMMAND
SLIS_EV_TOP_OF_PAGE
SLIS_EV_TOP_OF_COVERPAGE
SLIS_EV_END_OF_COVERPAGE
SLIS_EV_FOREIGN_TOP_OF_PAGE
SLIS_EV_FOREIGN_END_OF_PAGE
SLIS_EV_PF_STATUS_SET
SLIS_EV_LIST_MODIFY
SLIS_EV_TOP_OF_LIST
SLIS_EV_END_OF_PAGE
SLIS_EV_END_OF_LIST
SLIS_EV_AFTER_LINE_OUTPUT
SLIS_EV_BEFORE_LINE_OUTPUT
SLIS_EV_REPREP_SEL_MODIFY
SLIS_EV_SUBTOTAL_TEXT
下面图片的功能全部都是用ALV的事件做到的
下面是源代码
TYPE-POOLS slis.
TYPES ty_tab_spfli TYPE spfliOCCURS 0.
START-OF-SELECTION.
PERFORM f_display.
*&---------------------------------------------------------------------*
*& Form f_getdata
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PT_SPFLI text
*----------------------------------------------------------------------*
FORM f_getdata TABLES pt_spfliTYPE ty_tab_spfli.
SELECT * FROM spfli INTO TABLE pt_spfli.
ENDFORM. "f_getdata
*&---------------------------------------------------------------------*
*& Form f_display
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_display.
DATA: lt_spfli TYPE ty_tab_spfli,
lt_events TYPE slis_t_event.
PERFORM f_getdata TABLES lt_spfli.
PERFORM f_event_build TABLES lt_events.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_structure_name = 'SPFLI'
it_events = lt_events
TABLES
t_outtab = lt_spfli.
ENDFORM. "f_display
*&---------------------------------------------------------------------*
*& Form f_event_build
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PT_EVENTS text
*----------------------------------------------------------------------*
FORM f_event_build TABLESpt_events TYPE slis_t_event.
DATA lwa_event LIKE LINE OF pt_events.
lwa_event-name = 'PF_STATUS_SET'.
lwa_event-form = 'F_SET_STATUS'.
APPEND lwa_event TO pt_events.
lwa_event-name = 'USER_COMMAND'.
lwa_event-form = 'F_SET_USER_COMMAND'.
APPEND lwa_event TO pt_events.
lwa_event-name = 'TOP_OF_PAGE'.
lwa_event-form = 'F_TOP_OF_PAGE'.
APPEND lwa_event TO pt_events.
lwa_event-name = 'END_OF_LIST'.
lwa_event-form = 'F_END_OF_LIST'.
APPEND lwa_event TO pt_events.
ENDFORM. "f_event_build
*&---------------------------------------------------------------------*
*& Form f_set_status
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
FORM f_set_status USINGrt_extab TYPE slis_t_extab.
SET PF-STATUS 'SLVC_FULLSCREEN' EXCLUDINGrt_extab.
ENDFORM. "f_set_status
*&---------------------------------------------------------------------*
*& Form f_set_user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM f_set_user_command USINGucomm LIKE sy-ucomm
rs_selfield TYPEslis_selfield.
CASE ucomm.
WHEN 'FUNCTION'.
MESSAGE i000(ytest) WITH 'you clickbutton'.
ENDCASE.
ENDFORM. "f_set_user_command
*&---------------------------------------------------------------------*
*& Form F_TOP_OF_PAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_top_of_page.
DATA: lt_listheader TYPE slis_t_listheader,
lwa_listheader LIKE LINE OFlt_listheader.
lwa_listheader-typ = 'H'.
lwa_listheader-info = 'Xin''s alv EventHEADER'.
APPEND lwa_listheader TO lt_listheader.
lwa_listheader-typ = 'S'.
lwa_listheader-info = 'Selection'.
APPEND lwa_listheader TO lt_listheader.
lwa_listheader-typ = 'A'.
lwa_listheader-info = 'Action'.
APPEND lwa_listheader TO lt_listheader.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
i_logo = 'ENJOYSAP_LOGO'
it_list_commentary = lt_listheader.
ENDFORM. "F_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form F_END_OF_LIST
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_end_of_list.
DATA: lt_listheader TYPE slis_t_listheader,
lwa_listheader LIKE LINE OF lt_listheader.
lwa_listheader-typ = 'H'.
lwa_listheader-info = 'End Of List'.
APPEND lwa_listheader TO lt_listheader.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = lt_listheader.
ENDFORM. "F_END_OF_LIST