ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Internal Tables → Expressions and Functions for Internal Tables → FOR - Table Iterations
FOR - cond
Other versions:
7.31 | 7.40 | 7.54
Syntax
... [USING KEY keyname]
[FROM idx1] [TO idx2]
[WHERE ( log_exp )|(cond_syntax)] ...
Effect
As with LOOP AT itab
,
the following is possible for each expression FOR
... IN itab and FOR GROUPS ... OF
of a constructor expression:
USING KEY
can be used to specify the table key with which table loop is evaluated.
FROM
andTO
can be used as upper and lower limits to restrict the rows in the table index used.
WHERE
can be used to specify static or dynamic conditions for column content.
The syntax and semantics are exactly the same as in
LOOP AT itab, apart from the fact that a statically specified logical expression log_exp
in the WHERE
condition must always be placed in parentheses.
In the expression FOR ... IN GROUP group
,
only static WHERE
conditions can be specified for cond
.
Notes
- The local auxiliary variables of the expression visible in this position can be used for
idx1
,idx2
, and in the logical expression of theWHERE
condition.
- The pseudo component
table_line
can be used in the logical expression of theWHERE
condition.
Example
The example shows how the same result can be achieved with a WHERE
condition
in an iteration expression and the filter operator FILTER
. The shorter filter expression is usually more suitable in this case.
DATA messages TYPE SORTED TABLE OF t100 WITH NON-UNIQUE KEY sprsl msgnr.
SELECT *
FROM t100
WHERE arbgb = 'SABAPDEMOS'
INTO TABLE @messages.
DATA value_tab LIKE messages.
value_tab = VALUE #( FOR wa IN messages WHERE ( sprsl = 'E' ) ( wa ) ).
ASSERT value_tab = FILTER #( messages WHERE sprsl = 'E' ).