Padding a Stage Variable with zeros in front

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
jweir
Participant
Posts: 134
Joined: Wed Aug 04, 2010 12:31 pm

Padding a Stage Variable with zeros in front

Post by jweir »

Hello,

I am trying to pad a stage variable with zeros in front of it. This stage variable is a counter, but it is not static counter; it resets to zero often. So it is unsure how many characters will be in the stage variable at a given time. Also, the stage variable has to be 3 characters long, and it is a Char variable type. I am trying to do this in a transformer, if possible. Does anyone have any suggestions?

I tried PadString function but that did not work...
Jweir

--- If strength were all, tiger would not fear scorpion.
datskosaraju
Premium Member
Premium Member
Posts: 48
Joined: Tue Nov 25, 2008 11:10 pm
Location: Des Moines,IA

Post by datskosaraju »

"So it is unsure how many characters will be in the stage variable at a given time. Also, the stage variable has to be 3 characters long"

The above statements are a perfect contradiction.
"It's easier to go down a hill than up it but the view is much better at the top"
-Bennet,Arnold
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Code: Select all

Right('000':Cntr,3)
You are the creator of your destiny - Swami Vivekananda
jweir
Participant
Posts: 134
Joined: Wed Aug 04, 2010 12:31 pm

Post by jweir »

datskosaraju wrote:"So it is unsure how many characters will be in the stage variable at a given time. Also, the stage variable has to be 3 characters long"

The above statements are a perfect contradiction.
It means that the variable has to be 3 chars long. But the counter will be an unknown length inside the variable. I suppose you needed a little bit more explination.
Jweir

--- If strength were all, tiger would not fear scorpion.
jweir
Participant
Posts: 134
Joined: Wed Aug 04, 2010 12:31 pm

Post by jweir »

I have used this logic, which is correct:

Str('0',3 - Len(Counter)) : Counter

Where 'Counter' is my stage variable.
Jweir

--- If strength were all, tiger would not fear scorpion.
datskosaraju
Premium Member
Premium Member
Posts: 48
Joined: Tue Nov 25, 2008 11:10 pm
Location: Des Moines,IA

Post by datskosaraju »

If it is the case, then you question has already been answered :D
"It's easier to go down a hill than up it but the view is much better at the top"
-Bennet,Arnold
asorrell
Posts: 1707
Joined: Fri Apr 04, 2003 2:00 pm
Location: Colleyville, Texas

Post by asorrell »

FYI - Anbu's method (Using "Right") is marginally faster.
Andy Sorrell
Certified DataStage Consultant
IBM Analytics Champion 2009 - 2020
Post Reply