ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Assignments → Assigning Components → Assigning Components: Examples
Component Operator, Comparison with FOR Expression
This example compares the component operator with table comprehensions,
Other versions:
7.31 | 7.40 | 7.54
Source Code
DATA(iterations) = 10.
in->request( CHANGING field = iterations ).
DO iterations TIMES.
DATA t1 TYPE i.
GET RUN TIME FIELD DATA(t11).
result1 = CORRESPONDING #(
itab MAPPING carrier = carrid
connection = connid
departure = cityfrom
destination = cityto ).
GET RUN TIME FIELD DATA(t12).
t1 = t1 + t12 - t11.
DATA t2 TYPE i.
GET RUN TIME FIELD DATA(t21).
result2 = VALUE #( FOR wa IN itab ( carrier = wa-carrid
connection = wa-connid
departure = wa-cityfrom
destination = wa-cityto ) ).
GET RUN TIME FIELD DATA(t22).
t2 = t2 + t22 - t21.
DATA t3 TYPE i.
GET RUN TIME FIELD DATA(t31).
result3 = VALUE #( FOR wa IN itab (
CORRESPONDING #(
wa MAPPING carrier = carrid
connection = connid
departure = cityfrom
destination = cityto ) ) ).
GET RUN TIME FIELD DATA(t32).
t3 = t3 + t32 - t31.
ENDDO.
IF result1 = result2 AND result1 = result3.
out->write(
|CORRESPONDING: {
CONV decfloat16( t1 / iterations )
WIDTH = 10 ALIGN = RIGHT } Microseconds\n| &&
|FOR: {
CONV decfloat16( t2 / iterations )
WIDTH = 10 ALIGN = RIGHT } Microseconds\n| &&
|FOR CORRESPONDING: {
CONV decfloat16( t3 / iterations )
WIDTH = 10 ALIGN = RIGHT } Microseconds\n|
)->line(
)->display( result1 ).
ELSE.
out->display( `What?` ).
ENDIF.
Description
The columns of an internal table can be assigned to columns with different names in a different table in three different ways:
- Constructor expression with component operator
CORRESPONDING
and mapping rule
- Explicit assignment of the individual components behind a
FOR
expression of a table comprehension.
FOR
expression with evaluation of a constructor expression with component operator for each row.
Each method provides the same results. The component operator is quicker than the table comprehension when there are more than approximately 10 iterations. Using the component operator for each row is always the slowest solution.