table_exp - Chainings
The structure component selector - can be used to chain table
expressions directly with other table expressions.
If the constructor operator VALUE or REF is specified
before a chaining to control the result ,
only the final result is affected. Any intermediate results are always
temporary field symbols and the corresponding performance notes should
be read.
Note
Chainings of table expressions with functional methods (specifying the
internal table as a functional method call, reading the internal table
using chained attribute reads, and specifying an object component
selector - on the right of a table expression) are not yet
possible.
Example
The following example demonstrates two ways of bypassing the current
restriction specifying that a table expression cannot be positioned
directly in front of - . In the first case, the helper variable
oref is introduced. The second case requires an additional
operation, but no helper variables.
DATA itab TYPE TABLE OF REF TO class.
DATA(oref) = itab[ idx ].
oref->meth( ).
CAST class( itab[ idx ] )- meth( ).
Chainings with the Structure Component Selector
A table expression can be chained as follows using the structure
component selector - :
If the result of a table expression itab[ ... ] is a structure,
the structure component selector can be used to read each component
comp of the structure:
... itab[ ... ]-comp ...
If comp has a suitable type, a
specified offset/length
+off(len) can be appended, except when
the chaining is used as a memory
area of the statement ASSIGN or as an argument of the
reference operator REF .
If a structure struct has a table-like component comp , it
can be used as the name of the internal table of a table expression:
... struct-comp[ ... ] ...
Both of these alternatives can be combined, enabling a structured
component selector to be located directly on the left and right of a
table expression.
Note
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.
Example
Reads the first column of the second row of the table-like second
component of the first row of the internal table itab . The result
is 4.
TYPES: BEGIN OF struct1,
col1 TYPE i,
col2 TYPE i,
END OF struct1,
tab1 TYPE TABLE OF struct1 WITH EMPTY KEY,
BEGIN OF struct2,
col1 TYPE i,
col2 TYPE tab1,
END OF struct2,
tab2 TYPE TABLE OF struct2 WITH EMPTY KEY.
DATA(itab) =
VALUE tab2(
( VALUE struct2( col1 = 1
col2 = VALUE tab1(
( VALUE struct1( col1 = 2
col2 = 3 ) )
( VALUE struct1( col1 = 4
col2 = 5 ) ) ) ) )
( VALUE struct2( col1 = 6
col2 = VALUE tab1(
( VALUE struct1( col1 = 7
col2 = 8 ) )
( VALUE struct1( col1 = 9
col2 = 10 ) ) ) ) ) ).
DATA(num) = itab[ 1 ]-col2[ 2 ]-col1.
Example
See Table Expressions, Chainings
for a further example.
Chainings with Table Expressions
If the result of a table expression itab[ ... ] is an internal
table, it can be used as the name of the internal table of a table
expression:
... itab[ ... ][ ... ] ...
An expression of this type can
continue itself with square brackets ( [ ... ] ) if its result is
again table-like,
combined with the information from structure component selectors above.
Example
In an internal table nested twice, reads the first row of the innermost
table in the second row of the center table in the second row of the
outermost table. The result is 7.
TYPES: tab1 TYPE TABLE OF i WITH EMPTY KEY,
tab2 TYPE TABLE OF tab1 WITH EMPTY KEY,
tab3 TYPE TABLE OF tab2 WITH EMPTY KEY.
DATA(itab) = VALUE tab3(
( VALUE tab2(
( VALUE tab1(
( 1 )
( 2 ) ) )
( VALUE tab1(
( 3 )
( 4 ) ) ) ) )
( VALUE tab2(
( VALUE tab1(
( 5 )
( 6 ) ) )
( VALUE tab1(
( 7 )
( 8 ) ) ) ) ) ).
DATA(num) = itab[ 2 ][ 2 ][ 1 ].
Example
Direct chaining of table expressions and chaining with the structure
component selector in a single expression. Reads the structure component
of the innermost nested table with the value 13.
TYPES: BEGIN OF struct1,
col1 TYPE i,
col2 TYPE i,
END OF struct1,
tab1 TYPE TABLE OF struct1 WITH EMPTY KEY,
BEGIN OF struct2,
col1 TYPE i,
col2 TYPE TABLE OF tab1 WITH EMPTY KEY,
END OF struct2,
tab2 TYPE TABLE OF struct2 WITH EMPTY KEY.
DATA(itab) =
VALUE tab2(
( VALUE struct2(
col1 = 1
col2 = VALUE #(
( VALUE tab1(
( VALUE struct1(
col1 = 2
col2 = 3 ) )
( VALUE struct1(
col1 = 4
col2 = 5 ) ) ) )
( VALUE tab1(
( VALUE struct1(
col1 = 6
col2 = 7 ) )
( VALUE struct1(
col1 = 8
col2 = 9 ) ) ) ) ) ) )
( VALUE struct2(
col1 = 10
col2 = VALUE #(
( VALUE tab1(
( VALUE struct1(
col1 = 11
col2 = 12 ) )
( VALUE struct1(
col1 = 13
col2 = 14 ) ) ) )
( VALUE tab1(
( VALUE struct1(
col1 = 15
col2 = 16 ) )
( VALUE struct1(
col1 = 17
col2 = 18 ) ) ) ) ) ) ) ).
DATA(num) = itab[ 2 ]-col2[ 1 ][ 2 ]-col1.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved