cancel
Showing results for 
Search instead for 
Did you mean: 

Adding new line "TOTAL" after data group

Dio
Explorer
1,087

Hi Experts,

Name's Dio, I have a need to add a new line after the group data, that new line is the subtotal of the 'WRBTR' field. I've been looking for a way for 3 days and haven't found a way. Please help me to solved this, I appreciate any help.

Capture.JPG

Regards,
Dio

 

Sandra_Rossi
Active Contributor
If your requirement is to display the subtotal, don't do it in the internal table, do it in the display.
View Entire Topic
Uli75
Discoverer
0 Kudos
cl_salv_table=>factory( IMPORTING r_salv_table = DATA(lo_salv)
                        CHANGING t_table = lt_table ).

lo_salv->get_sorts( )->add_sort( columnname = 'LIFNR' subtotal = abap_true      sequence = if_salv_c_sort=>sort_up ).

lo_salv->get_aggregations( )->add_aggregation( columnname = 'WRBTR' aggregation = if_salv_c_aggregation=>total ).

lo_salv->display( ).

Quick solution to display the table with subtotals in an ALV...

 

Dio
Explorer
0 Kudos

Hi, 

Thank you for your answer friend, I got another way to do this. here's the code :

READ TABLE it_data INTO DATA(work_area2) INDEX 1.

  IF sy-subrc IS INITIAL.
    old_val = work_area2-znme1.
  ENDIF.

  LOOP AT it_data INTO work_area.

    IF work_area-znme1 <> old_val.
      new_line-znme1 = 'SUBTOTAL'.
      new_line-wrbtr = sum.
      INSERT new_line INTO it_data INDEX sy-tabix.
      CLEAR sum.
      old_val = work_area-znme1.
    ENDIF.

    sum = sum + work_area-wrbtr.
  ENDLOOP.

  data: v_lin type i.

  DESCRIBE TABLE it_data lines v_lin.
  READ TABLE it_data into data(work_area3) index v_lin.

  new_line-payment = 'GRAND TOTAL'.
  new_line-wrbtr = sum.
  INSERT new_line INTO it_data INDEX v_lin.

Regards,
Dio