Ansicht
Dokumentation
ABENTABLE_COMPREHENSIONS - TABLE COMPREHENSIONS
General Material Data ABAP Short ReferenceThis documentation is copyright by SAP AG.
FOR - Table Comprehensions
Syntax
... NEW|VALUE type(
[let_exp]
FOR wa1|<fs1> IN itab1 [INDEX INTO idx1]
[cond1] [let_exp1]
FOR wa2|<fs2> IN itab2 [INDEX INTO idx2]
[cond2] [let_exp2] ...
( ... )
( ... ) ... ) ...
Addition:
Effect
These extended forms of the instance operator NEW and the value operator VALUE (for constructing internal tables) evaluate the rows of existing internal tables itab1, itab2, ... in one or more nested FOR loops and insert rows into the target table in the innermost FOR loop.
A FOR loop evaluates the internal table specified after IN sequentially in the same way as a LOOP loop. cond1, cond2, ... can be used to set conditions for the evaluation. The system field sy-tabix is not set. In each loop pass, the result is either assigned to a local work area wa1, wa2, ... or to a field symbol <fs1>, <fs2>, ... The work area or the field symbol is declared implicitly with the row type of the internal table and bound locally to the FOR loop as a subexpression of the full constructor expression. The same applies to the namespace and visibility as to the auxiliary fields declared in LET expressions.
As in NEW or VALUE, type can be used to specify a table type when constructing internal tables or the type can be derived using #. There must be at least one inner parenthesis specified in the innermost FOR and multiple inner parentheses can be specified in accordance with the rules that apply in regular construction of internal tables. The rows constructed using these inner parentheses are inserted in the tabular return value in each loop pass. The local work areas and field symbols visible in the inner parentheses can be used to construct the table rows.
As an option, LET expressions let_exp can be used to define local auxiliary fields for the full expression and for each FOR loop. The variables or field symbols declared in FOR loops are local in these loops. The local data from all outer FOR loops can be used when their values are defined.
Notes
- Similar concepts in many other languages are known as "List Comprehension".
- For tasks that can be solved with table comprehensions and also with special assignments for components (in particular the component operator CORRESPONDING), we recommend the use of assignments (see example).
- Instead of using directly specified internal tables itab1, itab2, table comprehensions can also be created using mesh paths, where FOR loops from both categories can be used together in the same constructor expression.
- Changes to the content of the internal table specified after IN within the FOR loop
can only be made using method calls. Deleting or replacing the table in full always produces a runtime error.
Addition
... INDEX INTO idx
Effect
In each loop pass of the associated FOR loop, this addition sets the auxiliary variable idx to the value to which the system field sy-tabix would be set in a corresponding LOOP loop. The auxiliary variable idx is declared implicitly with the type i and bound locally to the FOR loop as a subexpression of the full constructor expression. The same applies to the namespace and visibility as to the auxiliary fields declared in LET expressions.
Examples
See Examples of Table Comprehensions.
TXBHW - Original Tax Base Amount in Local Currency ROGBILLS - Synchronize billing plans
This documentation is copyright by SAP AG.
Length: 6223 Date: 20240424 Time: 211425 sap01-206 ( 94 ms )