Constructor operators worth memorizing
What you'll learn
Memorize VALUE, CORRESPONDING, COND, SWITCH, REDUCE, FILTER, and FOR..IN — but remember FILTER needs a SORTED or HASHED secondary key or it will not activate.
- VALUE builds structures/tables; CORRESPONDING maps them (with optional MAPPING).
- COND is expression if/else; SWITCH is expression case; REDUCE folds to one value.
- FOR .. IN is a table comprehension; FILTER selects rows by condition.
A handful of constructor operators replace most of the boilerplate of building and transforming data. VALUE builds a structure or table inline; CORRESPONDING maps between structures and accepts a MAPPING addition to bridge differently-named fields; COND is the expression-form if/else and SWITCH the expression-form case; REDUCE folds a table down to a single value with INIT and NEXT.
FILTER selects rows from an internal table by a condition, and FOR .. IN is the table comprehension that builds a new table by iterating an existing one (optionally with a WHERE). Used well, these turn multi-statement loops into a single readable assignment that says what you want, not how to accumulate it.
One sharp edge: FILTER requires the source table to carry a SORTED or HASHED secondary key for the filtered components, or it will not even activate — it raises a syntax error. The right fix is to declare the secondary key on the table (for example WITH NON-UNIQUE SORTED KEY status_idx COMPONENTS status), not to abandon FILTER for a LOOP.
Key points
- VALUE builds structures/tables; CORRESPONDING maps them (with optional MAPPING).
- COND is expression if/else; SWITCH is expression case; REDUCE folds to one value.
- FOR .. IN is a table comprehension; FILTER selects rows by condition.
- FILTER needs a SORTED/HASHED secondary key or it raises a syntax error.
Examples
VALUE builds a table inline; REDUCE folds line amounts into a total in one expression.
ABAPdata(lt_nums) = value int_table( ( 1 ) ( 2 ) ( 3 ) ).
data(lv_total) = reduce i( init s = 0
for <l> in lt_lines
next s = s + <l>-amount ).This will not activate — FILTER needs a declared secondary key for the filtered component.
ABAPdata lt_items type standard table of ty_item.
data(lt_open) = filter #( lt_items where status = 'OPEN' ).Declaring a SORTED secondary key on the source makes FILTER activate.
ABAPdata lt_items type standard table of ty_item
with non-unique sorted key status_idx components status.
data(lt_open) = filter #( lt_items using key status_idx
where status = 'OPEN' ).Pitfalls
- Reaching for FILTER without declaring a secondary key, hitting the syntax error, and falling back to a LOOP instead of just adding the key.
Source notes: clean-core-curriculum §3.3
Ask Claude
Build a prompt from this lesson + your question and open a fresh Claude chat with it pre-filled — handy for adapting a before/after pattern to your own object.