I am wanting ao add leading zero's to a numeric field if it is not 10 characters long.
I know the FMT Function is used for string fields but what can I use for a numeric field ?
Leading Zero's on Numeric Fields
Moderators: chulett, rschirm, roy
Re: Leading Zero's on Numeric Fields
JezT wrote:I am wanting ao add leading zero's to a numeric field if it is not 10 characters long.
I know the FMT Function is used for string fields but what can I use for a numeric field ?
Alternate Way:
If LEN(NUMERIC_FIELD) < 10 then oconv(NUMERIC_FIELD,"MR%10") else
NUMERIC_FIELD
Hope this helps.
thanks
Pramod
Thanks
Pramod
Pramod
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
There are no data types within DataStage; everything is handled as string unless the context requires otherwise. So you can use FMT on "numeric" fields. You can use NUM to test whether a string can legally be regarded as numeric.
Cameron's reply can be improved in two ways. Because you specified numeric, he should have used right justified rather than left justified.Cameron's solution ("10'0'L") would give you trailing zeroes!
An alternative (short cut?) syntax is to use the special mask character "%" which specifies a background character of "0", to achieve the same result.
which is shorthand notation for
both of which mean "lay down YourNumber right-justified over a background of ten zeroes".
Cameron's reply can be improved in two ways. Because you specified numeric, he should have used right justified rather than left justified.
Code: Select all
Fmt(YourNumber, "10'0'R")
An alternative (short cut?) syntax is to use the special mask character "%" which specifies a background character of "0", to achieve the same result.
Code: Select all
Fmt(YourNumber, "R%10")
Code: Select all
Fmt(YourNumber, "R%%%%%%%%%%")
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.