Skip to Content
avatar image
Former Member

Report field fixed widths?

My company has purchased Crystal Reports 2008 and I'm in the process of determining if the product will do everything we need and not become a maintenance nitemare.

We would like to setup some standard report headings to be used in all reports. I've setup on already as a SUBREPORT and it works fine. We pass optional parameters that may be blank.

We have several questions:

1) ...

2) ...

3) ...

4) Standard Report... Creating the report is difficult with guessing the width to define to the field. Is there a way that the report can know and display the exact size of the field being used? A fixed field defininiton of some sort would make it MUCH easier in the layout of the report.

5) ...

6) ...

This is question 4 from a larger post to make it easier for responses.

Thanks in advance.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Sep 10, 2008 at 08:07 AM

    Hi Tim,

    Fixed length fields can be created using Crystal Formula fields.

    You can use this formula to create a fixed width field.

    You will need to substitute {Customer.Customer Name} with the name of your database field:

    // Start Formula

    // specify the desired length of the field in characters (this example uses 20)

    numbervar requiredlength:= 20; // You can calculate the maximum length of the field {Customer.Customer Name} and place it in requiredlength.

    // Get the current length of the database field.

    numbervar currentlength:= length({Customer.Customer Name});

    // Check the length of the database field compared to the required length

    if requiredlength < currentlength then

    // truncate fields which are longer than the required length. Put " 1 to requiredlength " in a square bracket.

    {Customer.Customer Name} [1 to requiredlength]


    // pad the field length with underscore characters (_)

    // for readibility and testing, any added spaces are denoted using underscore characters (_)

    {Customer.Customer Name} + replicatestring("_", requiredlength-currentlength)

    // End Formula

    Insert the above formula on the report instead of the database field.

    For readability, any added spaces are denoted using underscore characters (_). If you wish to use blank spaces instead, replace the last line of code in the formula with the following:

    {Customer.Customer Name} + replicatestring(" ", requiredlength-currentlength)


    If the database field length is greater than the required fixed length, then the resulting field will be truncated. For example, if the required fixed length is 5, then the string 'Crystal' will be returned as 'Cryst'

    In this scenario, you can calculate the maximum length of the field {Customer.Customer Name} and place it in requiredlength

    Hope this helps!!



    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      My method is for creating a field that is exactly a set length, you then append it to other fields. This is for applications where you have to create a fixed-length text file to upload to some other system. I wasn't quite sure if that was what your intent was.

      You can do them all in one big formula, but for clarity, I prefer to do the pieces in individual formulas, then have one formula for the detail line that just concatenates all the other peices in the right ordr.