乐趣区

关于sap:一个占据SAP-BSP应用占据存储空间的小工具

Today one of my colleague asks me whether there is some tool which can allow us to get a draft estimation on the size of a BSP application. As far as I know there is no such tool, so I write one by myself. This tool simply fetches source code of all artifacts belonging to a specified BSP application (js, html, css etc), accumulate the total number of characters returned by strlen().

You can simply create a report and paste the source code from this blog, execute it by specifying the BSP application name:

And the total number of characters in this BSP application is displayed:

According to ABAP help, in Unicode system 1 char occupies 2 bytes:

So in the example below the BSP application CRM_OPPRTNTY occupies at least 2011344 * 2 = 4022688 bytes.
Source code of report:

REPORT zbsp.
PARAMETERS: bspname TYPE o2pagdir-applname OBLIGATORY DEFAULT 'CRM_OPPRTNTY'.
TYPES:
     BEGIN OF ty_view_source,
       applname TYPE o2pagdir-applname,
       pagekey  TYPE o2pagdir-pagekey,
       source   TYPE o2pageline_table,
     END OF ty_view_source .
TYPES:
  tt_view_source TYPE STANDARD TABLE OF ty_view_source WITH KEY
  applname pagekey .
DATA: ls_pagecon_key TYPE o2pconkey,
  lt_view_source TYPE tt_view_source,
  lv_total TYPE i VALUE 0,
  lv_each TYPE i.
FIELD-SYMBOLS: <line> LIKE LINE OF lt_view_source.
START-OF-SELECTION.
  PERFORM main.
FORM main.
  SELECT applname pagekey FROM o2pagdir INTO CORRESPONDING FIELDS OF TABLE
     lt_view_source WHERE applname = bspname.
  ls_pagecon_key-objtype = 'PD'.
  ls_pagecon_key-version = 'A'.
  LOOP AT lt_view_source ASSIGNING <line>.
    ls_pagecon_key-applname = <line>-applname.
    ls_pagecon_key-pagekey = <line>-pagekey.
    IMPORT content    TO  <line>-source
       FROM DATABASE o2pagcon(tr) ID ls_pagecon_key
       ACCEPTING PADDING IGNORING CONVERSION ERRORS.
    PERFORM get_char_number USING <line>-source CHANGING lv_each.
    lv_total = lv_total + lv_each.
    WRITE: / <line>-pagekey COLOR COL_NEGATIVE, lv_each COLOR COL_KEY.
  ENDLOOP.
  WRITE: / 'total number of characters:' COLOR COL_NEGATIVE , lv_total COLOR COL_GROUP.
ENDFORM.                    "MAIN
FORM get_char_number USING it_source TYPE o2pageline_table CHANGING cv_size TYPE i.
  CLEAR: cv_size.
  FIELD-SYMBOLS: <source> LIKE LINE OF it_source.
  LOOP AT it_source ASSIGNING <source>.
    cv_size = cv_size + strlen(<source>).
  ENDLOOP.
ENDFORM.                    "GET_CHAR_NUMBER

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

退出移动版