Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Obsolete Language Elements →  Obsolete Processing of Internal Data →  Obsolete Extracts →  Examples of Extracts 

Extracts - Ascertaining Numbers and Totals

This example demonstrates how numbers and totals are ascertained in extracts.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    INSERT t2 t1 INTO header.

    t1 ='AABB'. t2 = 1. EXTRACT test.
    t1 ='BBCC'. t2 = 2. EXTRACT test.
    t1 ='AAAA'. t2 = 2. EXTRACT test.
    t1 ='AABB'. t2 = 1. EXTRACT test.
    t1 ='BBBB'. t2 = 2. EXTRACT test.
    t1 ='BBCC'. t2 = 2. EXTRACT test.
    t1 ='AAAA'. t2 = 1. EXTRACT test.
    t1 ='BBBB'. t2 = 1. EXTRACT test.
    t1 ='AAAA'. t2 = 3. EXTRACT test.
    t1 ='AABB'. t2 = 1. EXTRACT test.

    SORT BY t1 t2.

    DATA(out) = cl_demo_output=>new( ).

    LOOP.

      out->write( |{ t1 } { t2 }| ).

      AT END OF t2.
        out->line( ).
        out->write( |Sum: { sum(t2) }| ).
        out->line( ).
      ENDAT.

      AT END OF t1.
        out->write( |Different values: { cnt(t1) }| ).
        out->line( ).
      ENDAT.

      AT LAST.
        out->line( ).
        out->write( |Sum: { sum(t2) }| ).
        out->write( |Different values: { cnt(t1) }| ).
      ENDAT.

    ENDLOOP.

    out->display( ).

Description

An example extract is created that contains only fields from the header field group. After sorting, the contents of the data set, as well as the numbers from the different fields t1 and the sum of the fields t2, are output at the end of every control level and at the end of the loop.