Focal Point
How do I add a leading zero?

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/1611074861

May 18, 2006, 11:40 AM
Suzanne
How do I add a leading zero?
I have an A2 field that is determined by using the GETTOK command. I need the first character to be zero if the result is only one character. Any ideas?


WF 766
Win2K
May 18, 2006, 11:44 AM
jimster06
FIELD2/A02 = IF EDIT(FIELD1,'9') EQ ' '
THEN '0' | EDIT(FIELD1, '$9')
ELSE FIELD1;

Try this.
May 18, 2006, 11:46 AM
<Special-K>
You could turn it into a number and add 100 and edit the last 2 characters, something like

DEFINE FILE CAR
FLD1/A2=;
FLD2/I2=EDIT(FLD1);
FLD3/I3=100+FLD2;
FLD4/A3=EDIT(FLD3);
FLD5/A3=EDIT(FLD4,'$99');
END

TABLE FILE CAR
PRINT FLD1 FLD5
END
May 18, 2006, 12:03 PM
Francis Mariani
The simplest way is to use edit to conver the A2 to I2 and then back to A2:

TABLE FILE CAR
PRINT
CAR
COMPUTE TEST1/A2 = ' 3';
COMPUTE TEST2/I2 = EDIT(TEST1);
COMPUTE TEST3/A2 = EDIT(TEST2);
WHERE RECORDLIMIT EQ 1
END


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
May 18, 2006, 12:03 PM
Suzanne
Didn't work... result is still only one character

FIELD2/A02 = IF EDIT(FIELD1,'9') EQ ' '
THEN '0' | EDIT(FIELD1, '$9')
ELSE FIELD1;


WF 766
Win2K
May 18, 2006, 12:13 PM
Suzanne
Converting the A2 to I2 and then back to A2 did the trick... Thanks!


WF 766
Win2K
May 18, 2006, 12:18 PM
susannah
there's always
newfield/A4='00' || oldfield ;
newfield/A4=RJUST(4,newfield,newfield);
newerfield/A2=SUBSTRING(4,newfield,3,4,2,'A2');




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
May 18, 2006, 04:09 PM
JimRice
Hi Suzanne,

There's a formatting option of an 'L' that can be used with numeric fields which will retain leading zeroes. I use this most when I create extract files that need leading zeroes to be retained (ON TABLE HOLD AS MYFILE FORMAT ALPHA).

Here's an example using the CAR table:

DEFINE FILE CAR
CNT/I2 WITH MODEL = CNT + 1;
A_CNT/A2 WITH MODEL = IF CNT EQ 1 THEN '1' ELSE '2';
I_CNT/I2L WITH MODEL = EDIT(A_CNT);
-*
END
TABLE FILE CAR
PRINT
CAR
MODEL
CNT
A_CNT
I_CNT
WHERE RECORDLIMIT EQ 2
END

Jim


WF DevStu 5.2.6/WF Srv 5.2.4/Win NT 5.2