Most efficient itab filtering with ABAP 7.40+ syntax

送分小仙女□ 提交于 2020-12-28 20:53:51

问题


With release 7.40 we have plenty of ways to filter internal table data. For example, one can use such ABAP constructs:

FILTER operator

DATA(lt_extract) =
  FILTER #( lt_bseg USING KEY matnr_bwtar WHERE matnr = CONV matnr( SPACE ) 
                                            AND bwtar = CONV bwtar( SPACE ) ).

FOR table iterations with VALUE construction operator

DATA(lt_extract) = 
 VALUE tty_bseg( FOR line IN lt_bseg WHERE ( matnr EQ SPACE AND bwtar EQ SPACE ) ( line ) ).

Is there any performance gain of one over another and why?

Maybe you know any other syntax to perform internal tables filtering efficiently?


回答1:


I didn't find any benchmark on the web, but it's so simple to make a test by yourself.

It would be logic that FILTER, being specialized for that task, is faster than other constructs which have an overhead cost to choose between many other possible operations.

FILTER has also the advantage to force the developer to use an index. Of course, the building of an index has itself a cost, so you must balance its use versus the amount of filtering done.

The ABAP documentation 7.52 explains well the performance of FILTER and recommendations when to not using it ( https://help.sap.com/http.svc/rc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abenconstructor_expression_filter.htm ) :

Table filtering can also be performed using a table comprehension or a table reduction with an iteration expression for table iterations with FOR. The operator FILTER provides a shortened format for this special case and is more efficient to execute.

A table filter constructs the result row by row. If the result contains almost all rows in the source table, this method can be slower than copying the source table and deleting the surplus rows from the target table.



来源:https://stackoverflow.com/questions/48825937/most-efficient-itab-filtering-with-abap-7-40-syntax

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