SAP Knowledge Base Article - Public

1215543 - How to format strings and numbers using the Picture function in Crystal Reports?

Symptom

  • Formatting a string or numeric value.
  • How to format text or numbers using a formula?
  • How to customize the way a string or numeric value displays in Crystal Reports with the Picture function? 

Environment

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

Resolution

  • The function: Picture, can be used to specify the format of a string or a string of numeric value in Crystal Reports. The Picture function can only be used on database fields of data types: String.
         
  • To use the function Picture, follow the steps below:
        
    1. In Crystal Reports, open a report, and create a formula.
          
    2. In the Formula Editor window, use the function: Picture in the following format:
      1.  
      2. Picture(<DATABASE FIELD>,'<FORMAT>)
          
    3. Insert the formula on your report.
              
               
  • The following are examples of the Picture function's use.   
         
    • Formatting a String Field to Appear as North American Telephone Numbers

      • A database field stores telephone numbers as ten digit strings (for example "8005551234") without parentheses or dashes. Use the Picture function in a formula to display these numbers as North American telephone numbers (for example (800) 555-1234). In this example, the field {customer.phone} has a String data type.

      • Example Formula:

      • Picture ({customer.phone}, '(xxx) xxx-xxxx')
      • If a value from the {customer.phone} field is "8005551234", the formula returns "(800) 555-3002".
      •  
    • Formatting a Number Field to Look Like a Date

      • A database field stores dates as eight numbers (for example 12252003) without slashes. Use the Picture function in a formula to display these numbers as a date (for example 12/25/2003). This example uses the ToText function to convert the number field to a string.

      • Example Formula:
      • Picture(ToText({order.orderdate},0,""), 'xx/xx/xxxx')
      • If a value from the {order.orderdate} field is 12252003, the formula returns "12/25/2003".
      •     
          
  • For more information on the Picture function, refer to the Crystal Reports Online Help.

Keywords

CR, CR Date , KBA , BI-RA-CR , Crystal Reports designer or Business View Manager , How To

Product

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