attaching 0 before an integer

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
arnie_nits
Participant
Posts: 101
Joined: Mon Aug 13, 2007 2:32 am

attaching 0 before an integer

Post by arnie_nits »

Hi

I have an integer field of length 11. Now I need to attach Zeros before it, in the empty spaces.
e.g if input column is 124125,then I must get 00000124125
What I have done is - IntegerToDecimal(input column) in stage variable.....then Str('0',11-input column):input column in derivation.

But I am getting 00000000 instead of say 00000124125. Someone plz help.

Regards
Arnie
rsomiset
Premium Member
Premium Member
Posts: 46
Joined: Fri Sep 21, 2007 7:16 pm

Post by rsomiset »

Hi Arnie,
I think that 'Fmt' Function will help in achieving your desired output.

Regards,
Rajesh.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

An integer field does not contain leading zeroes. If you convert your integer to a string then you can use the str function as you mentioned. If you write this integer column to a text file you can also prepend leading zeroes (basically because everything going into a text file is a string).

So in order to really answer your question we need to know where this integer column is being written to.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Fmt() is a BASIC function and thus not available in parallel Transformer stage. As Arnd says, integers do not have leading zeroes; they are stored internally in binary format. Therefore, if you need leading zeroes, you also need an appropriate data type (a string of some kind). But ask yourself whether the leading zeroes are really necessary.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
divine
Premium Member
Premium Member
Posts: 149
Joined: Fri Oct 15, 2004 12:13 am
Location: Toronto,divine_auro@yahoo.co.in
Contact:

Post by divine »

Hi
Can you try with following:

Str('0',-11-input column)
With Regards
Biswajit
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You've all missed the vital Len() function. Assuming the target is a string data type:

Code: Select all

Str('0',11-Len(input column)):input column 
The conversion to string for the Len() function will occur implicitly.
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