abap系列-ALV拦截标准工具栏的点击事件

在使用ALV进行输出时,有时需要在用户点击标准按钮前进行一些处理. 例如,用户点击排序按钮前,弹出一个消息框提示用户等,然而系统没有提供事件来捕获这样的点击事件.
通过查看代码标准代码发现,所有的事件都是通过dispatch这个公共方法处理的,于是我们可以通过继承来重定义这个方法,从而实现我们需要的效果.

效果图
在这里插入图片描述

代码如下:

report ysltest2.

class lcl_alv definition inheriting from cl_gui_alv_grid.
  public section.
    methods dispatch redefinition .
    events: befor_sys_button_click exporting value(e_ucomm) type syst-ucomm,
            after_sys_button_click exporting value(e_ucomm) type syst-ucomm.

endclass.
class lcl_alv implementation.
  method dispatch.
    data: action type sy-ucomm.
    if eventid = evt_toolbar_button_click.

      call method get_event_parameter
        exporting
          parameter_id = 0
          queue_only   = space
        importing
          parameter    = action.

      raise event befor_sys_button_click exporting e_ucomm = action.

      super->dispatch( cargo = cargo eventid = eventid is_shellevent = is_shellevent is_systemdispatch = is_systemdispatch ).

      raise event after_sys_button_click exporting e_ucomm = action.

    else.

      super->dispatch( cargo = cargo eventid = eventid is_shellevent = is_shellevent is_systemdispatch = is_systemdispatch ).

    endif.

  endmethod.
endclass.

class lcl_event definition .
  public section.
    class-methods: befor_sort_click for event befor_sys_button_click of lcl_alv importing e_ucomm sender.
endclass.

class lcl_event implementation.
  method befor_sort_click.
    case e_ucomm .
      when sender->mc_fc_sort or
            sender->mc_fc_sort_asc or
            sender->mc_fc_sort_dsc.

        message 'sort button clicked' type 'I'.
    endcase.
  endmethod.
endclass.

data o_con type ref to cl_gui_docking_container.
data gt_makt type table of makt.

data ls_row_no type lvc_s_roid.
data ls_col_info type  lvc_s_col.
data gt_fcat type lvc_t_fcat.
data gs_fcat type lvc_s_fcat.

data o_alv type ref to lcl_alv.

define __fcat.
  gs_fcat-fieldname = &1.
  gs_fcat-reptext = &2.
  gs_fcat-ref_table = 'MAKT'.
  gs_fcat-ref_field = &1.
  append gs_fcat to gt_fcat.
end-of-definition.

parameter p_p1 type c.

at selection-screen output.
  if o_con is initial.
    create object :
      o_con exporting side = cl_gui_docking_container=>dock_at_bottom ratio = 90,
      o_alv exporting i_parent = o_con .

    __fcat:
      'MATNR' '物料号',
      'MAKTX' '物料描述'.

    set handler lcl_event=>befor_sort_click for o_alv .

    o_alv->set_table_for_first_display( changing it_outtab = gt_makt it_fieldcatalog = gt_fcat ).

  endif.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sap虫子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值