An official SAP presentation discussing new ABAP programming features in NetWeaver 7.4 (CD261) makes a big deal about table expressions, replacing the old syntax to read from an internal table:
READ TABLE lt_aufk INTO ls_aufk WITH KEY aedat = sy-datum.
lv_order = ls_aufk-aufnr.
with a single-line lv_order = lt_aufk[ aedat = sy-datum ]-aufnr.
However, it fails to mention that if a table expression fails to find a line it will raise exception CX_SY_ITAB_LINE_NOT_FOUND
, so really that notation should actually be:
TRY.
lv_order = lt_aufk[ aedat = sy-datum ]-aufnr.
CATCH cx_sy_itab_line_not_found.
ENDTRY.
Which is both longer and makes any simple read logic look incredibly complex and hard to read. Since every individual read might need to fail or succeed individually this quickly balloons out of proportion:
TRY.
wa1 = lt_itab[ col1 = ... ].
CATCH cx_sy_itab_line_not_found.
ENDTRY.
TRY.
wa2 = lt_itab[ col2 = ... ].
CATCH cx_sy_itab_line_not_found.
ENDTRY.
TRY.
wa3 = lt_itab[ col3 = ... ].
CATCH cx_sy_itab_line_not_found.
ENDTRY.
TRY.
wa4 = lt_itab[ col4 = ... ].
CATCH cx_sy_itab_line_not_found.
ENDTRY.
TRY.
wa5 = lt_itab[ col5 = ... ].
CATCH cx_sy_itab_line_not_found.
ENDTRY.
Is there any way to improve the readability of these table expressions? Am I using them improperly?