二维码

[ooalv] 在alv工具栏上自定义菜单下拉按钮

Twilight发表于 2014-08-20 15:40Twilight 最后回复于 2014-08-20 15:40 [复制链接] 4362 0

程序代码:
  1. *Class declarations
  2. CLASS lcl_event_receiver DEFINITION DEFERRED.
  3. *type pool declarations
  4. TYPE-POOLS : icon.
  5. *Internal table and work area declarations for dd02l
  6. DATA: it_dd02l   TYPE TABLE OF dd02l,
  7.       wa_dd02l TYPE dd02l.
  8. *Data declaration for ALV.
  9. DATA :it_layout   TYPE lvc_s_layo,
  10.       it_toolbar  TYPE stb_button,
  11.       c_alv  TYPE REF TO cl_gui_alv_grid,
  12.       custom_container TYPE REF TO cl_gui_custom_container,
  13.       event_receiver TYPE REF TO lcl_event_receiver.
  14. *Select options multiple values no ranges
  15. SELECT-OPTIONS : s_table FOR wa_dd02l-tabname NO INTERVALS.
  16. *Initialization event
  17. INITIALIZATION.
  18. *Start of selection event
  19. START-OF-SELECTION.
  20. *sUBROUTINE FOR ALV DISPLAY
  21.   PERFORM alvdisplay.
  22. *Class definition
  23. CLASS lcl_event_receiver DEFINITION.
  24.   PUBLIC SECTION.
  25.     CLASS-METHODS:
  26. *handling toolbar for interactive
  27.      handle_toolbar
  28.         FOR EVENT toolbar OF cl_gui_alv_grid
  29.             IMPORTING e_object e_interactive,
  30. *handling menu button
  31.      handle_menu_button
  32.         FOR EVENT menu_button OF cl_gui_alv_grid
  33.             IMPORTING e_object e_ucomm,
  34. *On click of the menu button
  35.     handle_user_command
  36.         FOR EVENT user_command OF cl_gui_alv_grid
  37.             IMPORTING e_ucomm.
  38.   PRIVATE SECTION.
  39. ENDCLASS.                    "lcl_event_receiver DEFINITION
  40. *Class implementation
  41. CLASS lcl_event_receiver IMPLEMENTATION.
  42.   METHOD handle_toolbar.
  43. * handle toolbar
  44.     CLEAR it_toolbar.
  45.     MOVE 'DETAIL' TO it_toolbar-function.
  46.     MOVE icon_detail TO it_toolbar-icon.
  47.     MOVE 2 TO it_toolbar-butn_type.
  48.     APPEND it_toolbar TO e_object->mt_toolbar.
  49.   ENDMETHOD.                    "handle_toolbar
  50.   METHOD handle_menu_button.
  51. * handle own menubuttons
  52.     IF e_ucomm = 'DETAIL'.
  53.       CALL METHOD e_object->add_function
  54.         EXPORTING
  55.           fcode = 'DISPLAY'
  56.           text  = 'DISPLAY'.
  57.     ENDIF.
  58.   ENDMETHOD.                    "handle_menu_button
  59.   METHOD handle_user_command.
  60. *On click
  61.     CASE e_ucomm.
  62.       WHEN 'DISPLAY'.
  63.         MESSAGE 'Menu Clicked' TYPE 'I'.
  64.     ENDCASE.
  65.   ENDMETHOD.                           "handle_user_command
  66. ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION
  67. *&-----------------------------------------------------------------*
  68. *&      Module  PBO  OUTPUT
  69. *&-----------------------------------------------------------------*
  70. *       text
  71. *------------------------------------------------------------------*
  72. MODULE pbo OUTPUT.
  73.   IF custom_container IS INITIAL.
  74. * select data from table dd02l
  75.     PERFORM fetch_dd02l.
  76. * create a custom container control for our ALV Control
  77.     CREATE OBJECT custom_container
  78.         EXPORTING
  79.             container_name = 'CCONT'.
  80. * create an instance of alv control
  81.     CREATE OBJECT c_alv
  82.            EXPORTING i_parent = custom_container.
  83. * Set a titlebar for the grid control
  84.     it_layout-grid_title = 'TABLE DETAILS'.
  85. *ALV display
  86.     CALL METHOD c_alv->set_table_for_first_display
  87.       EXPORTING
  88.         i_structure_name = 'dd02l'
  89.         is_layout        = it_layout
  90.       CHANGING
  91.         it_outtab        = it_dd02l.
  92. *Handlers for the events
  93.     CREATE OBJECT event_receiver.
  94.     SET HANDLER event_receiver->handle_user_command
  95.                 event_receiver->handle_menu_button
  96.                 event_receiver->handle_toolbar FOR ALL INSTANCES.
  97. *Calling the interactive toolbar method of ALV
  98.     CALL METHOD c_alv->set_toolbar_interactive.
  99.   ENDIF.
  100. ENDMODULE.                             " PBO  OUTPUT
  101. *&-----------------------------------------------------------------*
  102. *&      Module  PAI  INPUT
  103. *&-----------------------------------------------------------------*
  104. *       text
  105. *-----------------------------------------------------------------*
  106. MODULE pai INPUT.
  107. ENDMODULE.                             " PAI  INPUT
  108. *&----------------------------------------------------------------*
  109. *&      form fetch_dd02l
  110. *&----------------------------------------------------------------*
  111. *       text
  112. *-----------------------------------------------------------------*
  113. *Subroutine to fetch data
  114. FORM fetch_dd02l.
  115.   SELECT * FROM dd02l INTO CORRESPONDING FIELDS OF TABLE it_dd02l
  116.   WHERE  tabname IN s_table.
  117. ENDFORM.                               " SELECT_TABLE_dd02l
  118. *&-----------------------------------------------------------------*
  119. *&      Form  ALVDISPLAY
  120. *&-----------------------------------------------------------------*
  121. *       text
  122. *------------------------------------------------------------------*
  123. *  -->  p1        text
  124. *  <--  p2        text
  125. *------------------------------------------------------------------*
  126. FORM alvdisplay .
  127. * ALV output
  128.   SET SCREEN 600.
  129. ENDFORM.                    " ALVDISPLAY
复制代码

程序执行效果:
defined menu.jpg
回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表