Leading Zero's on Numeric Fields

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
JezT
Participant
Posts: 75
Joined: Wed Sep 15, 2004 1:52 am

Leading Zero's on Numeric Fields

Post by JezT »

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 ?
xcb
Premium Member
Premium Member
Posts: 66
Joined: Wed Mar 05, 2003 6:03 pm
Location: Brisbane, Australia
Contact:

Post by xcb »

You can still use FMT, try FMT([your number], "10'0'L") which will append up to 10 leading zeros.
Cameron Boog
pramod_au
Participant
Posts: 30
Joined: Thu Feb 06, 2003 8:30 am
Location: London,UK

Re: Leading Zero's on Numeric Fields

Post by pramod_au »

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
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

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.

Code: Select all

Fmt(YourNumber, "10'0'R")
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.

Code: Select all

Fmt(YourNumber, "R%10")
which is shorthand notation for

Code: Select all

Fmt(YourNumber, "R%%%%%%%%%%")
both of which mean "lay down YourNumber right-justified over a background of ten zeroes".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply