SAP Knowledge Base Article - Public

1217663 - How to create a Custom Function in Crystal Reports?

Symptom

  • What is a Custom Function?
  • How to create a Custom Function in Crystal Reports?

Environment

  • SAP Crystal Reports 2013
  • SAP Crystal Reports 2016
  • SAP Crystal Reports 2020 

Resolution

  • In Crystal Reports, you can write formulas. There is a large array of build in functions that can be used when creating a formula. If there is a formula that is used multiple times on the same report, or used on multiple reports, then it is possible to add it as a function in the report, called: Custom Function.
        

  • Advantages of Custom Functions:
    • Re-use the same formula code;
    • Stored in the report file, therefore it does not rely on an external driver like User Function Library (UFL)
    • Can be stored in the Repository of SAP BusinessObjects BI Platform, so it can be re-used on other reports.
    • Custom Function stored in the Repository can be changed in one place, and all the reports are updated with the new change.
           
  • To create a Custom Function:
      
    1. In Crystal Reports, open a report.
        
    2. Under the menu "Report", select "Formula Workshop..."
        
    3. In "Formula Workshop", in the left pane, right click on "Report Custom Functions", and select "New"
        
    4. Enter the name of the Custom Function, and click on: "Use Editor"
        
    5. In the Custom Function, defined one variable for the Custom Function arguments. For example:

           Function (DateVar myDate)
         
    6. Then write the code to perform the desired calculation, data manipulation, convertion,... For example:

          Function (DateVar myDate)   

                    Local NumberVar y := Year(myDate) + 10;
                    Local NumberVar m := Month(myDate);
                    Local NumberVar d := Day(MyDate);

                    Date(myYear,myMonth,MyDay)

    1. Once you completed writing your code, click on "Save and Close"
        
    2. Now, create a new Formula, and use the new function created. For example, the formula will look like:                   
        
          myFunctionName(<Insert Your Date Filed Here>);
        
    3. Save and close the formula.
        
    4. Insert the formula on the report to display the value.

      You can now use the Custom Function on this report only.
        
  • To use the Custom Function on other report, store it in the repository of SAP BusinessObjects BI platfom.
      
    1. In Crystal Reports, still with the report open on which you have the Custom Function, go under the menu "Report", select "Formula Workshop..."
       
    2. In "Formula Workshop", in the left pane,  expand the "Report Custom Functions".
        
    3. Right click on the "Custom Function" you created, like: "myFunctionName", and select "Add to Repository..."
         
    4. Login to the SAP BusinessObjects Enterprise, and save the Custom Function.

      The Custom Function will then be listed in the Repository Custom Function, and can be added to any reports.

Keywords

FORMULA CUSTOM FUNCTION EXTRACTOR WORKSHOP EXTRACT Crystal Reports Repository Custom functions Use extractor , KBA , BI-RA-CR , Crystal Reports designer or Business View Manager , How To

Product

SAP Crystal Reports 2013 ; SAP Crystal Reports 2016 ; SAP Crystal Reports 2020