1355542 - How to add a RunningTotal using the Crystal Reports .NET inproc RAS SDK?

SAP Knowledge Base Articles - public

1355542 - How to add a RunningTotal using the Crystal Reports .NET inproc RAS SDK?


How to add a RunningTotal using the Crystal Reports .NET inproc RAS SDK?

Reproducing the Issue

.NET Visual Studio 2005


How to add a RunningTotal using the Crystal Reports .NET inproc RAS SDK
A RunningTotal can be added as a Formula Field with specific formula as shown below 


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

        ReportDocument     m_boReportDocument;
        ISCDReportClientDocument     m_boReportClientDocument;
        CrystalDecisions.ReportAppServer.DataDefModel.FormulaField    m_boFormulaField;
        CrystalDecisions.ReportAppServer.ReportDefModel.Section    m_boSection;
        CrystalDecisions.ReportAppServer.DataDefModel.Fields    m_boFields;
        CrystalDecisions.ReportAppServer.DataDefModel.Field     m_boField;
        CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject    m_boFieldObject;

         int m_boFieldIndex;

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

         // load the RPT file 

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

         //First create the formula field
         m_boFormulaField = new CrystalDecisions.ReportAppServer.DataDefModel.FormulaField();

          //Set the parameters (assume it's a string and Crystal Syntax)
          // this is the specific RunningTotal Formula (see Crystal Reports Help file)
          m_boFormulaField.Text = "WhilePrintingRecords; CurrencyVar Amount; Amount := Amount + {Customer.Last Year's Sales};";

          m_boFormulaField.Name = "RunningTotal";
          m_boFormulaField.Syntax = CrystalDecisions.ReportAppServer.DataDefModel.CrFormulaSyntaxEnum.crFormulaSyntaxCrystal;
          m_boFormulaField.Type = CrystalDecisions.ReportAppServer.DataDefModel.CrFieldValueTypeEnum.crFieldValueTypeCurrencyField;

           //Now add it to the report

            //Now that the formula has been created, add the newly created formula to the report

            //First determine which section to add the formula field to - in this case the details section
            m_boSection = m_boReportClientDocument.ReportDefController.ReportDefinition.DetailArea.Sections[0];

             //Get back all the formulafields in the report
            m_boFields = m_boReportClientDocument.DataDefController.DataDefinition.FormulaFields;

            m_boFieldIndex = m_boFields.Find({@RunningTotal},

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

             //Set the type of field this is
             m_boField.Type = CrystalDecisions.ReportAppServer.DataDefModel.CrFieldValueTypeEnum.crFieldValueTypeCurrencyField;

             //Now create a new Field object which will be added to the report
             m_boFieldObject = new CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject();

            //Set the datasource of this field object to the formula form of the above Database Field Object
            m_boFieldObject.DataSourceName = m_boFormulaField.FormulaForm;
            m_boFieldObject.FieldValueType = m_boFormulaField.Type;

            //Now set the co-ordinates of where the field will go
            m_boFieldObject.Left = 5 * 1440; //1440 twips per inc
            m_boFieldObject.Width = 2 * 1440;

           //And finally Add it to the report
           m_boReportClientDocument.ReportDefController.ReportObjectController.Add(m_boFieldObject, m_boSection, -1);

            //Display in reportviewer
            crystalReportViewer1.ReportSource = m_boReportDocument;

Prior to the release of Crystal Reports XI R2 Service Pack 2, report modification was only possible using the RAS (Report Application Server) SDK with a RAS server or by using In-Process RAS with the purchase of additional licensing.
Using Crystal Reports  XI R2 Service Pack 2 and higher, you can now access the report modification APIs without any additional licensing by using the inprocess-RAS engine through the Crystal Reports .NET SDK. An example of accessing the RAS SDK through the Crystal Reports  .NET SDK is as follows:


RAS, Modification, RunningTotal, In-Process, .NET, Create, Add, Remove, Change, Modify, ReportClientDocument, inproc, FormulaField , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , How To


SAP Crystal Reports XI R2