To add a Top N sorting definition

Parent Previous Next

 

Report Application Server .NET SDK Developer Guide

To add a Top N sorting definition

See Also 

 







NoteNote

You must have added a summary field before you can add a Top N sort.

Adding a Top N sorting definition is similar to adding a normal sort, with a few exceptions. You create a Top N sort based on a specific summary field in the report that summarizes grouped data.

  1. Retrieve the DataDefController object.

Visual Basic

Dim dataDefController As DataDefController = rcd.DataDefController

C#

DataDefController dataDefController = rcd.DataDefController;

  1. Retrieve the report's first summary field.

Visual Basic

Dim summaryField As ISCRField = myDataDefController.DataDefinition.SummaryFields(0)

C#

ISCRField summaryField = dataDefController.DataDefinition.SummaryFields[0];

  1. Retrieve the SortController object.

Visual Basic

Dim sortController As SortController = myDataDefController.SortController

C#

SortController sortController = dataDefController.SortController;

  1. Create a new TopNSort object, set the field to sort on with the SortField property, and set the direction of the sort.

Visual Basic

Dim myTopNSort As TopNSort = New TopNSort
myTopNSort.SortField = mySummaryField
myTopNSort.Direction = CrSortDirectionEnum.crSortDirectionTopNOrder

C#

TopNSort topNSort = new TopNSort();
topNSort.SortField = summaryField;
topNSort.Direction = CrSortDirectionEnum.crSortDirectionTopNOrder;

  1. Set the number of groups in the Top N and specify how to handle groups outside the calculated Top N range.

In this example, the top five groups are considered. Groups not in the top five are not discarded, but rather grouped together in a group called "Other".

Visual Basic

myTopNSort.NIndividualGroups = 5
myTopNSort.DiscardOthers = False
myTopNSort.NotInTopBottomName = "Other"

C#

topNSort.NIndividualGroups = 5;
topNSort.DiscardOthers = false;
topNSort.NotInTopBottomName = "Other";

  1. Call the Add method of the SortController class to add the new sort to the report based on the chosen field.

The first parameter of the Add method specifies the location of the new sorting definition in the Sorts collection. A value of -1 indicates that the new sorting definition will be added to the end of the Sorts collection. This means that the new sorting definition will be applied to records last after all other sorting definitions have been applied.

Visual Basic

sortController.Add(-1, myTopNSort)

C#

sortController.Add(-1, topNSort);

The following code adds a new top five sort to a report based on the first summary field.

Visual Basic

Private Sub AddTopNSort(ByVal rcd As ISCDReportClientDocument)
 Dim dataDefController As DataDefController = rcd.DataDefController
 Dim summaryField As ISCRField = dataDefController.DataDefinition.SummaryFields(0)
 Dim sortController As SortController = dataDefController.SortController
 Dim topNSort As TopNSort = New TopNSortClass()
 topNSort.SortField = summaryField
 topNSort.Direction = CrSortDirectionEnum.crSortDirectionTopNOrder
 topNSort.DiscardOthers = False
 topNSort.NIndividualGroups = 5
 topNSort.NotInTopBottomName = "Other"
 sortController.Add(-1, topNSort)
End Sub

C#

private void AddTopNSort(ISCDReportClientDocument rcd)
{
 DataDefController dataDefController = rcd.DataDefController;
 ISCRField summaryField = dataDefController.DataDefinition.SummaryFields[0];
 SortController sortController = dataDefController.SortController;
 TopNSort topNSort = new TopNSortClass();
 topNSort.SortField = summaryField;
 topNSort.Direction = CrSortDirectionEnum.crSortDirectionTopNOrder;
 topNSort.DiscardOthers = false;
 topNSort.NIndividualGroups = 5;
 topNSort.NotInTopBottomName = "Other";
 sortController.Add(-1, topNSort);
}

This list includes the namespaces used by the sample code:

See Also

© 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: Generate EPub eBooks with ease