Skip to content

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

Internal Table, Grouping with FOR for Sorts

This example demonstrates sorts with FOR expressions.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    TYPES itab TYPE STANDARD TABLE OF string WITH EMPTY KEY.

    DATA(itab) =
      VALUE itab( ( `d` ) ( `B` ) ( `D` ) ( `b` ) ( `a` )
                  ( `D` ) ( `a` ) ( `C` ) ( `A` ) ( `c` ) ).
    cl_demo_output=>write( itab ).

    DATA jtab TYPE itab.
    jtab = VALUE #( FOR GROUPS <grp1> OF <line> IN itab
                        GROUP BY to_upper( <line> ) ASCENDING
                    FOR GROUPS <grp2> OF <mbr1> IN GROUP <grp1>
                        GROUP BY <mbr1> DESCENDING
                    FOR <mbr2> IN GROUP <grp2> ( <mbr2> ) ).
    cl_demo_output=>display( jtab ).

Description

This example works in the same way as the executable example for sorts across groupings using LOOP. Here, all groupings are collected in a single expression using three FOR expressions.