generate zeros based on input

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
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

generate zeros based on input

Post by DSguru2B »

I have a column where the length of the field has to be 6. if it is less than 6, i have to keep the length of the field as 6 and add zeros on the remaining field.
I am checking the length of the field by the Len() function. but how to put that many zeros in that field. Can it be done within the transformer or i need to write a routine for it.
thanks guys.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Check out the FMT command. It can justify and zero fill to a specific number of digits in a derivation.
-craig

"You can never have too many knives" -- Logan Nine Fingers
jenkinsrob
Participant
Posts: 31
Joined: Mon Dec 01, 2003 6:24 am
Location: London

Post by jenkinsrob »

Try the following code in a Stage Variable in your transformer

Code: Select all


<Field>:Str("0", 6 - Len(<Field>))

chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Why code it when there are built in functions to do that work? :?

Check this post for a couple of examples of how to use the FMT command.
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

It works. Thanks guyz.
Post Reply