Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

[ABAP 7.40] Multiple FILTERS OPERATORS on a iTab

rachidroughi
Explorer
0 Kudos
8,290

Dear,

I would like to apply several FILTERS and separately on my iTab but I am facing an issue on the primay-key definition for the line 54:

Why I cannot apply several filters separately on my sorted Table ?

I need to apply filters separately to avoid applying empty values on my table...

Thank you in advance,

Best regards,

Rachid.

3 REPLIES 3

Sandra_Rossi
Active Contributor
0 Kudos
7,645

FILTER works only by key, primary or secondary, you must indicate all the components of the key. Look at the ABAP documentation if you need some official confirmation.

If you want something slow, use VALUE #( FOR ... WHERE ... )

rachidroughi
Explorer
0 Kudos
7,645

If I provide the full key, my filter will not work correcty because sometimes, some fields of my key are empties and then, the entries are deleted.

I want to filter only when components of the key are not empties...

And, yes, I used VALUE# meanwhile ... it's working but not correct.

Sandra_Rossi
Active Contributor
7,645

FILTER works only by key, primary or secondary, you must indicate all the components of the key. Look at the ABAP documentation if you need some official confirmation.

So, to use FILTER, you must define as many keys as different field combinations (2 in your case).

If you want something slow (without a key/without FILTER), use VALUE #( FOR ... WHERE ... )

Be careful with "itab = VALUE #( FOR <x> IN itab ...)", it always results in an empty itab, it's because VALUE clears the target before running FOR. So you should use LET which runs before the target variable is cleared:

IF gv_division IS NOT INITIAL.
  lt_logs = VALUE #( LET itab = lt_logs IN 
                     FOR <line> IN itab 
                     WHERE ( division = gv_division )
                     ( <line> ) ).
ENDIF.

Note that the solution you may apply the classic solution used in other same situations, not specific to constructor expressions like FILTER or VALUE, which is to use "IN range_table":

... WHERE ( division IN COND ty_range_divisions( WHEN gv_division IS NOT INITIAL 
                                                 THEN VALUE #( ( sign = 'I' option = 'EQ' low = gv_division ) ) )
        AND type IN COND ty_range_types( WHEN gv_type_message IS NOT INITIAL 
                                         THEN VALUE #( ( sign = 'I' option = 'EQ' low = gv_type_message ) ) ) ) ...

(an empty range table means that the field expression is not evaluated)

Depending on your ABAP version, you may also build a dynamic WHERE but I guess it's much less legible.