Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

CL SALV aggregation doesn't work

Anandkarna123
Discoverer
0 Likes
3,273

The aggregation was not working on my main program, so I decided to write another dummy program to see if it works there or not. Turns out, it doesn't. I have gone through every discussion and cannot seem to find the solution. The total doesn't appear at the end of the column which technically, it should. 

Here is the code:

 

REPORT z_test_salv_aggregation.

TYPES: BEGIN OF ty_data,
         menge TYPE i, " Using integer for quantity
       END OF ty_data.

DATA: it_test      TYPE TABLE OF ty_data,
      wa_test      TYPE ty_data,
      lo_alv_table TYPE REF TO cl_salv_table,
      lo_agg       TYPE REF TO cl_salv_aggregations,
      lo_functions TYPE REF TO cl_salv_functions_list.

* Sample data
wa_test-menge = 10. APPEND wa_test TO it_test.
wa_test-menge = 20. APPEND wa_test TO it_test.
wa_test-menge = 30. APPEND wa_test TO it_test.

* Create the ALV Table
TRY.
    cl_salv_table=>factory(
      IMPORTING
        r_salv_table = lo_alv_table
      CHANGING
        t_table      = it_test
    ).
  CATCH cx_salv_msg INTO DATA(lx_msg).
    WRITE: / 'Error creating ALV table:', lx_msg->get_text( ).
    RETURN.
ENDTRY.

* Get the Functions object and activate all functions
lo_functions = lo_alv_table->get_functions(  ).
lo_functions->set_all( 'X' ).

lo_agg = lo_alv_table->get_aggregations(  ).
  TRY.
      CALL METHOD lo_agg->add_aggregation
        EXPORTING
          columnname  = 'MENGE'
          aggregation = if_salv_c_aggregation=>total.
    CATCH cx_salv_data_error cx_salv_not_found cx_salv_existing INTO DATA(lx_error).
  ENDTRY.

* Display the ALV Table
lo_alv_table->display( ).

 

 

The aggregation was not working on my main program, so I decided to write another dummy program to see if it works there or not. Turns out, it doesn't. I have gone through every discussion and cannot seem to find the solution. The total doesn't appear at the end of the column which technically, it should. 

Here is the code:

 

REPORT z_test_salv_aggregation.

TYPES: BEGIN OF ty_data,
         menge TYPE i, " Using integer for quantity
       END OF ty_data.

DATA: it_test      TYPE TABLE OF ty_data,
      wa_test      TYPE ty_data,
      lo_alv_table TYPE REF TO cl_salv_table,
      lo_agg       TYPE REF TO cl_salv_aggregations,
      lo_functions TYPE REF TO cl_salv_functions_list.

* Sample data
wa_test-menge = 10. APPEND wa_test TO it_test.
wa_test-menge = 20. APPEND wa_test TO it_test.
wa_test-menge = 30. APPEND wa_test TO it_test.

* Create the ALV Table
TRY.
    cl_salv_table=>factory(
      IMPORTING
        r_salv_table = lo_alv_table
      CHANGING
        t_table      = it_test
    ).
  CATCH cx_salv_msg INTO DATA(lx_msg).
    WRITE: / 'Error creating ALV table:', lx_msg->get_text( ).
    RETURN.
ENDTRY.

* Get the Functions object and activate all functions
lo_functions = lo_alv_table->get_functions(  ).
lo_functions->set_all( 'X' ).

lo_agg = lo_alv_table->get_aggregations(  ).
  TRY.
      CALL METHOD lo_agg->add_aggregation
        EXPORTING
          columnname  = 'MENGE'
          aggregation = if_salv_c_aggregation=>total.
    CATCH cx_salv_data_error cx_salv_not_found cx_salv_existing INTO DATA(lx_error).
  ENDTRY.

* Display the ALV Table
lo_alv_table->display( ).

 

 

8 REPLIES 8
Read only

Sandra_Rossi
Active Contributor
3,251

It does work.

Sandra_Rossi_0-1729055795861.png

 

Read only

0 Likes
3,249

Hey, thanks for your reply. As you can see in the image below, the sum is not shown. Could this be a version problem or something like that?

Anandkarna123_0-1729056015351.png

 

Read only

0 Likes
3,246

Of course. Optionally use "ALV SOS" to identify the cause (search the Web).

Read only

0 Likes
3,228

yeah, I did the consistency check. It shows this

Anandkarna123_0-1729057272562.pngAnandkarna123_1-1729057288676.png

What does this mean? 

Read only

0 Likes
3,165

It doesn't concern your total issue.

What it means:

Sandra_Rossi_0-1729060048134.png

Sandra_Rossi_1-1729060119843.png

Read only

Sandra_Rossi
Active Contributor
0 Likes
3,150

You didn't indicate your ABAP version.

Try with type P instead of I.

 

Read only

RaymondGiuseppi
Active Contributor
3,148

I copied your code and it worked on my ECC and S/4HANA systems, can you check that you didn't define a default display variant and/or execute the ALV consistency check on your system?

raymond_giuseppi_0-1729062067858.png

 

Read only

0 Likes
3,134

Also MENGE is usually a quantity field, so associated to a unit of measure field, add this uom field to the displayed structure (or define as a constant in field catalog) and insure the link is correct, so ALV will not sum add meters and litters.

  • CL_SALV_COLUMN->SET_QUANTITY or SET_QUANTITY_COLUMN