Tuesday, June 8, 2010

Shortening long string fields and removing carriage returns



Inevitably, your users will want a work order list report. In AiM, the work order and phase description fields are up to 255 chars long, which can eat up a lot of space in the limited space available on your report. To avoid killing tons of trees every time a report is printed, there are a couple options to shorten the text passed to the report.

Starting in Birt 2.5, you can control in the report editor whether wrapping is allowed or not. This can be found in data or column advanced properties/text/whitespace. Set the value to "no wrapping". I've found this to be of limited value because it doesn't control carriage returns in the data and will continue to wrap on the carriage returns.


Another option is to control the text formatting in the sql query.

Use the sql command SUBSTRING to limit the number of characters retrieved from the database.

select
substring (ph_desc, 1, 60) as ph_desc
from phase

which means that 60 chars, starting with the first character, of the ph_desc field will be retrieved.

Then, AiM allows users to enter carriage returns and line feeds, so I do a couple more modifications to remove those since they can also eat up space.

--to remove carriage returns
select
replace (ph_desc, CHAR (13), ' ') as ph_desc
from phase

and/or

--to remove line feeds
select
replace (ph_desc, CHAR (10), ' ') as ph_desc
from phase

All of these can be combined in the following way.

select
replace (replace (substring(ph_desc,1,60), CHAR (13), ' '), CHAR(10), ' ') as ph_desc
from phase

No comments:

Post a Comment