通过一个简单的ABAP报表窥探ABAP内存分配和管理机制

感情迁移 提交于 2020-01-25 07:56:03
REPORT zhelloworld.

PARAMETERS: clear TYPE c as CHECKBOX DEFAULT abap_false.

TYPES: tt_table TYPE TABLE OF tadir WITH KEY pgmid object.
DATA: lt_result TYPE TABLE OF tadir,
      lt_total  TYPE TABLE OF tadir,
      lr_result TYPE REF TO tt_table.

DATA: c1 TYPE cursor.

OPEN CURSOR @c1 FOR SELECT * FROM tadir.

DO.
  WRITE: / |Round: { sy-index } | COLOR COL_NEGATIVE.
  CREATE DATA lr_result.
  FETCH NEXT CURSOR @c1 INTO TABLE @lr_result->* PACKAGE SIZE 800000.
  IF sy-subrc <> 0.
    EXIT.
  ENDIF.
  APPEND LINES OF lr_result->* TO lt_total.
  cl_abap_memory_utilities=>get_memory_size_of_object( EXPORTING object = lt_total
      IMPORTING
        bound_size_alloc = DATA(bound_alloc)
        bound_size_used = DATA(bound_used) ).

  WRITE: / 'bound alloc:' , bound_alloc.
  WRITE: / 'bound used:' , bound_used.

  cl_abap_memory_utilities=>get_total_used_size( IMPORTING size = DATA(lv_before_size) ).
  WRITE: / |Total size before GC: { lv_before_size }| COLOR COL_POSITIVE.
  IF clear = abap_true.
     CLEAR: lr_result->*, lt_result, lr_result.
  ENDIF.
  "cl_abap_memory_utilities=>do_garbage_collection( ).
  cl_abap_memory_utilities=>get_total_used_size( IMPORTING size = DATA(lv_after_size) ).
  WRITE: / |Total size after GC: { lv_after_size }| COLOR COL_GROUP.
  DATA(rate) = ( lv_before_size - lv_after_size ) * 100 / lv_before_size.
  WRITE: / |Freed rate: { rate }%| COLOR COL_TOTAL.
ENDDO.

WRITE: / lines( lt_total ).

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!