B.3Internal Tables

Traditionally, READ TABLE statements were used to access the content of internal tables, which facilitated the use of a key or line index to read individual lines.

This can be done using expressions that you assign directly or process further. Listing B.7 shows an example of such use.

DATA: lt_carrier TYPE TABLE OF scarr WITH KEY carrid.
lt_carrier = VALUE #(
( carrid = 'AA' carrname = 'American Airlines' )
( carrid = 'LH' carrname = 'Lufthansa' ) ).

" Read first entry from the internal table
DATA(ls_carrier) = lt_carrier[ 1 ].

" Access with a key and use of an
" attribute
DATA(lv_name) = lt_carrier[ carrid = 'LH' ]-carrname.

Listing B.7Expressions for Access to Internal Tables

These expressions also facilitate direct access in the case of multidimensional structures, that is, if an internal table in a column also contains a table.

As is the case with constructor expressions, you should always bear performance in mind and avoid unnecessary accesses with expressions for internal tables. The following example demonstrates unfavorable usage of table expressions because the same line is read multiple times. Instead, you should temporarily store the line in a variable.

DATA(lv_carrid) = lt_carrier[ 1 ]-carrid.
DATA(lv_carrname) = lt_carrier[ 1 ]-carrname.