Intersection of internal tables

Using a sorted table temporarily
Runtime: 101 microseconds


* Entries: 200 (ITAB1), 100 (ITAB2)
* Intersection: 50 (ITAB3)
* Line width: 100, Key width: 20

STAB1 = ITAB1.
REFRESH ITAB3.
LOOP AT ITAB2 ASSIGNING <WA>.
  READ TABLE STAB1 FROM <WA>
                   TRANSPORTING NO FIELDS.
  IF SY-SUBRC = 0.
    APPEND <WA> TO ITAB3.
  ENDIF.
ENDLOOP.
FREE STAB1.


Using a hashed table temporarily
Runtime: 92 microseconds
* Entries: 200 (ITAB1), 100 (ITAB2)
* Intersection: 50 (ITAB3)
* Line width: 100, Key width: 20

HTAB1 = ITAB1.
REFRESH ITAB3.
LOOP AT ITAB2 ASSIGNING <WA>.
  READ TABLE HTAB1 FROM <WA>
                   TRANSPORTING NO FIELDS.
  IF SY-SUBRC = 0.
    APPEND <WA> TO ITAB3.
  ENDIF.
ENDLOOP.
FREE HTAB1.

 


Documentation
The source tables ITAB1 and ITAB2 are standard tables. It is assumed
that ITAB1 takes more entries than ITAB2. Otherwise, the table with
more entries must be computed with "DESCRIBE TABLE ... LINES ...".
Since both tables shall represent sets, it is assumed that their
entries are unique with respect to component K.

The algorithm works with a temporary table with unique key K. The
table is a copy of ITAB1 and is used to locate the entries beeing
also contained in ITAB2. The matching entries are copied to ITAB3.
The left-hand and right-hand side differ only by the kind of the
temporary table being used. For a hashed table, the READ statement
in the LOOP is faster than for the sorted table.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值