ABAP动态编程的性能开销 - Overhead of ABAP dynamic programming

简介: In Mytask offline performance improvement, it is necessary to support both two DDIC structure modelled in BP and Task, that is, crmt_odata_attachment_t and crmt_bp_odata_attachment_t. It is unknown which data type will be used since they are determined by runtime according to different urls passed f

The first approach to support both structure is first trying with my task structure using line ASSIGN lr_ref->* TO CASTING. If this line fails, we can know the structure does not belong to Task model, so we can use BP structure to store result.

In this approach, we have defined two variables with separate field symbol with data type crmt_odata_attachment_t and crmt_bp_odata_attachment_t to hold result

 METHOD dynamic_fill_approach1.

   DATA: lr_ref     TYPE REF TO data,

         ls_task    TYPE crmt_odata_attachment,

         ls_bp      TYPE crmt_bp_odata_attachment,

         lt_task    TYPE crmt_odata_attachment_t,

         lv_is_task TYPE abap_bool VALUE abap_true,

         lt_bp      TYPE crmt_bp_odata_attachment_t.

   FIELD-SYMBOLS: <detect> TYPE zcrm_task_attachment_t,

                  <task_t> TYPE crmt_odata_attachment_t,

                  <bp_t>   TYPE crmt_bp_odata_attachment_t.

   GET REFERENCE OF ct_table INTO lr_ref.

   TRY.

       ASSIGN lr_ref->* TO <detect> CASTING.

     CATCH cx_root.

       lv_is_task = abap_false.

   ENDTRY.

   LOOP AT ct_table ASSIGNING FIELD-SYMBOL(<task_item>).

     IF lv_is_task = abap_true.

       ASSIGN COMPONENT 'ATTACHMENT' OF STRUCTURE <task_item> TO <task_t>.

       ls_task-name = sy-index.

       ls_task-created_by = sy-uname.

       ls_task-mime_type = 'text/html'.

       ls_task-documentid = ls_task-header_guid = get_guid_by_index( sy-tabix ).

       APPEND ls_task TO <task_t>.

     ELSE.

       ASSIGN COMPONENT 'ATTACHMENT' OF STRUCTURE <task_item> TO <bp_t>.

       ls_bp-name = sy-index.

       ls_bp-created_by = sy-uname.

       ls_bp-mime_type = 'text/html'.

       ls_bp-documentid = get_guid_by_index( sy-tabix ).

       APPEND ls_bp TO <bp_t>.

     ENDIF.

   ENDLOOP.

 ENDMETHOD.

In approach2, we use generic programming style, neither dedicated type for BP nor for Task is defined in the code. Instead, “ANY TABLE” is defined.

 METHOD dynamic_fill_approach2.

   DATA:lr_attachment TYPE REF TO data,

        ls_task       TYPE crmt_odata_attachment,

        lt_task       TYPE crmt_odata_attachment_t.

   FIELD-SYMBOLS: <task_t>   TYPE crmt_odata_attachment_t,

                  <result>   TYPE ANY TABLE,

                  <att_data> TYPE ANY TABLE.

   CREATE DATA lr_attachment LIKE lt_task.

   ASSIGN lr_attachment->* TO <att_data>.

   LOOP AT ct_table ASSIGNING FIELD-SYMBOL(<task_item>).

     ASSIGN COMPONENT 'ATTACHMENT' OF STRUCTURE <task_item> TO <result>.

     CLEAR: lt_task.

     ls_task-name = sy-index.

     ls_task-created_by = sy-uname.

     ls_task-mime_type = 'text/html'.

     ls_task-documentid = ls_task-header_guid = get_guid_by_index( sy-tabix ).

     APPEND ls_task TO lt_task.

* Jerry 2016-01-29 19:10PM this is used to simulate that every task has an internal table

* to store multiple attachments

     <att_data> = lt_task.

     MOVE-CORRESPONDING <att_data> TO <result>.

   ENDLOOP.

 ENDMETHOD.

In ABAP help, it is said we should avoid generic programming unless it is really necessary from security and performance perspective. In this case, I would like to know the performance loss if I use approach2 compared with approach1.

Then I write the following report to get answ

PARAMETERS: num TYPE int4 OBLIGATORY DEFAULT 10.

