SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Internal Tables → Expressions and Functions for Internal Tables → table_exp - Table Expressions →table_exp - Result
Syntax
... { itab[ itab_line ] }
| { VALUE type( itab[ itab_line ] ) }
| { REF type( itab[ itab_line ] ) } ...
Alternatives:
1. ... itab[ ... ]
2. ... VALUE type( itab[ ... ] )
3. ... REF type( itab[ ... ] )
Effect
If a table expression is specified in a general expression position or in a functional operand position, the read row can be passed to this position in three different ways:
The result of a table expression is only available temporarily. It is used as an operand of a statement and then deleted again. It is deleted when the current statements is closed or after the analysis of a relational expression once the logical value has been determined.
The alternative ways of specifying a table expression shown here define the method used to return the table row.
... itab[ ... ]
... VALUE type( itab[ ... ] )
Effect
Both alternatives can be specified in all reader positions for table expressions in which the row type matches the operand type (see also Chainings). The result is either a temporary field symbol, a temporary work area, or the value is assigned directly to a target variable.
In most cases, it is transparent (and irrelevant) whether the result is made available as a field symbol or as a work area. In some cases, however, performance reasons or side effects dictate that the standard behavior is suspended and data written explicitly to a temporary work area instead.
Notes
Example
The following program excerpt shows table expression with field symbols and work areas as a result.
CLASS class DEFINITION.
PUBLIC SECTION.
CLASS-METHODS meth IMPORTING p1 TYPE i OPTIONAL
p2 TYPE string OPTIONAL
p3 TYPE c OPTIONAL.
ENDCLASS.
CLASS class IMPLEMENTATION.
METHOD meth.
ENDMETHOD.
ENDCLASS.
TYPES text TYPE c LENGTH 1000.
DATA itab TYPE TABLE OF i.
DATA jtab TYPE TABLE OF string.
DATA ktab TYPE TABLE OF text.
FIELD-SYMBOLS <itab> TYPE INDEX TABLE.
START-OF-SELECTION.
itab = VALUE #( ( 1 ) ).
jtab = VALUE #( ( CONV string( sy-abcde ) ) ).
ktab = VALUE #( ( sy-abcde ) ).
DATA(number) = itab[ 1 ].
DATA(text) = VALUE #( jtab[ 1 ] ).
class=>meth( p1 = itab[ 1 ] ) ##operator.
class=>meth( p2 = VALUE #( jtab[ 1 ] ) ) ##operator.
class=>meth( p3 = VALUE #( ktab[ 1 ] ) ) ##operator.
ASSIGN itab TO <itab>.
class=>meth( p1 = <itab>[ 1 ] ).
Example
See Table Expressions, Side Effects for an example with a side effect.
... REF type( itab[ ... ] )
Effect
This alternative can be specified in all reader positions for table expressions in which a data reference variable with a suitable type is expected. If a table expression is used as an argument of a constructor expression with the reference operator REF, the result is a temporary data reference variable that points to the table row in question.
The static type of the reference variable is determined by specifying type for the constructor expression:
If the reference operator REF is specified in front of a chaining whose result is a component of a structured table row, it creates a reference to this component. In this case, no substring accesses +off(len) can be specified after the component.
Notes
Example
The following program is similar to the example for READ TABLE REFERENCE INTO, but the statement READ has been replaced by a table expression in the constructor expression REF.
PARAMETERS: p_carrid TYPE sflight-carrid,
p_connid TYPE sflight-connid,
p_fldate TYPE sflight-fldate.
DATA sflight_tab TYPE SORTED TABLE OF sflight
WITH UNIQUE KEY carrid connid fldate.
SELECT *
FROM sflight
INTO TABLE sflight_tab
WHERE carrid = p_carrid AND
connid = p_connid.
IF sy-subrc = 0.
TRY.
DATA(sflight_ref) =
REF #( sflight_tab[ KEY primary_key
COMPONENTS carrid = p_carrid
connid = p_connid
fldate = p_fldate ] ).
sflight_ref->price = sflight_ref->price * '0.9'.
CATCH cx_sy_itab_line_not_found.
...
ENDTRY.
ENDIF.