二维码

[salv] ABAP报表开发HANA平台大数据展示工具SALV学习之五

Twilight发表于 2019-10-09 11:46Twilight 最后回复于 2019-10-09 11:46 [复制链接] 264 0

sALV工具栏操作有两个方法TOOLBAR&STANDARD_FUNCTIONS,其中STANDARD_FUNCTIONS功能比较简单,就是实现工具栏按钮的开启和隐藏,但是TOOLBAR方法可以新增按钮、添加按钮下拉等功能。

1、工具栏的显示隐藏
  1. CLASS lcl_handle DEFINITION.
  2.   PUBLIC SECTION.
  3.     METHODS handle FOR EVENT function_selected OF if_salv_gui_toolbar_ida
  4.       IMPORTING ev_fcode.
  5. ENDCLASS.

  6. CLASS lcl_handle IMPLEMENTATION.
  7.   METHOD handle.
  8.     CASE ev_fcode.
  9.       WHEN 'DELE'.
  10.         MESSAGE 'This is delete button' TYPE 'I'.
  11.     ENDCASE.
  12.   ENDMETHOD.
  13. ENDCLASS.

  14. TABLES: vbak.

  15. SELECT-OPTIONS: s_vbeln FOR vbak-vbeln.

  16. START-OF-SELECTION.
  17. **********************************************************************
  18. *ALV data
  19. **********************************************************************
  20.   TRY.
  21.       CALL METHOD cl_salv_gui_table_ida=>create
  22.         EXPORTING
  23.           iv_table_name        = 'VBAK'
  24.         RECEIVING
  25.           ro_alv_gui_table_ida = DATA(lr_alv).
  26.     CATCH cx_salv_db_connection.
  27.     CATCH cx_salv_db_table_not_supported.
  28.     CATCH cx_salv_ida_contract_violation.
  29.   ENDTRY.

  30. **********************************************************************
  31. *alv select option
  32. **********************************************************************
  33.   DATA:lt_ranges TYPE if_salv_service_types=>yt_named_ranges.
  34.   DATA:ls_ranges TYPE if_salv_service_types=>ys_named_range.
  35.   DATA: lr_range TYPE REF TO cl_salv_range_tab_collector.

  36.   CREATE OBJECT lr_range.
  37.   lr_range->add_ranges_for_name(
  38.     EXPORTING
  39.       iv_name   = 'VBELN'
  40.       it_ranges = s_vbeln[]
  41.   ).

  42.   lr_range->get_collected_ranges(
  43.     IMPORTING
  44.       et_named_ranges = lt_ranges[]
  45.   ).

  46.   ls_ranges-name = 'WAERK'.
  47.   ls_ranges-sign = 'I'.
  48.   ls_ranges-option = 'EQ'.
  49.   ls_ranges-low = 'USD'.
  50.   APPEND ls_ranges TO lt_ranges.

  51.   TRY.
  52.       lr_alv->set_select_options(
  53.     EXPORTING
  54.       it_ranges    = lt_ranges[]
  55.   ).
  56.     CATCH cx_salv_ida_associate_invalid.
  57.     CATCH cx_salv_db_connection.
  58.     CATCH cx_salv_ida_condition_invalid.
  59.     CATCH cx_salv_ida_unknown_name.
  60.   ENDTRY.

  61. **********************************************************************
  62. *alv select option
  63. **********************************************************************
  64.   DATA(lr_option) = lr_alv->display_options( ).
  65.   lr_option->set_title( iv_title = 'VBAK information alv with ida' ).
  66.   lr_option->enable_alternating_row_pattern( ).

  67. **********************************************************************
  68. *Toolbar
  69. **********************************************************************
  70. *  lr_alv->toolbar( )->hide_all_standard_functions(  ).    "隐藏工具栏所有按钮
  71.   DATA:lr_handle TYPE REF TO lcl_handle.

  72.   TRY.
  73.       lr_alv->toolbar( )->add_button(
  74.     EXPORTING
  75.       iv_fcode                     = 'DELE'
  76.       iv_icon                      = '@11@' "ICON_DELETE
  77. *    iv_is_disabled               =
  78.       iv_text                      = 'Delete button'
  79.       iv_quickinfo                 = 'Delete'
  80. *    iv_is_checked                =
  81. *    iv_before_standard_functions = abap_false
  82.   ).
  83.     CATCH cx_salv_ida_gui_fcode_reserved.
  84.   ENDTRY.

  85.   CREATE OBJECT lr_handle.
  86.   SET HANDLER lr_handle->handle FOR ALL INSTANCES.

  87. **********************************************************************
  88. *standard functions
  89. **********************************************************************
  90.   DATA(lr_func) = lr_alv->standard_functions( ).
  91. *lr_func->SET_EXPORT_ACTIVE( iv_active = abap_false ).       "Deactivate/activate function 'Export'
  92.   lr_func->set_print_active( iv_active = abap_false ).       "Deactivate/activate function 'Print'
  93. *lr_func->set_filter_active( iv_active = abap_false ).       "Deactivate/activate function 'Set Filter'
  94. *lr_func->set_sort_active( iv_active = abap_false ).         "Deactivate/activate function 'Sort'
  95. *lr_func->set_detail_active( iv_active = abap_false ).       "Deactivate/activate function 'Display Detail'
  96. *lr_func->set_aggregation_active( iv_active = abap_false ).  "Deactivate/activate all aggregation functions
  97. *lr_func->set_text_search_active( iv_active = abap_false ).  "Enable/Disable function 'TextSearch'

  98. **********************************************************************
  99. *alv rows
  100. **********************************************************************
  101.   TRY.
  102.       lr_alv->set_maximum_number_of_rows(
  103.         EXPORTING
  104.           iv_number_of_rows = 20
  105.       ).
  106.     CATCH cx_salv_param_out_of_bounds.
  107.   ENDTRY.
  108. **********************************************************************
  109. *alv dispaly
  110. **********************************************************************
  111.   TRY.
  112.       lr_alv->fullscreen( )->display( ).
  113.     CATCH cx_salv_ida_contract_violation.
  114.   ENDTRY.
复制代码

2、测试效果
salv-toolbar-functions.jpg
STANDARD_FUNCTIONS 隐藏指定按钮
salv-toolbar-cancel-all.jpg
TOOLBAR隐藏所有按钮
salv-delete-button.jpg
添加删除按钮
回复

使用道具 举报

快速回帖

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

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