Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing a formula to pad a text field 1

Status
Not open for further replies.

scootswiss

Technical User
Mar 1, 2001
11
US
I am compiling a report in Crystal 8.0, pulling data from an Oracle database. The flat file will be imported into a mainframe system. My question, is it possible to write a formula for a text field to always be 6 characters, even if the data is only 4 or 5 characters? In other words, use a RPAD function that can be used in other programming languages. Any padding needed would be blank spaces. The Oracle database field is VARCHAR2, (20). Would function would I use and how would the formula be formatted.

Thanks, Brian

woelfel@sccompanies.com
 
One simple way is to append the 6 spaces and then take the last 6 characters of the result:


Right (" " + {field} , 6) Ken Hamady
Crystal Reports Training/Consulting and a
Quick Reference Guide to VB/Crystal (including ADO)
 
scootswiss: I suggest the following:

Left(rtrim({textfield})&Space(20),6)

This first trims your field to however many relevant characters, merges the result to a maximum of 20 characters with spaces - the equivalent of RPAD - and then returns the first 6 David C. Monks
david.monks@chase-international.com
Accredited Crystal Decisions Enterprise Partner
 
I guess I shouldn't have assumed that that padding was on the left. I am used to padding numeric strings on the left. You could use the left function in my formula, also:

Left ({field} + " " , 6)

I don't think you need to trim a field in CR when you concatenate it. At least not in modern versions. The concatenate should AutoTrim. Ken Hamady
Crystal Reports Training/Consulting and a
Quick Reference Guide to VB/Crystal (including ADO)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top