Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most efficient itab filtering with ABAP 7.40+ syntax

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?

like image 829
Suncatcher Avatar asked Feb 16 '18 11:02

Suncatcher


People also ask

How to use filter in sap ABAP 7. 4?

A new FILTER operator is available which can used on ABAP internal tables to filter the data (or) to retrieve subset of data into a new internal table. As of ABAP 7.4 this keyword is available to use in the system. The result of FILTER operator is a new internal table with filtered data.

How to filter internal table in sap ABAP?

USING KEY can (or must) be used to specify a table key for evaluating itab or ftab (depending on the variant). Table filtering can also be performed using a table comprehension or a table reduction with an iteration expression for table iterations with FOR.

How do you filter a table in SAP?

If you press the filter icon at the start of the filter line, or if you press ENTER in a filter InputField, the values of the filter line are put in the relevant attributes for TableColumn. filterValue, and event Table. onFilter is triggered. The actual filtering of the data must be done by the application itself.

How do you populate a range table from an internal table?

I found this code for filling a range table (source is already offline): DATA lr_vkorg TYPE RANGE OF vkorg. TYPES: lr_range_t TYPE RANGE OF vkorg. lr_vkorg = VALUE lr_range_t( LET s = 'I' o = 'EQ' IN sign = s option = o ( low = '1100' ) ( low = '1200' ) ( low = '1300' ) ( low = '1400' ) ( low = '1500' ) ).


1 Answers

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

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 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 use 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.

like image 123
Sandra Rossi Avatar answered Oct 18 '22 23:10

Sandra Rossi