Internal Tables
ABAP DevelopmentIntermediate

READ TABLE, sy-subrc and Modern Table Expressions

Learn safe read patterns using READ TABLE, TRANSPORTING NO FIELDS, line_exists and table expressions.

Explanation

READ TABLE is used to find a row in an internal table. After READ TABLE, sy-subrc tells whether a matching row was found. If sy-subrc is not checked, the program may process old or initial data and create wrong output. When you only need to check whether a row exists, READ TABLE ... TRANSPORTING NO FIELDS is better than reading the full row. Modern ABAP provides line_exists( ) and table expressions such as itab[ key = value ]. These make code shorter, but direct table expressions must be used carefully because they can raise an exception if the row does not exist.

Code example

ABAP Code
READ TABLE lt_blocked_customers TRANSPORTING NO FIELDS  WITH KEY kunnr = lv_kunnr. IF sy-subrc = 0.  lv_blocked = abap_true.ENDIF. IF line_exists( lt_blocked_customers[ kunnr = lv_kunnr ] ).  lv_blocked = abap_true.ENDIF.

Real project scenario

In an order validation enhancement, the program checks whether a customer exists in a blocked customer list. If only existence is needed, TRANSPORTING NO FIELDS or line_exists( ) is cleaner than reading the full row.

Common mistakes

- Not checking sy-subrc after READ TABLE. - Using table expression without handling missing row. - Reading full row when only existence check is needed. - Using old values from work area after failed READ TABLE.

Best practices

- Use TRANSPORTING NO FIELDS for existence checks. - Use line_exists for readable existence checks. - Use table expressions carefully when missing rows are possible. - Clear or avoid stale work areas.

Interview angle

Interviewers may ask why old READ TABLE is still used when modern expressions exist. A mature answer explains safety, readability and exception behavior.