Table expressions need a missing-row plan
A table expression such as dispatches[ dispatch_id = id ] is concise, but if no row matches it can raise CX_SY_ITAB_LINE_NOT_FOUND. Decide what absence means before using it.
Pick the behavior you need
IF line_exists( dispatches[ dispatch_id = id ] ).
DATA(found) = dispatches[ dispatch_id = id ].
ENDIF.
If you want one safe expression instead, VALUE ty_dispatch( dispatches[ ... ] OPTIONAL ) gives an initial structure when the line is absent. DEFAULT lets you provide a fallback structure. These choices do not tell you whether the initial value came from an actual row or from absence; use an explicit existence test when that distinction matters.
Repeated lookups may perform the search twice. For performance-sensitive code, read once into a variable and handle the result, or use an appropriate key-access statement. Check release availability for the exact additions in the target system.
Sources
- SAP Samples: Constructor Expressions — OPTIONAL and DEFAULT
- ABAP Keyword Documentation: table expressions
Developer practice · ABAP
Practice: provide a fallback for a missing row
Use a table expression to read dispatch D-1207 safely, returning an initial row rather than raising a missing-line exception.
This choice changes the output pattern checked here: WRITE belongs in a classic executable report, while out->write( ) uses the supplied output reference in an ABAP Cloud class-run method. It does not switch the language version of the other code; check release and API availability in your target system.
Complete the task and include the output statement shown for your selected environment. Variable names can differ if you use them consistently. This browser checker checks structure only; it does not compile or run ABAP.
0 required structures detected · 0 checks
Write your solution, then check its structure.
One possible solution
TYPES: BEGIN OF ty_dispatch,
dispatch_id TYPE string,
status TYPE string,
END OF ty_dispatch.
TYPES ty_dispatches TYPE HASHED TABLE OF ty_dispatch WITH UNIQUE KEY dispatch_id.
DATA(dispatches) = VALUE ty_dispatches( ( dispatch_id = 'D-1201' status = 'READY' ) ).
DATA(found) = VALUE ty_dispatch( dispatches[ dispatch_id = 'D-1207' ] OPTIONAL ).
DATA(result) = found-status.
WRITE result.out->write( result ).These are context-specific output examples. In your own program, use the result variable from your solution and the output mechanism available in that program.