SAP:SALV刷新按钮事件

SAP SALV刷新事件

1、主程序

*&---------------------------------------------------------------------*
*& Report  Z17_04
*&
*&---------------------------------------------------------------------*
*& 全屏Classic List模式
*& LIST_DISPLAY : 用SALV显示与传统式REUSE_ALV_LIST_DISPLAY函数输出ALV
*& 一样效果的报表。
*& 36、USER-COMMAND事件是追加在TOOLBAR事件中追加的图标功能的事件。追加当
*&   单击REFRESS按钮时从表SFLIGHT中取得10件数据的逻辑。
*& 问题: 没有搞懂类的定义、实现与子程序之间的顺序 。
*&---------------------------------------------------------------------*

REPORT Z17_36.



DATA: gt_itab type table of sflight.
DATA: gr_table TYPE REF TO CL_SALV_TABLE.
DATA: gr_function type ref to cl_salv_functions_list." 应用工具栏
DATA: gr_container type ref to cl_gui_custom_container.
DATA: OK_CODE type syucomm.




SELECT * FROM  SFLIGHT INTO CORRESPONDING FIELDS OF TABLE
  gt_itab up to 25 rows.

*& #REGION: 用 屏幕100代替
*cl_salv_table=>factory(
*  EXPORTING
*    list_display = abap_true
*  IMPORTING
*    r_salv_table = gr_table
*  CHANGING
*    t_table = gt_itab
*      ).

*& #region:  应用工具栏
*gr_function = gr_table->get_functions( ).
*gr_function->set_default( ).
*gr_function->set_all( abap_true ).
*& #endregion:  应用工具栏
*


*gr_table->display( ).
*& #ENDREGION: 用 屏幕100代替

*& 调用自定义的屏幕100
CALL SCREEN 0100.



*&---------------------------------------------------------------------*
*& CLASS lcl_handle_events DEFINTION
*&---------------------------------------------------------------------*
CLASS lcl_handle_events DEFINITION.
  PUBLIC SECTION.
    methods:
    on_user_command FOR EVENT added_function of cl_salv_events
    IMPORTING e_salv_function.
ENDCLASS. " lcl_handle_events DEFINITION

*&---------------------------------------------------------------------*
*& CLASS lcl_handle_event IMPLEMENTATION
*&---------------------------------------------------------------------*
CLASS lcl_handle_events IMPLEMENTATION.
  METHOD on_user_command.
    PERFORM handle_user_command USING e_salv_function.
  ENDMETHOD. " on_user_command
ENDCLASS. " lcl_handle_events IMPLEMENTATION

DATA: gr_event type ref to lcl_handle_events.

data: lr_event TYPE REF TO cl_salv_events_table.  " 定义事件变量





*& 屏幕输出后事件 子程序
INCLUDE Z17_36_PBO.
*INCLUDE Z17_35_PBO.
*INCLUDE z17_04_pbo.

*& 屏幕的输入前事件 子程序
INCLUDE Z17_36_PAI.
*INCLUDE Z17_35_PAI.
*INCLUDE z17_04_pai.



*&---------------------------------------------------------------------*
*&  FORM handle_user_command
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
FORM handle_user_command USING p_function type salv_de_function.
  CASE p_function .
    when 'REFRESH'.
      perform refresh.
    WHEN OTHERS.
  ENDCASE.

ENDFORM. " handle__user_command.
*&---------------------------------------------------------------------*
*& FORM REFRESH 刷新事件
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
FORM  Refresh.
  SELECT * FROM SFLIGHT
    INTO CORRESPONDING FIELDS OF TABLE gt_itab
    UP TO 10 rows.

  gr_table->refresh( ).
ENDFORM. " REFRESH FORM.

  

2、屏幕逻辑流

PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
  MODULE 0100_PBO.
*
PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100.
  MODULE 0100_PAI.

  

3、 PAI 子程序

*----------------------------------------------------------------------*
***INCLUDE Z17_36_PAI.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  0100_PAI  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE 0100_PAI INPUT.
  CASE OK_CODE.
    WHEN 'BACK' OR 'EXIT' OR  'CANC'.
      SET SCREEN 0.
      LEAVE SCREEN.
  ENDCASE.
ENDMODULE.                 " 0100_PAI  INPUT

  

4、 PBO子程序 

*----------------------------------------------------------------------*
***INCLUDE Z17_36_PBO.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  0100_PBO  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE 0100_PBO OUTPUT.
  SET PF-STATUS '0100'.

  IF gr_container is not bound.


*& 1. Create Container
    CREATE OBJECT gr_container
     exporting
       container_name = 'CONTAINER'.

*& 2. CREATE ALV
    cl_salv_table=>factory(
      exporting
        r_container = gr_container
        container_name = 'CONTAINER'
      IMPORTING
        r_salv_table = gr_table
      CHANGING
        t_table = gt_itab
    ).

*& 3. SET ALV BUTTON
    gr_function = gr_table->get_functions( ).
    gr_function->set_all( abap_true ). " 追加ALV所有功能

*& 3.1
*& #region: 追加刷新按钮
    INCLUDE <icon>.
    DATA: l_icon TYPE string .
    l_icon = icon_refresh.

    gr_function->add_function(
    name = 'REFRESH'
    icon = l_icon
    text = 'REFRESH'
    tooltip = 'REFRESH'
    position = if_salv_c_function_position=>right_of_salv_functions
    ).
*&
*& #endregion: 追加刷新按钮

*& 3.2
*& #REGION: 注册事件
lr_event = gr_table->get_event( ).
Create object gr_event .
SET HANDLER gr_event->on_user_command for lr_event .
*& #ENDREGION: 注册事件


*& 4. Call alv
    gr_table->display( ).
  ENDIF.
ENDMODULE.                 " 0100_PBO  OUTPUT

  效果图:

 

posted @ 2024-06-13 07:56  samrv  阅读(69)  评论(0编辑  收藏  举报