OO面向对象ALV小测试

选择屏幕时,不需要话个alv控件,
这时也可以用OO ALV的

REPORT  zlm_alv_oo_03.
DATA:
      g_it_spfli TYPE TABLE OF spfli,
      g_wa_spfli TYPE spfli.

DATAl_ref_alv  TYPE REF TO cl_gui_alv_grid.
DATAg_s_events TYPE slis_t_event.
DATAgt_events  TYPE slis_t_event,                   "ALV 事件
      gw_events  TYPE slis_alv_event.

*----------------------------------------------------------------------*
      事件类定义
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION .
  PUBLIC SECTION .
    METHODS:
*To add new functional buttons to the ALV toolbar
    handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
    IMPORTING e_object ,"e_interactive     ,

*To implement user commands
    handle_user_command
    FOR EVENT user_command OF cl_gui_alv_grid
    IMPORTING e_ucomm             ,

*Hotspot click control
    handle_hotspot_click
    FOR EVENT hotspot_click OF cl_gui_alv_grid
    IMPORTING e_row_id e_column_id es_row_no ,

*Double-click control
    handle_double_click
    FOR EVENT double_click OF cl_gui_alv_grid
    IMPORTING e_row e_column    ,

    handle_data_changed
    FOR EVENT data_changed OF cl_gui_alv_grid
    IMPORTING er_data_changed         .

ENDCLASS                   "lcl_event_handler DEFINITION

*----------------------------------------------------------------------*
      CLASS lcl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
 事件类实现
*----------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION .
*Handle Toolbar
  METHOD handle_toolbar.
    PERFORM handle_toolbar USING e_object .e_interactive .
  ENDMETHOD                    "handle_toolbar

*Handle Hotspot Click
  METHOD handle_hotspot_click .
    PERFORM handle_hotspot_click USING e_row_id e_column_id es_row_no .
  ENDMETHOD                    "handle_hotspot_click

*Handle Double Click
  METHOD handle_double_click .
    PERFORM handle_double_click USING e_row e_column .
  ENDMETHOD                    "handle_double_click

*Handle User Command
  METHOD handle_user_command .
    PERFORM handle_user_command USING e_ucomm .
  ENDMETHOD                   "handle_user_command

*Handle Data Changed
  METHOD handle_data_changed .
    PERFORM handle_data_changed USING er_data_changed .
  ENDMETHOD                   "handle_data_changed

ENDCLASS                     "lcl_event_handler IMPLEMENTATION
*&---------------------------------------------------------------------*
*&      Form  HANDLE_BEFORE_USER_COMMAND
*&---------------------------------------------------------------------*
      text
*----------------------------------------------------------------------*
     -->P_E_UCOMM  text
*----------------------------------------------------------------------*
FORM handle_before_user_command  USING    p_e_ucomm.

ENDFORM                   HANDLE_BEFORE_USER_COMMAND
*&---------------------------------------------------------------------*
*&      Form  HANDLE_DOUBLE_CLICK
*&---------------------------------------------------------------------*
      text
*----------------------------------------------------------------------*
     -->P_E_ROW  text
     -->P_E_COLUMN  text
*----------------------------------------------------------------------*
FORM handle_double_click   USING    e_row TYPE lvc_s_row
                                    e_column TYPE lvc_s_col.
  READ TABLE g_it_spfli INTO g_wa_spfli  INDEX e_row-index.
  IF sy-subrc AND e_column-fieldname 'CITYFROM'.
    MESSAGE g_wa_spfli-cityfrom   TYPE 'I'.
  ELSE.
    MESSAGE g_wa_spfli-carrid TYPE 'I'.
  ENDIF.
ENDFORM                   HANDLE_DOUBLE_CLICK
*&---------------------------------------------------------------------*
*&      Form  HANDLE_HOTSPOT_CLICK
*&---------------------------------------------------------------------*
      text
*----------------------------------------------------------------------*
     -->P_E_ROW_ID  text
     -->P_E_COLUMN_ID  text
     -->P_ES_ROW_NO  text
*----------------------------------------------------------------------*
FORM handle_hotspot_click  USING    e_row       TYPE lvc_s_row
                                    e_column    TYPE lvc_s_col
                                    es_row_no   TYPE lvc_s_roid.



ENDFORM                   HANDLE_HOTSPOT_CLICK
*&---------------------------------------------------------------------*
*&      Form  HANDLE_TOOLBAR
*&---------------------------------------------------------------------*
      text
*----------------------------------------------------------------------*
     -->P_E_OBJECT  text
     -->P_E_INTERACTIVE  text
*----------------------------------------------------------------------*
form HANDLE_TOOLBAR  using    p_e_object
                              p_e_interactive.

endform                   HANDLE_TOOLBAR 
*&---------------------------------------------------------------------*
*&      Form  HANDLE_USER_COMMAND
*&---------------------------------------------------------------------*
      text
*----------------------------------------------------------------------*
     -->P_E_UCOMM  text
*----------------------------------------------------------------------*
FORM handle_user_command  USING    p_e_ucomm.

ENDFORM                   HANDLE_USER_COMMAND

*&---------------------------------------------------------------------*
*&      Form  HANDLE_DATA_CHANGED
*&---------------------------------------------------------------------*
      text
*----------------------------------------------------------------------*
     -->P_ER_DATA_CHANGED  text
*----------------------------------------------------------------------*
FORM handle_data_changed  USING    p_er_data_changed.

ENDFORM                   HANDLE_DATA_CHANGED


START-OF-SELECTION.

  SELECT FROM spfli INTO TABLE g_it_spfli.
  PERFORM zform_show.



*&---------------------------------------------------------------------*
*&      Form  zform_show
*&---------------------------------------------------------------------*
FORM zform_show.
*填充事件信息
  CLEAR gt_events[].
  gw_events-name 'CALLER_EXIT'.
  gw_events-form 'CALLER_EXIT'.
  APPEND gw_events TO gt_events.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
     i_callback_program                sy-repid
     i_structure_name                  'SPFLI'
     it_events                         gt_events[]
    TABLES
      t_outtab                           g_it_spfli
            .
ENDFORM                   "zform_show

*&---------------------------------------------------------------------*
*&      Form  caller_exit
*&---------------------------------------------------------------------*
FORM caller_exit USING ls_data TYPE slis_data_caller_exit.
  DATAo_event_handler    TYPE REF TO lcl_event_handler."声明事件处理类对象。
*创建事件处理类
  CREATE OBJECT o_event_handler.
*获取全局的ALV对象
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid l_ref_alv.
*设置事件理类
  SET HANDLER o_event_handler->handle_toolbar        FOR l_ref_alv.
  SET HANDLER o_event_handler->handle_user_command   FOR l_ref_alv.
  SET HANDLER o_event_handler->handle_double_click   FOR l_ref_alv.
  SET HANDLER o_event_handler->handle_hotspot_click  FOR l_ref_alv.
  SET HANDLER o_event_handler->handle_data_changed   FOR l_ref_alv.

ENDFORM                   "CALLER_EXIT
posted @ 2014-01-22 09:20  胡来  阅读(184)  评论(0编辑  收藏  举报