×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Writing a formula to pad a text field

Writing a formula to pad a text field

Writing a formula to pad a text field

(OP)
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

RE: Writing a formula to pad a text field

One simple way is to append the 6 spaces and then take the last 6 characters of the result:


Right ("      " + {field} , 6)

Ken Hamady
http://www.kenhamady.com/
Crystal Reports Training/Consulting and a
Quick Reference Guide to VB/Crystal (including ADO)

RE: Writing a formula to pad a text field

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
http://www.chase-international.com
Accredited Crystal Decisions Enterprise Partner

RE: Writing a formula to pad a text field

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
http://www.kenhamady.com/
Crystal Reports Training/Consulting and a
Quick Reference Guide to VB/Crystal (including ADO)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close