ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Internal Tables →  Expressions and Functions for Internal Tables → 

table_exp - Table Expressions

Syntax

... itab[ itab_line ] ...

Effect

A table expression consists of an internal table itab, followed directly by a row (itab_line) specified in square brackets [ ]. The expression finds the specified row in the internal table and returns it as a result that can be used as follows:

The internal table itab must be specified directly using its name, a field symbol, or a dereferenced data reference as described under Reader Positions. In a table with header line, the table body is addressed and not the header line.

The structure component selector - can be used to access components of the row in question and direct chainings [ ... ][  ... ] of multiple table expressions. Table expression cannot yet, however, be specified on the left side of object component selector ->.

If the specified row is not found, a handleable expression of the class CX_SY_ITAB_LINE_NOT_FOUND is raised in all operand positions, except when

Notes

Example

The content of the component carrid of the row of the internal table carrier_tab is passed to the method get_spfli. In this table, the component carrname of the secondary key name has a specific value.

DATA carrier_tab TYPE HASHED TABLE OF scarr
                 WITH UNIQUE KEY carrid
                 WITH NON-UNIQUE SORTED KEY name COMPONENTS carrname.

SELECT * FROM scarr INTO TABLE carrier_tab.

TRY.
    DATA(flight_tab) = cl_demo_spfli=>get_spfli(
      carrier_tab[ KEY name
                   COMPONENTS carrname = 'United Airlines' ]-carrid ).
    cl_demo_output=>display( flight_tab ).
  CATCH cx_sy_itab_line_not_found.
    cl_demo_output=>display( `Nothing found` ).
ENDTRY.

Example

Here, the first calculation with table rows is a bad example of how to use table expressions. The same selection is made three times in the same statement. The second calculation shows how this can be avoided by using an assignment to a field symbol.

DATA itab TYPE TABLE OF i.
itab = VALUE #( ( 3 ) ( 5 ) ).

"Bad example
itab[ table_line = 3 ] =
  itab[ table_line = 3 ] * itab[ table_line = 3 ].

"Good example
ASSIGN itab[ table_line = 5 ] TO FIELD-SYMBOL(<fs>).
<fs> = <fs> * <fs>.

Examples

The program DEMO_TABLE_EXPRESSIONS shows further examples of how to use table expressions.

Exceptions

Catchable Exceptions

CX_SY_ITAB_LINE_NOT_FOUND




Continue
table_exp - itab_line
table_exp - Result
table_exp - Chainings
table_exp - Writer Positions