Skip to Content
author's profile photo Former Member
Former Member

Subtotals at the end of ALV Grid

Just like to ask how to group all the subtotals at the end of ALV GRID just before the total line?

The output should be somehow look like this:

Data1		GroupA		20.00
Data2		GroupA		10.00
Data3		GroupA		40.00
Data4		GroupB		20.00
Data5		GroupB		40.00
Subtotal(GroupA)		70.00
Subtotal(GroupB)		60.00
Total			       130.00

Thanks in advance!

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Feb 02, 2007 at 06:25 AM

    run this program & see whether it helps u

    type-pools: slis.

    data: it_spfli type table of spfli,

    it_fcat type slis_t_fieldcat_alv,

    wa_fcat like line of it_fcat,

    it_sort type slis_t_sortinfo_alv,

    wa_sort like line of it_sort.

    select * into table it_spfli from spfli.

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTING

    I_STRUCTURE_NAME = 'SPFLI'

    CHANGING

    CT_FIELDCAT = IT_FCAT.

    wa_fcat-do_sum = 'X'.

    modify it_fcat from wa_fcat

    transporting do_sum

    where fieldname = 'DISTANCE'.

    wa_sort-fieldname = 'CARRID'.

    wa_sort-subtot = 'X'.

    append wa_sort to it_sort.

    call function 'REUSE_ALV_GRID_DISPLAY'

    exporting

    • IS_LAYOUT = WA_LAYOUT

    it_fieldcat = it_fcat

    it_sort = it_sort

    tables

    t_outtab = it_spfli.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 02, 2007 at 09:56 AM

    Thanks for your reply but the output is still like the normal subtotals of ALV. What I like to do is to group all the subtotals together at the end of the ALV just before the total line.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi,

      I think this is not possible with standard alv functionality.

      When you have the final internal table ready to be output, you have to add those subtotal lines and total lines programatically.(Note that once you click the alv buttons for sorting and filtering..the layout would be a mess..so make sure you disable the standard alv buttons for sorting, totalling etc).

      sort itab by field1 group.

      loop at itab.

      at end of group.

      clear itab.

      sum.

      concatenate 'Subtotal(Group' itab-group into

      itab-field1.

      append itab.

      endat.

      endloop.

      Regards,

      Ravi

  • author's profile photo Former Member
    Former Member
    Posted on Feb 02, 2007 at 10:12 AM

    so you mean there is no way to do this using standard ALV functionality? I also consider your suggestion before, but because we need all the standard alv functionalities then I could not implement this.

    is there really no way to do this? what if i use OO ALV, would it be possible?

    Thanks!

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi,

      I'm not sure of OOPS Alv, but there is a method GET_SUBTOTALS n the class CL_GUI_ALV_GRID which would give only the subtotals lines. You can have a custom button on the alv toolbar, upon clicking which, you can shown the subtotals table in a popup. Try this alternative when there is no other way.

      Regards,

      Ravi

  • author's profile photo Former Member
    Former Member
    Posted on Feb 02, 2007 at 10:22 AM

    Do you have a sample code for this? Also, if i implement this, would it be possible that I could download it to Excel, do sorting, filtering and other ALV functionalities? Thanks!

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.