二维码

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

Twilight发表于 2019-10-08 10:34Twilight 最后回复于 2019-10-08 10:34 [复制链接] 87 0

1、分类汇总/平均值/最大值/最小值&标题
  1. TABLES: vbak.

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

  3. **********************************************************************
  4. *ALV data
  5. **********************************************************************
  6. TRY.
  7.     CALL METHOD cl_salv_gui_table_ida=>create
  8.       EXPORTING
  9.         iv_table_name        = 'VBAK'
  10.       RECEIVING
  11.         ro_alv_gui_table_ida = DATA(lr_alv).
  12.   CATCH cx_salv_db_connection.
  13.   CATCH cx_salv_db_table_not_supported.
  14.   CATCH cx_salv_ida_contract_violation.
  15. ENDTRY.

  16. **********************************************************************
  17. *alv select option
  18. **********************************************************************
  19. DATA:lt_ranges TYPE if_salv_service_types=>yt_named_ranges.
  20. DATA:ls_ranges TYPE if_salv_service_types=>ys_named_range.
  21. DATA: lr_range TYPE REF TO cl_salv_range_tab_collector.

  22. CREATE OBJECT lr_range.
  23. lr_range->add_ranges_for_name(
  24.   EXPORTING
  25.     iv_name   = 'VBELN'
  26.     it_ranges = s_vbeln[]
  27. ).

  28. lr_range->get_collected_ranges(
  29.   IMPORTING
  30.     et_named_ranges = lt_ranges[]
  31. ).

  32. ls_ranges-name = 'WAERK'.
  33. ls_ranges-sign = 'I'.
  34. ls_ranges-option = 'EQ'.
  35. ls_ranges-low = 'USD'.
  36. APPEND ls_ranges TO lt_ranges.

  37. TRY.
  38.     lr_alv->set_select_options(
  39.   EXPORTING
  40.     it_ranges    = lt_ranges[]
  41. ).
  42.   CATCH cx_salv_ida_associate_invalid.
  43.   CATCH cx_salv_db_connection.
  44.   CATCH cx_salv_ida_condition_invalid.
  45.   CATCH cx_salv_ida_unknown_name.
  46. ENDTRY.

  47. **********************************************************************
  48. *alv select option
  49. **********************************************************************
  50. DATA(lr_option) = lr_alv->display_options( ).
  51. lr_option->set_title( iv_title = 'VBAK information alv with ida' ).
  52. lr_option->enable_alternating_row_pattern( ).

  53. **********************************************************************
  54. *alv select option
  55. **********************************************************************
  56. DATA: lt_sort TYPE if_salv_gui_types_ida=>yt_sort_rule.
  57. DATA: ls_sort TYPE if_salv_gui_types_ida=>ys_sort_rule.
  58. DATA: lt_aggregations TYPE if_salv_gui_types_ida=>yt_aggregation_rule.
  59. DATA: ls_aggregations TYPE if_salv_gui_types_ida=>ys_aggregation_rule.

  60. CLEAR: ls_sort.
  61. ls_sort-field_name = 'ERNAM'.
  62. ls_sort-descending = ''.
  63. ls_sort-is_grouped = 'X'.   "按照字段ERNAM分类
  64. APPEND ls_sort TO lt_sort.

  65. CLEAR: ls_aggregations.
  66. ls_aggregations-field_name = 'NETWR'.
  67. ls_aggregations-function   = 'SUM'. "SUM,AVG,MIN,MAX,按照分类聚合字段NETWR数值
  68. APPEND ls_aggregations TO lt_aggregations.

  69. DATA(lr_layout) = lr_alv->default_layout( ).
  70. TRY.
  71.     lr_layout->set_sort_order( it_sort_order = lt_sort ).
  72.   CATCH cx_salv_ida_unknown_name.
  73.   CATCH cx_salv_ida_duplicate_name.
  74. ENDTRY.

  75. TRY.
  76.     lr_layout->set_aggregations( it_aggregations = lt_aggregations ).
  77.   CATCH cx_salv_key_figure_definition INTO DATA(LV_TEXT).
  78.   CATCH cx_salv_ida_unknown_name.
  79.   CATCH cx_salv_ida_contract_violation.
  80. ENDTRY.
  81. **********************************************************************
  82. *alv rows
  83. **********************************************************************
  84. TRY.
  85.     lr_alv->set_maximum_number_of_rows(
  86.       EXPORTING
  87.         iv_number_of_rows = 20
  88.     ).
  89.   CATCH cx_salv_param_out_of_bounds.
  90. ENDTRY.
  91. **********************************************************************
  92. *alv dispaly
  93. **********************************************************************
  94. TRY.
  95.     lr_alv->fullscreen( )->display( ).
  96.   CATCH cx_salv_ida_contract_violation.
  97. ENDTRY.
复制代码

2、运行结果
salv-aggregation.jpg
回复

使用道具 举报

快速回帖

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

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