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

table_exp - Table Expressions

Syntax

... itab[ itab_line ][-comp|[ ... ]|->comp] ...

Effect

A table expression consists of an internal table itab, followed directly by a row (itab_line) specified in square brackets [ ]. A chaining -comp|[ ... ]|->comp can be appended to this row.  The expression searches for the specified row in the internal table.

The result of a table expression 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 Reading Positions. In a table with header line, the table body is addressed and not the header line.

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

Handleable Exceptions

CX_SY_ITAB_LINE_NOT_FOUND



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