DATA(lo_tool) = NEW zcl_crm_attachment_tool( ).

DATA: lt_task1 TYPE zcrm_task_attachment_t,

     lt_bp1   TYPE zcrm_bp_attachment_t,

     lt_task2 LIKE lt_task1,

     lt_bp2 LIKE lt_bp1.

CALL METHOD lo_tool->prefill_attachment_tab

 EXPORTING

    iv_num = num

 CHANGING

    ct_bp1 = lt_bp1

    ct_bp2 = lt_bp2

    ct_task1 = lt_task1

    ct_task2 = lt_Task2.

lo_tool->start( ).

lo_tool->dynamic_fill_approach1( CHANGING ct_table = lt_task1 ).

lo_tool->dynamic_fill_approach1( CHANGING ct_table = lt_bp1 ).

lo_tool->stop( 'static assign performance: ').

lo_tool->start( ).

lo_tool->dynamic_fill_approach2( CHANGING ct_table = lt_task2 ).

lo_tool->dynamic_fill_approach2( CHANGING ct_table = lt_bp2 ).

lo_tool->stop( 'dynamic assign performance: ').

CHECK lo_tool->compare_bp( it_bp1 = lt_bp1 it_bp2 = lt_bp2 ).

CHECK lo_tool->compare_task( it_task1 = lt_task1 it_task2 = lt_task2 ).

WRITE: / 'attachment number: ' COLOR COL_POSITIVE,

lines( lt_bp1 ) COLOR COL_GROUP , ' equal' COLOR COL_NEGATIVE.

When handling with 10 tasks: performance difference: 300 microseconds

image.png

100 tasks: approach1 is one time faster than approach2

image.png

500 tasks:


image.png

1000 tasks:

image.png

10000 tasks:

image.png 

相关文章
|
1月前
|
数据库
ABAP 泛型编程实战 - 分享一个数据库表内容的拷贝工具试读版
ABAP 泛型编程实战 - 分享一个数据库表内容的拷贝工具试读版
20 0
|
7月前
|
存储 JavaScript Cloud Native
SAP ABAP 平台新的编程模型
SAP ABAP 平台新的编程模型
69 0
|
6月前
|
算法 搜索推荐 测试技术
ABAP 泛型编程(Generic Programming) 在实际工作中的一个例子
ABAP 泛型编程(Generic Programming) 在实际工作中的一个例子
62 1
|
2月前
|
存储 BI 数据库
如何使用 ABAP 编程的方式,给 Business Object 创建 attachment
如何使用 ABAP 编程的方式,给 Business Object 创建 attachment
22 0
如何使用 ABAP 编程的方式,给 Business Object 创建 attachment
|
6月前
|
JavaScript 前端开发 Java
如何使用 SAP ABAP Development Tool 连接 SAP BTP 上的免费 ABAP 编程环境试读版
如何使用 SAP ABAP Development Tool 连接 SAP BTP 上的免费 ABAP 编程环境试读版
38 0
|
7月前
|
SQL 数据库
使用事务码 SAT 比较传统的 SELECT SQL 语句和 OPEN / FETCH CURSOR 分块读取 ABAP 数据库表两种方式的性能差异试读版
使用事务码 SAT 比较传统的 SELECT SQL 语句和 OPEN / FETCH CURSOR 分块读取 ABAP 数据库表两种方式的性能差异试读版
65 0
|
7月前
|
机器学习/深度学习 JavaScript 前端开发
SAP 云平台 ABAP 编程环境的前世今生
SAP 云平台 ABAP 编程环境的前世今生
67 0
|
7月前
|
存储 测试技术
SAP 云平台上的 ABAP 编程环境里如何消费第三方服务
SAP 云平台上的 ABAP 编程环境里如何消费第三方服务
39 0
|
7月前
|
数据库
SAP Restful ABAP Programming 编程模型的 Action 实现和云端调试介绍
SAP Restful ABAP Programming 编程模型的 Action 实现和云端调试介绍
57 0
|
7月前
|
存储 前端开发 JavaScript
如何使用 Restful ABAP Programming 编程模型开发一个支持增删改查的 Fiori 应用
如何使用 Restful ABAP Programming 编程模型开发一个支持增删改查的 Fiori 应用
38 0

热门文章

最新文章