cancel
Showing results for 
Search instead for 
Did you mean: 

How to add a subtotal line in a table control?

Former Member

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

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

Former Member
0 Kudos

All nice and well. But:

The current IWDTable has not been designed to provide such features and, as you have shown, there is no easy method to add them via the existing API.

So I would recommend to wait until the ALV like table will be provided. It is already planned for the (not so far) future.

Regards, Armin

Former Member
0 Kudos

Hi all! Need to have ALV enabled tables! Does an API already exist providing such functionality?

Christoph

0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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