2023 Apr 14 3:31 PM
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.
2023 Apr 14 4:21 PM
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 ... )
2023 Apr 15 1:56 PM
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.
2023 Apr 16 8:29 AM
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.