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 Reductions 

Table Reductions, Method Calls

This example demonstrates a reduction of the columns of an internal table to an object.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA carriers TYPE TABLE OF scarr.
    SELECT * FROM scarr INTO TABLE @carriers.

    DATA out TYPE REF TO if_demo_output.
    out = REDUCE #(
            INIT o = cl_demo_output=>new( )
            FOR wa IN carriers
            NEXT o = o->write( to_string( wa ) ) ).
    out->display( ).

Description

In this example, a call of a method to_string transforms the rows of the internal table carriers after the FOR expression to a text string. This string is then passed to the instance method WRITE of an object of the class CL_DEMO_OUTPUT. This object is created after INIT and referenced by the local reference variable o. The return value of the method WRITE returns a reference to its own object, which means that the assignment to o does not modify its value but does meet the syntax rule that o must be filled. At the end of processing, the reference to the object in o is assigned to the reference variable out and the content of the internal table written to the object can be displayed using the method DISPLAY.