To add a summary to a group

Parent Previous Next

 

Report Application Server .NET SDK Developer Guide

To add a summary to a group


 







You can summarize the fields in a group. For example, you can group a report by region, and then summarize the sales for each region.

  1. Retrieve the DataDefController object.

Visual Basic

Dim dataDefController As DataDefController = rcd.DataDefController

C#

DataDefController dataDefController = rcd.DataDefController;

  1. Retrieve the report's outermost group.

Visual Basic

Dim group As Group = dataDefController.DataDefinition.Groups(0);

C#

Group group = dataDefController.DataDefinition.Groups[0];

  1. Retrieve the field to summarize.

This example assumes that the report design contains a Last_Years_Sales field called from a table called Customer.

NoteNote

Not all fields can be summarized on. The CanSummarizeOn method of the SummaryFieldController class checks whether the field can be summarized.

Visual Basic

Dim resultFields As Fields = dataDefController.DataDefinition.ResultFields
Dim fieldToSummarize As Field = DirectCast(resultFields.FindField("{Customer.Last_Years_Sales}", CrFieldDisplayNameTypeEnum.crFieldDisplayNameFormula, CeLocale.ceLocaleEnglishUS), Field)

C#

Fields resultFields = dataDefController.DataDefinition.ResultFields;
Field fieldToSummarize = (Field)resultFields.FindField("{Customer.Last_Years_Sales}", CrFieldDisplayNameTypeEnum.crFieldDisplayNameFormula, CeLocale.ceLocaleEnglishUS);

  1. Retrieve the SummaryFieldController object.

Visual Basic

Dim summaryFieldController As SummaryFieldController = myDataDefController.SummaryFieldController

C#

SummaryFieldController summaryFieldController = dataDefController.SummaryFieldController;

  1. Create a new SummaryField object.

Visual Basic

Dim summaryField As SummaryField = new SummaryFieldClass()

C#

SummaryField summaryField = new SummaryFieldClass();

  1. Set the group to summarize, the field to perform a summary calculation on, and the operation of the summary calculation.

Visual Basic

summaryField.Group = group
summaryField.SummarizedField = fieldToSummarize
summaryField.Operation = CrSummaryOperationEnum.crSummaryOperationSum

C#

summaryField.Group = group;
summaryField.SummarizedField = fieldToSummarize;
summaryField.Operation = CrSummaryOperationEnum.crSummaryOperationSum;

  1. Call the Add method of the SummaryFieldController class to add the new summary field to the report.

The first parameter of the Add method specifies the location of the new sorting definition in the SummaryFields collection. A value of -1 indicates that the new sorting definition will be added to the end of the SummaryFields collection. However, the location in the collection makes no difference to the report. Apply a report template to ensure consistent formatting of your reports.

Visual Basic

summaryFieldController.Add(-1, summaryField)

C#

summaryFieldController.Add(-1, summaryField);

The following code adds a new summary field the first group in a report and based on a given field to perform a summary calculation on. This example checks whether the selected field is a valid field to summarize on before attempting to create the summary field.

Visual Basic

Private Sub AddSummaryFieldToGroup(ByVal rcd As ISCDReportClientDocument)
 Dim dataDefController As DataDefController = rcd.DataDefController
 
 Dim group As Group = dataDefController.DataDefinition.Groups(0)
 
 Dim resultFields As Fields = dataDefController.DataDefinition.ResultFields
 Dim fieldToSummarize As Field = DirectCast(resultFields.FindField("{Customer.Last_Years_Sales}", CrFieldDisplayNameTypeEnum.crFieldDisplayNameFormula, CeLocale.ceLocaleEnglishUS), Field)
 Dim summaryFieldController As SummaryFieldController = dataDefController.SummaryFieldController
 If summaryFieldController.CanSummarizeOn(fieldToSummarize) Then
  Dim summaryField As SummaryField = New SummaryFieldClass()
  summaryField.Group = group
  summaryField.SummarizedField = fieldToSummarize
  summaryField.Operation = CrSummaryOperationEnum.crSummaryOperationSum
  summaryFieldController.Add(-1, summaryField)
 End If
End Sub

C#

private void AddSummaryFieldToGroup(ISCDReportClientDocument rcd)
{
 DataDefController dataDefController = rcd.DataDefController;
 
 Group group = dataDefController.DataDefinition.Groups[0];
 
 Fields resultFields = dataDefController.DataDefinition.ResultFields;
 Field fieldToSummarize = (Field)resultFields.FindField("{Customer.Last_Years_Sales}", CrFieldDisplayNameTypeEnum.crFieldDisplayNameFormula, CeLocale.ceLocaleEnglishUS);
 SummaryFieldController summaryFieldController = dataDefController.SummaryFieldController;
 if (summaryFieldController.CanSummarizeOn(fieldToSummarize))
 {
  SummaryField summaryField = new SummaryFieldClass();
  summaryField.Group = group;
  summaryField.SummarizedField = fieldToSummarize;
  summaryField.Operation = CrSummaryOperationEnum.crSummaryOperationSum;
  summaryFieldController.Add(-1, summaryField);
 }
}

This list includes the namespaces used by the sample code:

© 2021 SAP AG. All rights reserved.

http://www.sap.com/sapbusinessobjects/

Support services

http://service.sap.com/bosap-support/

Created with the Personal Edition of HelpNDoc: Create help files for the Qt Help Framework