Crystal Reports for Eclipse Developer Guide

To add and remove formula fields

These samples show how to add and remove a formula field to a Crystal report. Formula fields allow you to put data on the report that may not exist in any of the data fields.
For example, to calculate the number days it takes to process each order, you need a formula that determines the number of days between the order date and the ship date. These formulas are added to the FormulaFields collection, which can be modified by using the DataDefController class.
To add or remove a formula field:
  • Get the DataDefController object, which allows you to modify the report's data definition. A data definition defines what data is used in the report and how it is treated.
  • Get the FormulaFieldController object, which allows you to add, remove, and modify formula fields on the report.
  • Add a formula field to the report by with the add method and remove a formula field from the report with the remove method. The add method returns the index of the item after it has been added to the FormulaFields collection.

    Note: The add method returns the index of the item after it has been added to the Fields collection. If the method is unable to find the index, it returns a value of -1.
Example: Adding a formula field
void addFormulaField(ReportClientDocument rcd)
{        
	DataDefController dataDefController = rcd.getDataDefController();
	FormulaFieldController formulaFieldController = dataDefController.getFormulaFieldController();
	int ret = formulaFieldController.add("newFormula", "Date(1999, 12, 31)", FormulaSyntax.crystal);
}
Example: Removing a formula field
void removeFormulaField(ReportClientDocument rcd)
{  
	DataDefController dataDefController = rcd.getDataDefController();
	FormulaFieldController formulaFieldController = dataDefController.getFormulaFieldController();
	formulaFieldController.remove( "newFormula" );
}



SAP BusinessObjects
http://www.sap.com/sapbusinessobjects/
Support services
http://service.sap.com/bosap-support/
Product Documentation on the Web
http://help.sap.com/