Trim on char fields

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
zulfi123786
Premium Member
Premium Member
Posts: 730
Joined: Tue Nov 04, 2008 10:14 am
Location: Bangalore

Trim on char fields

Post by zulfi123786 »

Hi,

I am trying to read a sequential file having 10 columns all defined as varchar.
A transformer stage follows the sequential file where i am converting some varchar to char. There is a field 'GMAB' of length 3 having value 'IN ' for all the records.

In the transformer stage i am using TrimLeadingTrailing function on the field and mapping to o/p as char(3). now when i am checking using the condition " If TrimLeadingTrailing(GMAB) = 'IN' Then 1 Else 0 " in another transformer which is the last stage of my job, is giving the value '0'.


What could be the possible reason
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You can't trim spaces from a char. Why not simply check for = 'IN ' instead?
-craig

"You can never have too many knives" -- Logan Nine Fingers
zulfi123786
Premium Member
Premium Member
Posts: 730
Joined: Tue Nov 04, 2008 10:14 am
Location: Bangalore

Post by zulfi123786 »

chulett wrote:You can't trim spaces from a char. Why not simply check for = 'IN ' instead? ...
i need this field to make joins, so should trim it.
narasimha
Charter Member
Charter Member
Posts: 1236
Joined: Fri Oct 22, 2004 8:59 am
Location: Staten Island, NY

Post by narasimha »

Is it ok if you do not do the conversion from varchar to char? Then the TrimLeadingTrailing function would work.
Narasimha Kade

Finding answers is simple, all you need to do is come up with the correct questions.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Joining to another char field of the same size? If so, then no trim needed. If something else, then please explain.
-craig

"You can never have too many knives" -- Logan Nine Fingers
zulfi123786
Premium Member
Premium Member
Posts: 730
Joined: Tue Nov 04, 2008 10:14 am
Location: Bangalore

Post by zulfi123786 »

narasimha wrote:Is it ok if you do not do the conversion from varchar to char? Then the TrimLeadingTrailing function would work.
The problem is that i need to convert it to char. so i am searching for a solution!!!
zulfi123786
Premium Member
Premium Member
Posts: 730
Joined: Tue Nov 04, 2008 10:14 am
Location: Bangalore

Post by zulfi123786 »

chulett wrote:Joining to another char field of the same size? If so, then no trim needed. If something else, then please explain. ...
I need to join this field with another field of length char(1)
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

And by "join" you mean in the database / sql sense rather than say, concatenation, yes? What are your rules for "joining" a char(1) with a char(3)? :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
zulfi123786
Premium Member
Premium Member
Posts: 730
Joined: Tue Nov 04, 2008 10:14 am
Location: Bangalore

Post by zulfi123786 »

chulett wrote:And by "join" you mean in the database / sql sense rather than say, concatenation, yes? What are your rules for "joining" a char(1) with a char(3)? :? ...
isn't is possible to join char(1) field with char(3) field???
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

All things are possible, but think about it. Out of the box the only values that may match to the char(1) are 1 character values in the char(3) field, is that what you need? Or are they a match if the first character is the same in both fields? You'd have to tell us what your match rules are.
-craig

"You can never have too many knives" -- Logan Nine Fingers
zulfi123786
Premium Member
Premium Member
Posts: 730
Joined: Tue Nov 04, 2008 10:14 am
Location: Bangalore

Post by zulfi123786 »

chulett wrote:All things are possible, but think about it. Out of the box the only values that may match to the char(1) are 1 character values in the char(3) field, is that what you need? Or are they a match if the first character is the same in both fields? You'd have to tell us what your match rules are.
you are right. o in char(only those values which are of length 13) field have to be matched with the other char(1) field. so i want to trim the char(3) field so as to remove any leading spaces, is this possible without changing the datatype of char(3) to varchar. If so please suggest.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Hmmm... 13? New number here. Sure, leading spaces can be trimmed from a char field. It's the trailing ones being discussed as problematic here, the "padding" that is automatically done for the data type to its full size. Sorry if that wasn't clear.
-craig

"You can never have too many knives" -- Logan Nine Fingers
zulfi123786
Premium Member
Premium Member
Posts: 730
Joined: Tue Nov 04, 2008 10:14 am
Location: Bangalore

Post by zulfi123786 »

chulett wrote:Hmmm... 13? New number here. Sure, leading spaces can be trimmed from a char field. It's the trailing ones being discussed as problematic here, the "padding" that is automatically done for the data type to its full size. Sorry if that wasn't clear.
sory it was 3 not 13. one more doubt!! what happen it the trailing spaces are trimmed from a char field and mapped to a field of same length .
Ex: if ID='IN ' now if i trim it would become 'IN' and if i map this to a field char(3) would it again pad a space???
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

It will pad, and it will use whatever character is set as the value of APT_STRING_PADCHAR environment variable as the pad character. If this is a space, then yes, it will pad with spaces. If this is Ctrl-@, then it will pad with Ctrl-@ (NUL) characters.
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