To add a summary to a report

Parent Previous Next

  Copy image CopyHover image

Report Application Server .NET SDK Developer Guide

To add a summary to a report


 







This example assumes that you have a report with a table named Customer that contains a field named Last_Years_Sales.

This example shows how to create a summary field that finds the largest value for the Customer.Last_Years_Sales field.

  1. Get the DataDefController object from a ReportClientDocument object.

 

CopyCode image

DataDefController dataDefController = rcd.getDataDefController();

  1. Get the list of database tables, and find theCustomer table.

 


Tables tables = rcd.getDatabaseController().getDatabase().getTables();
ITable customerTable = tables.findTableByAlias("Customer"); 

  1. Get the list of database fields, and find the Last_Years_Sales field.

 


Fields<IField> fields = customerTable.getDataFields();
IField salesField = fields.findField("{Customer.Last_Years_Sales}", FieldDisplayNameType.formulaName, java.util.Locale.US);

  1. Call the canSummarizeOn method of the SummaryFieldController class to test whether summaries can be calculated for the field.

 


SummaryFieldController summaryFieldController = dataDefController.getSummaryFieldController();
boolean canSummarizeOn = summaryFieldController.canSummarizeOn(salesField);

  1. Create a new SummaryField object.

 


ISummaryField summaryField = new SummaryField();

  1. Call the setSummarizedField method to set the field that is being summarized.

 


summaryField.setSummarizedField(salesField);

  1. Call the setOperation method to define the type of summary operation.

 


 summaryField.setOperation(SummaryOperation.sum);

NoteNote

Call the method setOperationParameter if the summary operation requires a parameter.

  1. Call the add method of SummaryFieldController to add the summary to the report.

The value -1 adds the summary to the end of the summary list.

 

CopyCode image

summaryFieldController.add(-1, summaryField);

Adding a summary to a report

This example shows how to calculate the sum of the Customer.Last_Years_Sales field. The summary is added to the report footer.

 

CopyCode image

public void addSummary(ReportClientDocument rcd) throws ReportSDKException
{
  DataDefController dataDefController = rcd.getDataDefController();
  Tables tables = rcd.getDatabaseController().getDatabase().getTables();
  ITable customerTable = tables.findTableByAlias("Customer"); 
  Fields<IField> fields = customerTable.getDataFields();
  IField salesField = fields.findField("{Customer.Last_Years_Sales}", FieldDisplayNameType.formulaName, java.util.Locale.US);
  SummaryFieldController summaryFieldController = dataDefController.getSummaryFieldController();
  boolean canSummarizeOn = summaryFieldController.canSummarizeOn(salesField);
   
  if (canSummarizeOn)
  {
    ISummaryField summaryField = new SummaryField();
    summaryField.setSummarizedField(salesField);  
    summaryField.setOperation(SummaryOperation.sum);
    summaryFieldController.add(-1, summaryField);
  }
}

This list includes the classes 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 HTML Help, DOC, PDF and print manuals from 1 single source