Skip to Content

How to change subtotal dinamically in ALV

Hi all,

I have this kind of problem. I'm using an ALV GRID for

displaying a set of document with different values in the column. I have set the first column as a checkbox to allow the user to check/uncheck a single line. The problem is that I want to sum only the line that is checked dinamically.

Can you give me any suggestions?

Thanks in advance


nb: I take look to the method 'set_table_for_first_display' but I don't find where the sum is calculated.

Message was edited by: Stefano Ferrarini

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 04, 2005 at 11:04 AM

    If SAP guys are listening , they will go crazy, looking at the flexibility requested from ALV from the posts in the past few days.

    Anyway, I am not sure whether this is possible, however I can suggest a workaround.

    <b>Option 1</b>

    a) Put a button 'Sum' in the ALV toolbar

    b) On clicking the 'Sum' button, open a new screen and display the records selected and the sum below.

    <b>Option 2</b>

    a) Put a button 'Sum' in the ALV toolbar

    b) On clicking the 'Sum' button,

    1) Find all the records selected by the user

    2) Remove the unselected entries from the table

    3) Change the fieldcatalog accordingly with do_sum = 'X'

    4) call the method refresh_display

    If you found a way better than this, do share.


    Subramanian V.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 04, 2005 at 02:36 PM

    Hi Subramanian,

    thank you for your kindly help.

    After I put my questions I thought I was a little paranoid about constructing this dynpro but now I try to find an elegant solution.

    Corncerning your first option I prefer to don't open a new screen.

    In the second solution there is the problem that if I uncheck a line I can't check it back (because it's not visible).

    I was looking for a solution using the method get_subtotals or a modification of it but I think it's very hard.

    Now I'm working at this application using only a little part of my time but if I find a good solution I post it directly in this forum.

    If anyone have any other suggestions...

    Thanks a lot


    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      I will use Subramanian's idea in regard to adding a SUM button, to provide another option.

      Assume FIELD1 is the field that you want to sum on based on the checkbox indicator. Add an additional field to your internal table, I will call it FIELD1_SUM, defined LIKE FIELD1. Consider suppressing zero display so that a zero value displays as spaces.

      On first display, I assume all checkboxes are unchecked, so FIELD1 will have values, FIELD1_SUM will be zero, and a total is presented on FIELD1_SUM that intially is zero.

      The user can use your checkbox to indicate which numbers to sum. After the user sets the checks, your new SUM button is hit.

      The hit of the new SUM button should invoke the following logic:

      1. LOOP at internal table.

      2. For each row, if checkbox is set, move FIELD1 to FIELD1_SUM.

      3. For each row, if checkbox is NOT set, set FIELD1_SUM to zero.

      Refresh the ALV grid display with the new data and you should now have a new total of FIELD1_SUM for only the checkboxed fields.

      You can also consider making FIELD1 a hotspot and every time the user hits the hotspot, the value is added/removed from the total of FIELD1_SUM. You could add an S type message to tell the user what happened.

      Lot of missing details here but hopefully you get the idea. Does this meet your needs?

  • Posted on Jan 05, 2005 at 04:54 PM

    Hi all,

    thanks Subramanian, Charles and Christian for your useful suggestions. Finally I decided to implement this solution (really it's a workaround but I think it's good).

    In my case I've 3 different fields with values:document value, interest value and total. Merging all the solution proposed I've add an extra column with a flag and I've clear the column of interest and total when I uncheck a row (and refill with the initial value if I recheck).

    Using standard totals only in the second and third column (interest an total) I realize that layout:

    - if a user check a document (row) the interest and total column were valorized and totals increase;

    - if a user uncheck a document (row) the interest and total column were cleared and totals decrease;

    Thank you very much for your collaboration


    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.