Focal Point
how to add leading zeros

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

December 28, 2007, 01:48 PM
vkrugman
how to add leading zeros
Hi, could someone remind me how to add leading 0? Number of 0 could be different each time.
It's alpha field I'm working with
Thanks


Valeriya

WebFOCUS 764 Servlet - MRE/Dashboard/Self Service/ReportCaster - Windows 2000
December 28, 2007, 02:17 PM
Prarie
This is what IBI says to do.

DEFINE FILE CAR
VAR1/A10 WITH CAR ='0';
VAR2/D10L=ATODBL(VAR1,10,'D10');
VAR3/A10=FTOA(VAR2,'(D10Lc)',VAR3);
END
TABLE FILE CAR
PRINT CAR VAR1 VAR2 VAR3
END


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
convert the alpha field to integer and then back to alpha and the EDIT will pack it out with leading zeroes, whether you want it to or not.
DEFINE FILE CAR
MYALPHAFIELD/A8=EDIT(SALES);
temp/I8=EDIT(MYALPHAFIELD);
RESULT/A8=EDIT(temp);
END

another way , maybe more direct, is to use CTRAN which translates all instances of character in an alpha string to another character
in this case a blank (32) to a zero(48)
DEFINE FILE ...
NEWFIELD/A20=
CTRAN ( 20, fieldname , 32 , 48, 'A20');
END
(example for a field of length 20)

i find either of these ways easier than the ibi suggested hoops to jump thru. The CTRAN way would work even if some freaky alpha character snuck its way in to your input field. You might even want to RJUST your input field before you CTRAN it, just to make sure there's no freaky extra blank at the end, entered by mistake. Look at the 4th manual in the basic set, "Using Functions"




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
Add an "L" to the format of your output field. I.E. "D12.2L" or "I11L". This will automatically pack out leading zeros to the max size.


WF 7703M, XP/Win7, MRE, RC, BID, PMF, HTML, PDF, Excel 2000/7/10
Alex

The question was that Lera used an alpha field. Your solution only works for numeric fields.




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

Adding the setting:
SET CENT-ZERO = ON
may also help.
But that is also just for numeric fields....


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988