Appending the spaces with Zero

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
LavanyaRamesh007
Participant
Posts: 42
Joined: Mon Apr 21, 2008 1:49 am

Appending the spaces with Zero

Post by LavanyaRamesh007 »

Hi,

My requirement is such that I need to append zeros with my input file. The output length is 5. I might get an input from 1 length to 5 length. Say the input 'ABC' (length 3)

Input='ABC'

Output='ABC00'

Then my output must append two zeros. length of input is 4, then 1 zero needs to be appened..
'Kindly help me
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

LEFT(In.InputColumnName:'00000',5) should do the trick for you assuming your datatype is CHAR or VARCHAR
satishbalantrapu
Participant
Posts: 12
Joined: Wed Jul 25, 2007 6:56 am
Location: Hyd

Post by satishbalantrapu »

If the string is length is more, say 50 then following can be used

Code: Select all

TrimLeadingTrailing(In.InputColumnName):PadString('','0',50-len(TrimLeadingTrailing(In.InputColumnName)))

Thanks,
Satish
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Why not just "LEFT(In.InputColumnName:STR('0',50),50)" - simpler and uses somewhat less CPU?
LavanyaRamesh007
Participant
Posts: 42
Joined: Mon Apr 21, 2008 1:49 am

Post by LavanyaRamesh007 »

ArndW wrote:Why not just "LEFT(In.InputColumnName:STR('0',50),50)" - simpler and uses somewhat less CPU? ...

It woked out. Thanks a lot :D
rajendharreddy
Participant
Posts: 46
Joined: Tue Aug 21, 2007 5:39 am
Location: Bangalore, India

Post by rajendharreddy »

Create a routine with the following code. Call the routine in wherever required.

if Len(In.InputColumnName) = 2 Then Ans = In.InputColumnName:'000'
else if Len(In.InputColumnName) = 3 Then Ans = In.InputColumnName:'00'
else if Len(In.InputColumnName) = 4 Then Ans = In.InputColumnName:'0':
else Ans = In.InputColumnName
OddJob
Participant
Posts: 163
Joined: Tue Feb 28, 2006 5:00 am
Location: Sheffield, UK

Post by OddJob »

Yikes, that last solution is absolute madness :shock:

What happens when the requirement says pad up to 1000 zeros - your cutting and pasting skills will be seriously tested, and the result will be completely unsupportable!
Post Reply