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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change format from numeric to alpha with leading 0's 1

Status
Not open for further replies.

GJFNH

Programmer
May 19, 2010
4
US
Hi - I'm wondering if there is a cleaner way to convert Numeric fields to Alpha (with leading zeros).
I'm appending 2 tables, and am changing a lot of fields so they'll all be formatted the same in both tables.

Here's my current version, which works, but for larger fields, would be cumbersome.

Code:
FORMAT TERR $3.;
TERR = TERRITORY;
IF SUBSTR(TERR,1,1) = ' ' THEN SUBSTR(TERR,1,1) = '0'; 
IF SUBSTR(TERR,2,1) = ' ' THEN SUBSTR(TERR,2,1) = '0';
IF SUBSTR(TERR,3,1) = ' ' THEN SUBSTR(TERR,3,1) = '0';

example:
territory = 051
terr would = " 51" (although looks like "51 " on monitor!)
after IF's, terr = 051

Thanks in advance!
 
Z formats are your friend.

If your data is in char format, convert to it to numeric and then convert back to char using the z format feature.
if its in numeric format then all you need to do is format it using the z format feature.
example
Code:
*** IF TERRITORY IS A CHAR ***;
TERR = trim(left(put(input(TERRITORY, best32.),z3.)));

*** IF TERRITORY IS A NUM***;
TERR = trim(left(put(TERRITORY,z3.)));

I hope this helps.
Klaz :)
 
That is so slick........tried it, and it's perfect!

THANK YOU!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top