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:
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( ).