Unusual scenario in datastage

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

soumya5891
Participant
Posts: 152
Joined: Mon Mar 07, 2011 6:16 am

Unusual scenario in datastage

Post by soumya5891 »

I am facing one peculiar problem.In my source I have fixed length file.In a transformer I have taking out the various fields with proper length.
Now let say I have taking out one column and it is space.Now if I apply trim and write only that field in a dataset then one space is there instead of empty.But if we write any other column with that then it is working properly,it's coming as empty.

Can you please help me on this?
Soumya
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Trim(many spaces) always returns one space, not none. This is documented behaviour. There are other functions for removing spaces.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
soumya5891
Participant
Posts: 152
Joined: Mon Mar 07, 2011 6:16 am

Post by soumya5891 »

Hi Ray,

If I write only that field in dataset after trim then one space comes.But if I write any other field along with that field after trim then it comes as empty.I am getting confused in this scenario.
Soumya
zulfi123786
Premium Member
Premium Member
Posts: 730
Joined: Tue Nov 04, 2008 10:14 am
Location: Bangalore

Post by zulfi123786 »

What is the data type of the columns you are talking about ?. Trim - if the whole data is string of only spaces it returns empty, else it strips off the leading and trailing spaces and reduces multiple spaces embedded withing the charactes to single occurence as told by Ray
- Zulfi
soumya5891
Participant
Posts: 152
Joined: Mon Mar 07, 2011 6:16 am

Post by soumya5891 »

My target datatype is VARCHAR(4).
Soumya
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

try trim with option 'A' or convert ' ' to ''
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
PhilHibbs
Premium Member
Premium Member
Posts: 1044
Joined: Wed Sep 29, 2004 3:30 am
Location: Nottingham, UK
Contact:

Post by PhilHibbs »

ray.wurlod wrote:Trim(many spaces) always returns one space, not none. This is documented behaviour.
I think that that statement is incorrect.

Code: Select all

Len( Trim( '   ' ) )
returns 0 for me.

Phil.
Phil Hibbs | Capgemini
Technical Consultant
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

Phil,
And also try

Code: Select all

len('         ')
Now we can understand the behaviour
pandeeswaran
PhilHibbs
Premium Member
Premium Member
Posts: 1044
Joined: Wed Sep 29, 2004 3:30 am
Location: Nottingham, UK
Contact:

Post by PhilHibbs »

That returns 9, there are 9 spaces, but if you trim() it there will be 0 spaces. I don't understand what this demonstrates, other than that trim(many spaces) returns an empty string, not a single space, contrary to what Ray stated.
Phil Hibbs | Capgemini
Technical Consultant
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

Thanks Phil!!
I believe

Code: Select all

trim(many spaces)
returns no spaces.( i feel this is the usual behavior of trim).
pandeeswaran
chandra.shekhar@tcs.com
Premium Member
Premium Member
Posts: 353
Joined: Mon Jan 17, 2011 5:03 am
Location: Mumbai, India

Post by chandra.shekhar@tcs.com »

As Zulfi has mentioned, trim functions removes the leading and trailing spaces and reduces multiple spaces embedded withing the characters to single occurrence. There should not be any confusions now.
Thanx and Regards,
ETL User
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

chandra.shekhar@tcs.com wrote:multiple spaces embedded withing the characters to single occurrence.
Can you elaborate this part?
What i feel is, at the result of trim() the number of spaces will be zero(not even single)
pandeeswaran
chandra.shekhar@tcs.com
Premium Member
Premium Member
Posts: 353
Joined: Mon Jan 17, 2011 5:03 am
Location: Mumbai, India

Post by chandra.shekhar@tcs.com »

@Pandeesh
The following example will make you understand

Code: Select all

trim('  IBM   DataStage  ') = 'IBM DataStage'
Thanx and Regards,
ETL User
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

yes Chandra!!
Its clearly derived that

Code: Select all

trim(many spaces)-->No spaces(leading and trialing ,not a single occurrence even).
This is what initially phil claimed!
pandeeswaran
chandra.shekhar@tcs.com
Premium Member
Premium Member
Posts: 353
Joined: Mon Jan 17, 2011 5:03 am
Location: Mumbai, India

Post by chandra.shekhar@tcs.com »

That is also true. :o
Thanx and Regards,
ETL User
Post Reply