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.
If no chaining is specified, the whole row is returned as the result of the corresponding row type.
A table expression can be specified as a writable expression in
result positions. Once found, the row in question can be modified directly here.
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
a table expression is used in the statement ASSIGN, where sy-subrc is set to the value 4,
when used in the predicate function line_exists, where the truth value "false" is returned,
when used in the table function line_index, where the value 0 is returned.
Notes
In table expressions, the empty square brackets [] cannot be specified behind itab. In other operand positions, these empty brackets distinguish the table body from
header lines.
Functions and constructor expressions cannot currently be specified for itab, but the table expressions shown under
Chainings are possible.
A table expression cannot be followed directly by a
specified offset/length+off(len), but this is possible after a
chaining whose final place is a suitable structure component after a structure component selector.
Duplicate selections (multiple reads performed on the same row of an internal table in different
expressions) must be avoided. In these cases, a selection should be made before the statement and the result referenced by a field symbol or reference variable.
The exception class CX_SY_ITAB_LINE_NOT_FOUND contains attributes for
displaying the row number in the index or key used when a row cannot be accessed. If only index accesses
are used in statements with multiple table expressions, it is not possible to distinguish which expression was unsuccessful.
Each table expression can be view as a short form for a variant of the statement READ TABLE that enables reads to be performed on rows of internal tables in operand positions.
In writing positions, the same restrictions with respect to modifying key fields apply to table expressions whose
result is a field symbol or temporary reference
variable as to other field symbols or data reference variables that point to rows of internal tables.
More specifically, table expressions that return a row of a sorted table or hashed table to writing
positions (like the left side of an assignment) or as actual parameters for output parameters always raise an exception.
Unlike READ TABLE, a table
expression does not modify the value of the system field sy-tabix (except
when used in the statement ASSIGN).
Like the statement READ TABLE,
a table expression is a single row read. If multiple rows of an internal table are to be read, the statement
LOOP or a FOR expression generally displays better performance than using table expressions in a loop.
Mesh path expressions are a special form of table expression that can be used in exactly the same way as table expressions.
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 keyname has a specific value.
DATA carrier_tab TYPE HASHED TABLE OF scarr WITH UNIQUE KEY carrid
WITH NON-UNIQUE SORTED KEY name COMPONENTS carrname.
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 ) ).