To report off a data source at runtime

Parent Previous Next

 

Report Application Server .NET SDK Developer Guide

To report off a data source at runtime


 







You can take data from any source such as a database, data stream, or flat file, and then at run time you can manipulate and apply it to a report. Data is retrieved using a Rowset object and stored in a DataSet object.

NoteNote

If you create a report that is based on a DataSet object, the data that is used is not automatically saved with the report. To populate the report with data the next time you open it, you must either re-apply the data source to see current data, or access a saved version of the data source for preview.

  1. Create a RowsetMetaData object.

Visual Basic

Dim rowsetMD As New RowsetMetaData()

C#

RowsetMetaData rowsetMD = new RowsetMetaData();

  1. Add the fields to the RowsetMetaData object.

In this example the RowsetMetaData object is populated with result fields from the report. Any Field object can be used to populate the RowsetMetaData.

Visual Basic

Dim resultFields As Fields = rcd.DataDefinition.ResultFields 
rowsetMD.DataFields = resultFields

C#

Fields resultFields = rcd.DataDefinition.ResultFields;
rowsetMD.DataFields = resultFields;

  1. Use the RowsetBatchSize property of the RowsetController object to set the number of records to retrieve in each batch.

Visual Basic

Dim rowController As RowsetController = rcd.RowsetController
rowController.RowsetBatchSize = 1

C#

RowsetController rowController = rcd.RowsetController;
rowController.RowsetBatchSize = 1;

  1. Create a RowsetCursor object using the CreateCursormethod of the RowsetController object.

Visual Basic

Dim rowCursor As RowsetCursor = rowController.CreateCursor(Nothing, rowsetMD, 0) 

C#

RowsetCursor rowCursor = rowController.CreateCursor(null, rowsetMD, 0);

  1. Retrieve the Rowset object using the RowsetCursor object.

Retrieve an instance of the Rowset object using the Rowset property of the RowsetController object.

Visual Basic

Dim modifiedRowset As Rowset = rowCursor.Rowset

C#

Rowset modifiedRowset = rowCursor.Rowset;

  1. Navigate through the Rowset object to view or manipulate the data.

In this example all batches except the first batch are deleted.

Visual Basic

Dim rbatch As New RecordBatch()
Dim rbatches As New RecordBatches()
rbatches = modifiedRowset.RecordBatches
For x As Integer = 1 To rbatches.Count - 1
 rbatches(x).RemoveAll()
Next
modifiedRowset.RecordBatches = rbatches

C#

RecordBatch rbatch = new RecordBatch();
RecordBatches rbatches = new RecordBatches();
rbatches = modifiedRowset.RecordBatches;
for (int x = 1; x < rbatches.Count; x++)
{
  rbatches[x].RemoveAll();
}
modifiedRowset.RecordBatches = rbatches;

  1. Add the modified Rowset object to a Rowsets collection.

Visual Basic

Dim mysets As New Rowsets()
mysets.Add(modifiedRowset)

C#

Rowsets mysets = new Rowsets();
mysets.Add(modifiedRowset);

  1. Add the Rowsets collection to a Dataset object.

Visual Basic

Dim dataSet As DataSet = New DataSetClass()
dataSet.Rowsets = mysets

C#

DataSet dataSet = new DataSetClass();
dataSet.Rowsets = mysets;

  1. Set the table and table links information for the DataSet object.

Visual Basic

Dim dbController As DatabaseController = rcd.DatabaseController
dataSet.Tables = dbController.Database.Tables
dataSet.TableLinks = dbController.Database.TableLinks

C#

DatabaseController dbController = rcd.DatabaseController;
dataSet.Tables = dbController.Database.Tables;
dataSet.TableLinks = dbController.Database.TableLinks;

  1. Set the Dataset object as the data source for the report.

Visual Basic

dbController.SetDataSource(dataSet, "", "")

C#

dbController.SetDataSource(dataSet, "", "");

This sample retrieves a Rowset from the report, removes all batches except for the first batch, adds the modified Rowset object to a Dataset object, and then changes the report data source at runtime.

Visual Basic

Private Sub ModifyRuntimeDatasource(ByVal rcd As ISCDReportClientDocument)
 Dim rowsetMD As New RowsetMetaData()
 Dim resultFields As Fields = rcd.DataDefinition.ResultFields
 rowsetMD.DataFields = resultFields
 Dim rowController As RowsetController = rcd.RowsetController
 rowController.RowsetBatchSize = 1
 Dim rowCursor As RowsetCursor = rowController.CreateCursor(Nothing, rowsetMD, 0)
 Dim modifiedRowset As Rowset = rowCursor.Rowset
 Dim rbatch As New RecordBatch()
 Dim rbatches As New RecordBatches()
 rbatches = modifiedRowset.RecordBatches
 For x As Integer = 1 To rbatches.Count - 1
  rbatches(x).RemoveAll()
  Next
 modifiedRowset.RecordBatches = rbatches
 Dim mysets As New Rowsets()
 mysets.Add(modifiedRowset)
 Dim dataSet As DataSet = New DataSetClass()
 dataSet.Rowsets = mysets
 Dim dbController As DatabaseController = rcd.DatabaseController
 dataSet.Tables = dbController.Database.Tables
 dataSet.TableLinks = dbController.Database.TableLinks
 dbController.SetDataSource(dataSet, "", "")
End Sub

C#

private void ModifyRuntimeDatasource(ISCDReportClientDocument rcd)
{
 RowsetMetaData rowsetMD = new RowsetMetaData();
 Fields resultFields = rcd.DataDefinition.ResultFields;
 rowsetMD.DataFields = resultFields;
 RowsetController rowController = rcd.RowsetController;
 rowController.RowsetBatchSize = 1;
 RowsetCursor rowCursor = rowController.CreateCursor(null, rowsetMD, 0);
 Rowset modifiedRowset = rowCursor.Rowset;
 RecordBatch rbatch = new RecordBatch();
 RecordBatches rbatches = new RecordBatches();
 rbatches = modifiedRowset.RecordBatches;
 for (int x = 1; x < rbatches.Count; x++)
 {
  rbatches[x].RemoveAll();
 }
 modifiedRowset.RecordBatches = rbatches;
 Rowsets mysets = new Rowsets();
 mysets.Add(modifiedRowset);
 DataSet dataSet = new DataSetClass();
 dataSet.Rowsets = mysets;
 DatabaseController dbController = rcd.DatabaseController;
 dataSet.Tables = dbController.Database.Tables;
 dataSet.TableLinks = dbController.Database.TableLinks;
 dbController.SetDataSource(dataSet, "", "");
}

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: Easily create EBooks