Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Internal Tables →  Expressions and Functions for Internal Tables →  FOR - Table Iterations →  Examples of Table Comprehensions 

Table Comprehensions, Local Auxiliary Fields

This example demonstrates how local auxiliary fields are used in table comprehensions.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    TYPES:
      array TYPE TABLE OF i WITH EMPTY KEY,
      BEGIN OF line,
        col1 TYPE i,
        col2 TYPE i,
        col3 TYPE i,
      END OF line,
      itab TYPE TABLE OF line WITH EMPTY KEY.

    CONSTANTS factor TYPE i VALUE 1000.

    DATA(array) = VALUE array(
      ( 3 ) ( 5 ) ( 7 ) ( 9 ) ).

    DATA(itab) = VALUE itab(
      FOR x IN array INDEX INTO idx
         LET off = factor * idx IN
        ( col1 = x col2 = x * x col3 = x + off ) ).

    cl_demo_output=>display( itab ).

Description

From a single column table array, a three-column table itab is created whose column content is calculated from the respective row content in array. The local auxiliary fields in this example are the work area x of the FOR expression and the auxiliary field off defined in a LET expression.