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

How to add a subtotal line in a table control?

Hello expert,

could you please tell me how to create a subtotal line in a table control, that can automatically give the total of some specific numric columns? (just like ALV)

thanks and best regards.

Jun

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jul 12, 2004 at 07:57 AM

    any help / hints are highly appreciated.

    we are facing this issue right now, we find it's very hard to build a sub title line of a table control.

    we have to calculate the totals and append another small table below the table and put the total numbers into it.

    is there any good idear?

    best regards.

    netz

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 12, 2004 at 09:41 PM

    Hi Net Zilla,

    I don't know if I can help you, but how are you populating the data in the table? I presume it's from some context.

    How much data are you looking at summing up?

    Message was edited by: Michael Phorn

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Dear Michael Phorn,

      the table is populated from context which is read from r3 using rfc.

      I assume that the row number is less than 20.

      there are several columns need to do summary at the same time.

      Looking forward to your reply.

      best regards.

      netz

  • author's profile photo Former Member
    Former Member
    Posted on Jul 13, 2004 at 06:30 AM

    Hi Jun,

    assume a value node A to which the table's dataSource is bound. A has two value attributes C1 and C2, type integer. You want to display the summarized value of C2. The cell editors are TextViews:

    1. Add a boolean attribute "VIsSumLine" to A.

    2. Add a readonly attribute "VNoSumColumnVisible", type Visibility, to A. Set calculated to true and insert the following code lines into the calculated getter:

    if (element.getVIsSumLine()) {
      return WDVisibility.BLANK;
    } else {
      return WDVisibility.VISIBLE;
    }

    3. Add a readonly attribute "VSumCellTextViewDesign", type TextViewDesign to A. Set calculated to true and insert the following code lines into the calculated getter:

    if (!element.getVIsSumLine()) {
      return WDTextViewDesign.STANDARD;
    } else {
      return WDTextViewDesign.EMPHASIZED;
    }

    This will display the sum cells bold lateron.

    4. Bind the C1_editor-visible property to A.VNoSumColumnVisible.

    5. Bind the C2_editor-design property to A.VSumCellTextViewDesign.

    6. Context filling for testing (in wdDoInit() of the view controller for example):

    int sumC2 = 0;
    for (int ix = 0; ix < 10; ix++) {
      sumC2 += ix * 20;
    
      I<YourView>.IAElement el = wdContext.nodeA().createAElement();
      el.setC1(ix * 10);
      el.setC2(ix * 20);
      el.setVIsSumLine(false);
      wdContext.nodeA().addElement(el);
    }
    /* Add the sum line */
    I<YourView>.IAElement el = wdContext.nodeA().createAElement();
    el.setC2(sumC2);
    el.setVIsSumLine(true);
    wdContext.nodeA().addElement(el);
    /* Set the sum line to display as selected table entry */
    wdContext.nodeA().setLeadSelection(wdContext.nodeA().size() - 1);

    This does not work, if A is bound to a structure, since you can't add value attributes to nodes which are bound to structures. Adaptive RFC model nodes are bound to the structure created from the function module interface in the ABAP system. But there's a workaround:

    1. Create value node A with structure binding, select the corresponding structure which were created on model import. Select the attributes you want to display in the table. After that, delete the structure binding from A (the attributes are kept and still have the correct SimpleType).

    2. Add the attributes which control the visibility and summing as described before.

    3. Bind the table's dataSource to A instead of the RFC model node (including the editor settings).

    4. In the method which fills the model, create the elements of A and copy the value attributes which are part of the original model from the model to the A-elements. Do the summing and setting of "VIsSumLine" as requested.

    This is not really automatically, but at least it works 😉

    Hope that helps.

    Regards

    Stefan

    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.