table_exp - Result
ABAP Syntax ... { itab[
itab_line ] }
| { VALUE type( itab[ itab_line ]
) }
| { REF type( itab[ itab_line ]
) } ...
ABAP_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:
As a field symbol to which the table row
is assigned.
As a work area that contains the content of
the table row.
As a data reference variable
that points to the table row.
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.
ABAP_ALTERNATIVE_1 ... itab[ ... ]
ABAP_ALTERNATIVE_2 ... 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.
If the table expression is not specified as an operand of the value
operator VALUE or of the
reference operator REF ,
the result is usually a temporary field symbol typed with the row type
of the internal table and to which the table row in question is
assigned. For performance reasons, there are exceptions to this rule in
the following cases:
If the table expression is specified as the right side of an
assignment , the content of the table row or
a component is assigned directly to the
target variable instead of a temporary result being produced.
If the row type of the internal table is flat and thin and used directly
in the operand position (for example as an operand of an arithmetic
expression or as a formal parameter for an actual parameter where pass
by value is declared), the result is a temporary work area.
If the table expression is specified as an operand of the value operator
VALUE , the result is
always a temporary work area, except if the expression is specified as
the right side of an assignment . The data
type of the work area is determined by specifying
type for the constructor
expression:
If the # character is specified for type and the data type
required in an operand position can be identified uniquely and
completely, the operand type is used. Otherwise the row type of the
internal table is applied.
If a non-generic data type dtype is specified for type ,
the row type of the internal table must be compatible with this data
type or be convertible to this data type. In this case, the temporary
work area has the data type dtype and the data of the row in
question is converted to this data type, if necessary, in accordance
with the conversion rules .
If the expression is specified as the right side of an
assignment , the content of the table row or
component is also assigned directly when
using VALUE .
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.
For notes about performance, see the programming guideline
Output Behavior . This guideline should
also be respected when using table expressions. In the
extended program checks , a
syntax check warning (which can hidden using a pragma) is produced if
there is an obvious violation of the rule.
Side effects can occur if the row of the internal table to which the
temporary field symbol points is modified while the binding to the field
symbol persists.
Notes
A table expression whose result is a temporary field symbol can be
viewed as a short form of the statement READ
TABLE with the addition ASSIGNING
an table expression whose result is a temporary work area can be
viewed as a short form of this statement with the addition
INTO . The corresponding rules and
notes apply.
In variant 1, the compiler decides whether the result is a field symbol
or a work area, not the table content at runtime.
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 ] ).
Temporary work areas are passed in the assignments to number and
text . The VALUE operator of the second assignment
expresses this explicitly, but is not necessary.
In the passes to the formal parameter of the method meth , the
results are temporary field symbols by default. In two cases, the
VALUE operator forces a work area explicitly. In the extended program
checks, all passes produces syntax check warnings that can be hidden
here using the pragma ##operator .
In the pass to the formal parameter p1 , using a field symbol by
default is bad for performance, since the row is a flat thin table row.
The VALUE operator is recommended instead.
In the pass to the formal parameter p2 , specifying a work area
explicitly is bad for performance, since the row is a deep table row.
The VALUE operator is not recommended here.
In the pass to the formal parameter p3 , specifying a work area
explicitly is bad for performance, since the row is a wide table row.
The VALUE operator is not recommended here.
When specifying the internal table using a generically typed field
symbol itab , using the temporary field symbol by default does not
produce a syntax check warning, since no fixed work area can be derived
here.
Example
See Table Expressions, Side Effects
for an example with a side effect.
ABAP_ALTERNATIVE_3 ... 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 # character is specified for type , the row type of
the internal table is used as the static type.
If a non-generic data type dtype or the generic data type
data is specified for type
, they determine the static type of the result. A non-generic data
type, dtype , must be compatible with the row type of the internal
table.
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
A table expression whose result is a temporary data reference variable
can be viewed as a short form of the statement
READ TABLE with the addition
REFERENCE INTO . The corresponding rules and notes apply.
The static type of the temporary data reference variable can only be the
row type of the internal table or be fully generic.
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.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved