ABAP内表两种DELETE方式的性能比较

ABAP内表两种DELETE方式的性能比较

以代码实例为参考:

REPORT ZDELETE_COMPARE.

PARAMETERS: num type i OBLIGATORY DEFAULT 100.

types: begin of ty_product,
      id type comm_product-product_id,
      text type string,
     end of ty_product.

data: lt_product type STANDARD TABLE OF ty_product,
      lt_product1 LIKE lt_product,
      lt_compare type STANDARD TABLE OF comm_product-product_id,
      lt_range type RANGE OF comm_product-product_id,
      lv_start TYPE i,
      lv_end TYPE i.

FIELD-SYMBOLS: <product> TYPE ty_product,
               <range> LIKE LINE OF lt_range.

START-OF-SELECTION.
  PERFORM generate_main_tab.
  PERFORM solution1.
  PERFORM solution2.
  ASSERT lt_product = lt_product1.


FORM generate_main_tab.
   DO num TIMES.
     APPEND INITIAL LINE TO lt_product ASSIGNING <product>.
     <product>-id = sy-index.
     <product>-text = sy-index.
     APPEND INITIAL LINE TO lt_product1 ASSIGNING <product>.
     <product>-id = sy-index.
     <product>-text = sy-index.

     IF ( sy-index MOD 2 = 0 ).
        APPEND sy-index TO lt_compare.
     ENDIF.
   ENDDO.
ENDFORM.

FORM solution1.
   GET RUN TIME FIELD lv_start.

   LOOP AT lt_product ASSIGNING FIELD-SYMBOL(<product1>).
     READ TABLE lt_compare WITH KEY table_line = <product1>-id TRANSPORTING NO FIELDS.
     IF sy-subrc <> 0.
       DELETE TABLE lt_product FROM <product1>.
     ENDIF.
   ENDLOOP.

   GET RUN TIME FIELD lv_end.
   lv_end = lv_end - lv_start.
  WRITE: / 'Solution1: ' , lv_end COLOR COL_NEGATIVE.
ENDFORM.

FORM solution2.
   GET RUN TIME FIELD lv_start.

   LOOP AT lt_compare ASSIGNING FIELD-SYMBOL(<valid>).
      APPEND INITIAL LINE TO lt_range ASSIGNING <range>.
      <range>-low = <valid>.
      <range>-option = 'EQ'.
      <range>-sign = 'I'.
   ENDLOOP.

   DELETE lt_product1 WHERE id NOT IN lt_range.

   GET RUN TIME FIELD lv_end.
   lv_end = lv_end - lv_start.
  WRITE: / 'Solution2: ' , lv_end COLOR COL_NEGATIVE.
ENDFORM.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ᝰ随心ꦿེএ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值