1306326 - How to add a summary field to a report using the Crystal Reports .NET inproc RAS SDK

SAP Knowledge Base Article - Public

1306326 - How to add a summary field to a report using the Crystal Reports .NET inproc RAS SDK

Symptom

How to add a summary field to a report using the Crystal Reports .NET inproc RAS SDK ?

Reproducing the Issue

  • Crystal Reports XI Release 2 Service Pack 2 and later 
  • C#
  • Resolution

    sample code:


               using CrystalDecisions.CrystalReports.Engine;
               using CrystalDecisions.ReportAppServer.ClientDoc;
               using CrystalDecisions.ReportAppServer.DataDefModel;


                //CR Declarations
                ReportDocument                                                                                      m_boReportDocument;
                ISCDReportClientDocument                                                                  m_boReportClientDocument;
            
               CrystalDecisions.ReportAppServer.DataDefModel.Fields                 m_boFields;
               CrystalDecisions.ReportAppServer.DataDefModel.Field                   m_boField;
               CrystalDecisions.ReportAppServer.DataDefModel.SummaryField   m_boSummaryField;

                CrystalDecisions.ReportAppServer.ReportDefModel.Section           m_boSection;
                CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject     m_boFieldObject;

                
               

                //create a new ReportDocument
                m_boReportDocument = new ReportDocument();

                //load the RPT file
                m_boReportDocument.Load("..\\..\\DummyReport.rpt");

                //access the ReportClientDocument in the ReportDocument (EROM bridge)
                m_boReportClientDocument = m_boReportDocument.ReportClientDocument;


                //first determine the sections - in this case the report footer area
                m_boSection = m_boReportClientDocument.ReportDefController.ReportDefinition.ReportFooterArea.Sections[0];
                

                m_boFields = m_boReportClientDocument.DatabaseController.Database.Tables[0].DataFields;

                //set Last Year's Sales as data field
                //get {Customer.Last Year's Sales field}
                m_boFieldIndex = m_boFields.Find("Last Year's Sales",
                                           CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameName,
                                           CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleUserDefault);

                m_boField = (CrystalDecisions.ReportAppServer.DataDefModel.Field)  m_boFields[m_boFieldIndex];
               

                //create a Sum({Customer.Last Year's Sales})
                m_boSummaryField = new CrystalDecisions.ReportAppServer.DataDefModel.SummaryField();
                m_boSummaryField.SummarizedField = m_boField;
                m_boSummaryField.Operation = CrystalDecisions.ReportAppServer.DataDefModel.CrSummaryOperationEnum.crSummaryOperationSum;
                m_boSummaryField.Type = CrFieldValueTypeEnum.crFieldValueTypeCurrencyField;


                //assign the m_boSummaryField to the fieldObject
                m_boFieldObject = new CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject();

                //get the FormulaForm method as DataSource
                m_boFieldObject.DataSource = m_boSummaryField.FormulaForm;

                //use the same FieldValue as the SummaryField
                m_boFieldObject.FieldValueType = m_boSummaryField.Type;
               
                //set the location of the field object relative to the area settings    
                m_boFieldObject.Left     = 9000; // 1 would be left corner
                m_boFieldObject.Top     = 150;
                m_boFieldObject.Width  = 1580;
                m_boFieldObject.Height = 216;

                //add summary field to report client document
                m_boReportClientDocument.ReportDefController.ReportObjectController.Add(m_boFieldObject, m_boSection, -1);

                 //display in reportviewer
                crystalReportViewer1.ReportSource = m_boReportDocument;

    Keywords

    How add summaryfield report  Crystal Reports .NET inproc RAS SDK , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , How To

    Product

    SAP Crystal Reports XI R2