使用 ABAP 7.40+ 语法进行最有效的 itab 过滤 [英] Most efficient itab filtering with ABAP 7.40+ syntax

查看:13
本文介绍了使用 ABAP 7.40+ 语法进行最有效的 itab 过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 7.40 版中,我们有很多方法可以过滤内部表数据.例如,可以使用这样的 ABAP 结构:

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

过滤器运算符

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

FOR 表迭代VALUE 构造运算符

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?

推荐答案

我在网上没有找到任何基准测试,但是自己做一个测试很简单.

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

专用于该任务的 FILTER 比其他结构更快,这是合乎逻辑的,这些结构具有在许多其他可能的操作之间进行选择的开销成本.

It would be logical 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 还具有强制开发人员使用索引的优势.当然,建立索引本身是有成本的,所以你必须平衡它的使用和完成的过滤量.

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.

ABAP 文档 7.52 很好地解释了 FILTER 的性能以及何时不使用它的建议(https://help.sap.com/http.svc/rc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abenconstructor_expression_filter.htm ) :

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

表格过滤也可以使用表格理解或表约简与表迭代的迭代表达式为了.运算符 FILTER 为这个特殊的case 并且执行起来更有效率.

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.

这篇关于使用 ABAP 7.40+ 语法进行最有效的 itab 过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