How do table expressions work, and what happens when the line does not exist?
Say your answer out loud first.
Practise another way
A table expression reads a line directly: itab[ 3 ] by index, or itab[ key = value ] by components. It replaces READ TABLE for a single read.
If the line is not found, it raises the catchable exception CX_SY_ITAB_LINE_NOT_FOUND instead of setting sy-subrc. So I either check first with line_exists, wrap it in TRY, or use VALUE with OPTIONAL or DEFAULT to get an initial or default line back.
A table expression reads one line at an operand position. Variants:
itab[ 3 ]by indexitab[ order_id = 1 item = 2 ]by componentsitab[ KEY by_mat material =PEN]by a named keyitab[ 2 ]-qtydirect access to a component
Unlike READ TABLE, a table expression does not set sy-subrc. If no line matches, the catchable exception CX_SY_ITAB_LINE_NOT_FOUND is raised. This is the most common bug when people migrate from READ TABLE.
DATA(line) = items[ order_id = 1 item = 2 ]. " raises if missing
DATA(opt) = VALUE #( items[ order_id = 9 item = 9 ] OPTIONAL ). " initial line
DATA(dflt) = VALUE #( items[ order_id = 9 item = 9 ] DEFAULT items[ 1 ] ).
IF line_exists( items[ order_id = 9 ] ).
DATA(qty) = items[ order_id = 9 ]-qty.
ENDIF.
TRY.
DATA(x) = items[ 99 ].
CATCH cx_sy_itab_line_not_found INTO DATA(err).
ENDTRY.
Choosing a handling style
line_exists( )when the program branches on presence. It reads twice if you then read the line.OPTIONALreturns an initial line. That makes "not found" look like a real line full of initial values, so use it only when initial is a valid answer.DEFAULTreturns a line you choose.TRY ... CATCHwhen absence is an error.ASSIGN itab[ ... ] TO FIELD-SYMBOL(<l>)sets sy-subrc and gives access without raising, which suits "update if found".
Performance: a fully specified key of a sorted or hashed table uses that key; on a standard table with free components it is a linear search, as with READ TABLE.
Release: table expressions are ABAP 7.40; OPTIONAL and DEFAULT came with 7.40 SP08.
Names the exception, states that sy-subrc is not set, and gives four ways to handle a missing line with the downside of OPTIONAL.
Says 'it is like READ TABLE' and is surprised when asked what happens on a miss.
Replacing every READ TABLE with a table expression without handling the exception, so the first missing line dumps or hits a catch-all.
- Does a table expression set sy-subrc?
- What is the problem with OPTIONAL when the table holds structures?
- How do you read by a secondary key?
- How would you update a component only if the line exists?
3 official pages and 2 prep guides. Confidence: high. Checked 21 Nov 2026.
- Official page Backs the answer.
- Official page Backs the answer.
- Official page Backs the answer.
- Prep guide Gives the question.
- Prep guide Gives the question.