Application Development 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: 

How to make the ALV report in groups and caluculate the TOTALS

Former Member
0 Kudos

Hi

In my ALV report output .I have to group the output based on the DAYS field

0-10 days in one group

10-30 days in one group

above 30 days one group

There is also a field by name "AMOUNT" in my output.

I have to calculate SUBTOTALs at the end of every group and at the end of the report i should caluculate GRAND TOTAL.

Please remember that i should not use any any BLOCKED ALVs and for Totals i should not use the SYMBOLS provided in the application toolbar of the report

Thanks in Advance

2 REPLIES 2

naimesh_patel
Active Contributor
0 Kudos

Take on more field in your internal table say GRP (for group).

Now, based on your condition fill this field GRP.

LOOP AT IT_OUT.
  IF IT_OUT-DAY > 0 AND IT_OUT < 10.
    IT_OUT-GRP = 1.
  ELSEIF IT_OUT-DAY > 10 AND IT_OUT < 30.
    IT_OUT-GRP = 1.
  ELSEIF IT_OUT-DAY > 30.
    IT_OUT-GRP = 1.
  ENDIF.
  MODIFY IT_OUT.
  CLEAR IT_OUT.
ENDLOOP.

Set DO_SUM = 'X' in your fildcatalog for the AMOUNT field.

Now, fill the IT_SORT table which can be passed to your ALV.

DATA: t_sort TYPE slis_t_sortinfo_alv.
DATA: ls_sort TYPE slis_sortinfo_alv.

  ls_sort-fieldname = 'GRP'.
  ls_sort-spos = 1.
  ls_sort-up = 'X'. 
  ls_sort-sub_tot = 'X'.  " << For subtotal
  ls_sort-group = '*'.   " << this will make the group.
  APPEND ls_sort TO xt_sort.
  CLEAR ls_sort.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = l_repid
      i_callback_top_of_page  = c_formname_top_of_page
      i_callback_user_command = c_user_command
      i_save                  = 'A'
      is_variant              = i_variant
      it_sort                 = xt_sort   " << sort table
      it_fieldcat             = t_fieldcat[]
    TABLES
      t_outtab                = t_output
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.

Regards,

Naimesh Patel