二维码

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

Twilight发表于 2019-09-26 16:48Twilight 最后回复于 2019-09-26 16:48 [复制链接] 5497 0

SALV不需要写sql语句,通过Integrated Data Access直接访问数据,通常用在HANA平台,根据alv当前展示的数据实时从数据库抽取,滚动alv滚动条能明显感受到数据加载时的卡顿,传统数据库不推荐使用salv,可能会卡死。大量数据展示时SALV的好处特别明显。

一、ALV全屏展示
1、基本功能
  1. CL_SALV_GUI_TABLE_IDA=>create(  iv_table_name = 'VBAK' )->fullscreen( )->display( ).
复制代码

2、扩展fieldcate等功能
  1. PARAMETERS: p_vbeln TYPE vbak-vbeln.

  2. **********************************************************************
  3. *alv data
  4. **********************************************************************
  5. TRY.
  6.     CALL METHOD cl_salv_gui_table_ida=>create
  7.       EXPORTING
  8.         iv_table_name        = 'VBAK'        "这个可以是数据库表,也可以是CDS View
  9.       RECEIVING
  10.         ro_alv_gui_table_ida = DATA(lr_alv).
  11.   CATCH cx_salv_db_connection.
  12.   CATCH cx_salv_db_table_not_supported.
  13.   CATCH cx_salv_ida_contract_violation.
  14. ENDTRY.

  15. **********************************************************************
  16. *alv field cata
  17. **********************************************************************
  18. DATA(lr_field) = lr_alv->field_catalog( ).
  19. lr_field->get_available_fields(
  20.   IMPORTING
  21.     ets_field_names = DATA(lt_fields)
  22. ).

  23. LOOP AT lt_fields ASSIGNING FIELD-SYMBOL(<fs_fields>).
  24.   IF <fs_fields> = 'ABDIS'.
  25.     DELETE lt_fields INDEX sy-tabix.
  26.   ENDIF.
  27. ENDLOOP.
  28. *禁止VBELN排序功能
  29. TRY.
  30.     lr_field->disable_sort( iv_field_name = 'VBELN' ).
  31.   CATCH cx_salv_ida_unknown_name.
  32.   CATCH cx_salv_call_after_1st_display.
  33. ENDTRY.

  34. TRY.
  35.     lr_field->set_available_fields( its_field_names = lt_fields ).
  36.   CATCH cx_salv_ida_unknown_name INTO DATA(cx_text).
  37. ENDTRY.

  38. **********************************************************************
  39. *alv select option
  40. **********************************************************************
  41. DATA:lt_ranges TYPE if_salv_service_types=>yt_named_ranges.
  42. DATA:ls_ranges TYPE LINE OF if_salv_service_types=>yt_named_ranges.

  43. ls_ranges-name = 'VBELN'.
  44. ls_ranges-sign = 'I'.
  45. ls_ranges-option = 'EQ'.
  46. ls_ranges-low = p_vbeln.
  47. APPEND ls_ranges TO lt_ranges.

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

  58. **********************************************************************
  59. *alv rows
  60. **********************************************************************
  61. TRY.
  62.     lr_alv->set_maximum_number_of_rows(
  63.       EXPORTING
  64.         iv_number_of_rows = 20
  65.     ).
  66.   CATCH cx_salv_param_out_of_bounds.
  67. ENDTRY.
  68. **********************************************************************
  69. *alv dispaly
  70. **********************************************************************
  71. TRY.
  72.     lr_alv->fullscreen( )->display( ).
  73.   CATCH cx_salv_ida_contract_violation.
  74. ENDTRY.
复制代码

二、ALV自定义container展示
1、程序代码
  1. DATA:go_cust_cont TYPE REF TO cl_gui_custom_container.

  2. PARAMETERS: p_vbeln TYPE vbak-vbeln.

  3. START-OF-SELECTION.

  4.   CALL SCREEN 3000.

  5. *&---------------------------------------------------------------------*
  6. *& Module DISPLAY_ALV OUTPUT
  7. *&---------------------------------------------------------------------*
  8. *&
  9. *&---------------------------------------------------------------------*
  10. MODULE display_alv OUTPUT.
  11.   CREATE OBJECT go_cust_cont
  12.     EXPORTING
  13.       container_name              = 'CONT1'
  14.     EXCEPTIONS
  15.       cntl_error                  = 1
  16.       cntl_system_error           = 2
  17.       create_error                = 3
  18.       lifetime_error              = 4
  19.       lifetime_dynpro_dynpro_link = 5
  20.       OTHERS                      = 6.
  21.   IF sy-subrc <> 0.
  22.     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  23.   ELSE.
  24. **********************************************************************
  25. *alv data
  26. **********************************************************************
  27.     TRY.
  28.         CALL METHOD cl_salv_gui_table_ida=>create
  29.           EXPORTING
  30.             iv_table_name        = 'VBAK'        "这个可以是数据库表,也可以是CDS View
  31.             io_gui_container     = go_cust_cont
  32.           RECEIVING
  33.             ro_alv_gui_table_ida = DATA(lr_alv).
  34.       CATCH cx_salv_db_connection.
  35.       CATCH cx_salv_db_table_not_supported.
  36.       CATCH cx_salv_ida_contract_violation.
  37.     ENDTRY.

  38. **********************************************************************
  39. *alv field cata
  40. **********************************************************************
  41.     DATA(lr_field) = lr_alv->field_catalog( ).
  42.     lr_field->get_available_fields(
  43.       IMPORTING
  44.         ets_field_names = DATA(lt_fields)
  45.     ).

  46.     LOOP AT lt_fields ASSIGNING FIELD-SYMBOL(<fs_fields>).
  47.       IF <fs_fields> = 'ABDIS'.
  48.         DELETE lt_fields INDEX sy-tabix.
  49.       ENDIF.
  50.     ENDLOOP.
  51. *禁止VBELN排序功能
  52.     TRY.
  53.         lr_field->disable_sort( iv_field_name = 'VBELN' ).
  54.       CATCH cx_salv_ida_unknown_name.
  55.       CATCH cx_salv_call_after_1st_display.
  56.     ENDTRY.

  57.     TRY.
  58.         lr_field->set_available_fields( its_field_names = lt_fields ).
  59.       CATCH cx_salv_ida_unknown_name INTO DATA(cx_text).
  60.     ENDTRY.

  61. **********************************************************************
  62. *alv select option
  63. **********************************************************************
  64.     DATA:lt_ranges TYPE if_salv_service_types=>yt_named_ranges.
  65.     DATA:ls_ranges TYPE LINE OF if_salv_service_types=>yt_named_ranges.

  66.     ls_ranges-name = 'VBELN'.
  67.     ls_ranges-sign = 'I'.
  68.     ls_ranges-option = 'EQ'.
  69.     ls_ranges-low = p_vbeln.
  70.     APPEND ls_ranges TO lt_ranges.

  71.     TRY.
  72.         lr_alv->set_select_options(
  73.       EXPORTING
  74.         it_ranges    = lt_ranges[]
  75.     ).
  76.       CATCH cx_salv_ida_associate_invalid.
  77.       CATCH cx_salv_db_connection.
  78.       CATCH cx_salv_ida_condition_invalid.
  79.       CATCH cx_salv_ida_unknown_name.
  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.   ENDIF.

  92. ENDMODULE.
复制代码

2、screen 3000
salv-custom-container.jpg
3、执行效果
salv-custom-cont-result.jpg
回复

使用道具 举报

快速回帖

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

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