ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Internal Tables → Expressions and Functions for Internal Tables → FOR - Table Iterations → Examples of Table Reductions
Table Reductions, Structured Result
This example demonstrates a reduction of the columns of a table to a structure.
Other versions:
7.31 | 7.40 | 7.54
Source Code
cl_demo_output=>write( itab ).
DATA(result) = REDUCE result(
INIT res = VALUE result( max = 0
text = `Result: ` )
sep = ``
FOR <wa> IN itab
NEXT res-text = res-text && sep
&& <wa>-id
res-sum = res-sum + <wa>-num
res-max = nmax( val1 = res-max
val2 = <wa>-num )
sep = `-` ).
cl_demo_output=>display( result ).
Description
Reduces a two-column internal table itab
using
REDUCE
. The content of the first column of all rows is chained after
the FOR
expression, the total
of the second column is calculated, and the maximum value of the second column identified. These values
are assigned to the components of the local structure res
and the structure provided as the result.
The separator sep
in the chaining is declared as an auxiliary variable after
INIT
. It is initial for the first row read and set to a value here for the evaluation of the following rows.