1210573 - How to print a character or value N number of times in Crystal Reports?

SAP Knowledge Base Article - Public

1210573 - How to print a character or value N number of times in Crystal Reports?

Symptom

  • How to replicate a value N number of times?
  • How to repeat the same character N number of times?
  • Is it possible to print a character, values or database fields multiple times, based on a numeric value from another field in Crystal Reports?

Environment

  • Crystal Reports 2008
  • SAP Crystal Reports 2011
  • SAP Crystal Reports 2013
  • SAP Crystal Reports 2016

Resolution

  • To manually set the number of times a character, a value, or record to be printed, you can use in a formula the function: 

        ReplicateString( y, x )

    Where 'y' is the string to be replicated, and 'x' is the number of replications. ReplicateString only works on a string or text field.
       

    Below are the general steps on how to create a formula that uses the function ReplicateString:
       
    1. In Crystal Reports, create a formula where you declare a numeric variable.  
      This variable holds the value of the quantity field that determines the how many times to replicate the other string field.
       
    2. Still in the same formula, declare a string variable. Assign the string field that is to be repeated to this variable, and if you want, add a Chr(13), which is the ASCII character for carriage return.
       
    3. Use the ReplicateString function with the two variables.
       
    4. Place this formula where you want to see the repeated fields on the report.
        
    5. Format the formula with 'Can Grow', to accommodate the downward movement of the text.
        
      Below is a sample formula:.

          NumberVar y := {Table1.Quantity};
          StringVar x := {Table1.Name} + chr(13);
          ReplicateString (x, y );


      If the field to be replicated is not a string field, use the ToText() function to convert it to string.

          NumberVar y:= {Table1.Quantity};
          StringVar x:=ToText( {Table1.Name})+ chr(13);
          ReplicateString (x, y );

      To include more fields to the line, assign more fields to the string variable, making sure to add the Chr(13) at the end.
       
       
        
  • Note:  If the string replication results in more than 64,000 characters, the Crystal Reports Formula Editor will generate this error when checking the formula:
      
         "The number of copies of the string is too large or not an integer."

    Enter any numeric values lower than this limit.

Keywords

Repeat, duplicate, CR , KBA , BI-RA-CR , Crystal Reports designer or BusinessViews Manager , How To

Product

Crystal Reports 2008 V1 ; SAP Crystal Reports 2011 ; SAP Crystal Reports 2013 ; SAP Crystal Reports 2016