FMT function

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
fridge
Premium Member
Premium Member
Posts: 136
Joined: Sat Jan 10, 2004 8:51 am

FMT function

Post by fridge »

I simply want to pad a field with a number of leading zeros but the specific number is the value of an argument passed to the code.

I have tried
PadUnSigArg1 = FMT(UnSigArg1, "Arg1'0'R")
which does not work

and
PadUnSigArg1 = 0(Arg1 - Len(UnSigArg1)):UnSigArg1
which almost works
0.0000000123456

I realise I can manipulate the second result to get what I want but can I do it cleaner?

Any solution would be greatly appreciated.
WoMaWil
Participant
Posts: 482
Joined: Thu Mar 13, 2003 7:17 am
Location: Amsterdam

Post by WoMaWil »

If you want to write a routine with a total of 7 letters or digits and if your number is less then 7 and you want the rest to be filled with Zero you write the following code into your Routine:

Ans=FMT(Arg1,"7'0'R")

and if you want to have it flexible use a second Argument Arg2

pFormat=Arg2:"'0'R"
Ans=FMT(Arg1,pFormat)

That's it.

Wolfgang
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Can you please delete this post from Editor's Corner?
It's not necessary to post on every Forum.

Wolfgang's answer is 100% correct. However there is an alternative syntax that some people prefer.

Code: Select all

Fmt(TheString, "R%":Arg1)
The "%" character has the special meaning of "use zero as a background character" in the formatted result.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
fridge
Premium Member
Premium Member
Posts: 136
Joined: Sat Jan 10, 2004 8:51 am

Post by fridge »

Thanks for the help guys!
Post Reply