二维码

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

Twilight发表于 2019-10-08 14:45Twilight 最后回复于 2019-10-08 14:45 [复制链接] 5226 0

1、sALV双击&单击事件
  1. CLASS lcl_handle DEFINITION.
  2.   PUBLIC SECTION.
  3.     METHODS double_click FOR EVENT double_click OF if_salv_gui_table_display_opt
  4.       IMPORTING ev_field_name eo_row_data.
  5.     METHODS cell_action FOR EVENT cell_action OF if_salv_gui_field_display_opt
  6.       IMPORTING ev_field_name eo_row_data.
  7. ENDCLASS.

  8. CLASS lcl_handle IMPLEMENTATION.
  9.   METHOD double_click.
  10.     DATA: ls_vbak TYPE vbak.
  11.     CHECK ev_field_name = 'VBELN'.
  12. * read the row data
  13.     eo_row_data->get_row_data(
  14.       EXPORTING
  15.         iv_request_type = if_salv_gui_selection_ida=>cs_request_type-all_fields
  16.       IMPORTING
  17.         es_row = ls_vbak ).
  18. * Display the row data
  19.     cl_salv_ida_show_data_row=>display( iv_text = 'VBAK Row Info' is_data = ls_vbak ).
  20.   ENDMETHOD.
  21.   METHOD cell_action.
  22.     DATA: ls_vbak TYPE vbak.
  23.     CHECK ev_field_name = 'VBELN'.
  24. * read the row data
  25.     eo_row_data->get_row_data(
  26.       EXPORTING
  27.         iv_request_type = if_salv_gui_selection_ida=>cs_request_type-all_fields
  28.       IMPORTING
  29.         es_row = ls_vbak ).
  30. * Display the row data
  31.     cl_salv_ida_show_data_row=>display( iv_text = 'VBAK Row Info' is_data = ls_vbak ).
  32.   ENDMETHOD.
  33. ENDCLASS.

  34. TABLES: vbak.

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

  36. START-OF-SELECTION.
  37. **********************************************************************
  38. *alv data
  39. **********************************************************************
  40.   TRY.
  41.       CALL METHOD cl_salv_gui_table_ida=>create
  42.         EXPORTING
  43.           iv_table_name        = 'VBAK'
  44.         RECEIVING
  45.           ro_alv_gui_table_ida = DATA(lr_alv).
  46.     CATCH cx_salv_db_connection.
  47.     CATCH cx_salv_db_table_not_supported.
  48.     CATCH cx_salv_ida_contract_violation.
  49.   ENDTRY.

  50. **********************************************************************
  51. *alv select option
  52. **********************************************************************
  53.   DATA:lt_ranges TYPE if_salv_service_types=>yt_named_ranges.
  54.   DATA:ls_ranges TYPE if_salv_service_types=>ys_named_range.
  55.   DATA: lr_range TYPE REF TO cl_salv_range_tab_collector.
  56.   DATA: lr_handle TYPE REF TO lcl_handle.

  57.   CREATE OBJECT lr_range.
  58.   lr_range->add_ranges_for_name(
  59.     EXPORTING
  60.       iv_name   = 'VBELN'
  61.       it_ranges = s_vbeln[]
  62.   ).

  63.   lr_range->get_collected_ranges(
  64.     IMPORTING
  65.       et_named_ranges = lt_ranges[]
  66.   ).

  67.   ls_ranges-name = 'WAERK'.
  68.   ls_ranges-sign = 'I'.
  69.   ls_ranges-option = 'EQ'.
  70.   ls_ranges-low = 'USD'.
  71.   APPEND ls_ranges TO lt_ranges.

  72.   TRY.
  73.       lr_alv->set_select_options(
  74.     EXPORTING
  75.       it_ranges    = lt_ranges[]
  76.   ).
  77.     CATCH cx_salv_ida_associate_invalid.
  78.     CATCH cx_salv_db_connection.
  79.     CATCH cx_salv_ida_condition_invalid.
  80.     CATCH cx_salv_ida_unknown_name.
  81.   ENDTRY.

  82. **********************************************************************
  83. *alv select option
  84. **********************************************************************
  85.   DATA(lr_option) = lr_alv->display_options( ).
  86.   lr_option->set_title( iv_title = 'VBAK information alv with ida' ).
  87.   lr_option->enable_alternating_row_pattern( ).
  88.   lr_option->enable_double_click( ).
  89.   CREATE OBJECT lr_handle.
  90.   SET HANDLER lr_handle->double_click FOR ALL INSTANCES.
  91. **********************************************************************
  92. *alv field catalog
  93. **********************************************************************
  94.   DATA(lr_display) = lr_alv->field_catalog( )->display_options( ).
  95.   TRY.
  96.       lr_display->display_as_link_to_action( iv_field_name = 'VBELN' ).
  97.     CATCH cx_salv_ida_unknown_name.
  98.     CATCH cx_salv_call_after_1st_display.
  99.   ENDTRY.
  100.   SET HANDLER lr_handle->cell_action FOR ALL INSTANCES.
  101. **********************************************************************
  102. *alv select option
  103. **********************************************************************
  104.   DATA: lt_sort TYPE if_salv_gui_types_ida=>yt_sort_rule.
  105.   DATA: ls_sort TYPE if_salv_gui_types_ida=>ys_sort_rule.
  106.   DATA: lt_aggregations TYPE if_salv_gui_types_ida=>yt_aggregation_rule.
  107.   DATA: ls_aggregations TYPE if_salv_gui_types_ida=>ys_aggregation_rule.

  108.   CLEAR: ls_sort.
  109.   ls_sort-field_name = 'ERNAM'.
  110.   ls_sort-descending = ''.
  111.   ls_sort-is_grouped = 'X'.   "按照字段ERNAM分类
  112.   APPEND ls_sort TO lt_sort.

  113.   CLEAR: ls_aggregations.
  114.   ls_aggregations-field_name = 'NETWR'.
  115.   ls_aggregations-function   = 'SUM'. "SUM,AVG,MIN,MAX,按照分类聚合字段NETWR数值
  116.   APPEND ls_aggregations TO lt_aggregations.

  117.   DATA(lr_layout) = lr_alv->default_layout( ).
  118.   TRY.
  119.       lr_layout->set_sort_order( it_sort_order = lt_sort ).
  120.     CATCH cx_salv_ida_unknown_name.
  121.     CATCH cx_salv_ida_duplicate_name.
  122.   ENDTRY.

  123.   TRY.
  124.       lr_layout->set_aggregations( it_aggregations = lt_aggregations ).
  125.     CATCH cx_salv_key_figure_definition INTO DATA(lv_text).
  126.     CATCH cx_salv_ida_unknown_name.
  127.     CATCH cx_salv_ida_contract_violation.
  128.   ENDTRY.
  129. **********************************************************************
  130. *alv rows
  131. **********************************************************************
  132.   TRY.
  133.       lr_alv->set_maximum_number_of_rows(
  134.         EXPORTING
  135.           iv_number_of_rows = 20
  136.       ).
  137.     CATCH cx_salv_param_out_of_bounds.
  138.   ENDTRY.
  139. **********************************************************************
  140. *alv dispaly
  141. **********************************************************************
  142.   TRY.
  143.       lr_alv->fullscreen( )->display( ).
  144.     CATCH cx_salv_ida_contract_violation.
  145.   ENDTRY.
复制代码
2、执行效果
salv-double_click.jpg
salv-link_cell_action.jpg
回复

使用道具 举报

快速回帖

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

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