ABAP Keyword Documentation → ABAP − Reference → Program Flow Logic → Iteration Expressions → FOR - Iteration Expressions → Examples of Iteration Expressions
Inverse Reads on Internal Table with FOR
This example demonstrates how sequential inverse reads are performed on an internal table.
Other versions:
7.31 | 7.40 | 7.54
Source Code
DATA
itab TYPE STANDARD TABLE OF i
WITH EMPTY KEY
WITH NON-UNIQUE SORTED KEY sort_key COMPONENTS table_line.
itab = VALUE #( ( 2 ) ( 5 ) ( 1 ) ( 3 ) ( 4 ) ).
DATA(output) =
REDUCE string(
INIT o = ``
FOR i = lines( itab ) THEN i - 1 WHILE i > 0
NEXT o = o && COND #( LET r = itab[ KEY sort_key INDEX i ] IN
WHEN r > 2 THEN r && ` ` ) ).
cl_demo_output=>display( output ).
Description
In a conditional iteration, an internal table is read using WHILE
and a table
expression. The table expression uses the secondary table key sort_key
and
the result is created in a conditional expression using cond
. The example shows how to bypass the restriction that inverse
table iterations cannot be performed.