Trim on char datatype

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
thatiprashant
Participant
Posts: 25
Joined: Mon Sep 19, 2005 11:32 am

Trim on char datatype

Post by thatiprashant »

Hi Guru's,

I am pretty much new to datastage, currently i am experiencing a probs
where in my source datatype is char(40) when i trim this column and use
for comparing with other varchar column which holds the same data as this,
it is reading the columns as seperate data eventhough they have same values
in both columns.

thanks
prashant
meena
Participant
Posts: 430
Joined: Tue Sep 13, 2005 12:17 pm

Post by meena »

Hi...
Can you explain about your job design.....
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Trimming a CHAR(10) field with the value of "hello " will result in a value of "hello " (i.e. unchanged!) if it is being put back into a CHAR(10) field. You need to ensure that your comparison works on identical data types. If you do a transform stage and execute a derivation "IF TRIM(In.CharField)=TRIM(In.VarCharField) THEN 1 ELSE 2" it should work correctly.
thatiprashant
Participant
Posts: 25
Joined: Mon Sep 19, 2005 11:32 am

Post by thatiprashant »

meena wrote:Hi...
Can you explain about your job design.....
thanks for the prompt reply.

My design is

database --------> dataset1
char(40) Trim Char(40) prash(data)
COLname Order
database --------> dataset2
varchar(40) varChar(40) prash(data)
Colname order1

lets say my condition is if (order1<>order) then 0 else 1

in normal scenario it shud go to 1 as both has got the same data,but it
is going to 0 considering the data as different


thanks
prashant
meena
Participant
Posts: 430
Joined: Tue Sep 13, 2005 12:17 pm

Post by meena »

Hi..
I think you are using a lookup stage..Can you try to do TRIM on the column of dataset2 too...I am not sure whether this is going to work or not but just giving you an option to try..
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Convert your dataset to VarChar(40) and trim your strings.
thatiprashant
Participant
Posts: 25
Joined: Mon Sep 19, 2005 11:32 am

Post by thatiprashant »

ArndW wrote:Convert your dataset to VarChar(40) and trim your strings. ...

thanks Arndw,

with varchar(40) it is working but i was just wondering why it is not working with char(40) is there any particular reason why its not working
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

Because you cannot perform TRIM function on CHAR datatypes. :wink:
Kris

Where's the "Any" key?-Homer Simpson
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You CAN use Trim on Char data types but, because the target field is Char, it is then automatically padded again with $APT_STRING_PADCHAR 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.
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

I meant that but should have put it more clearly that CHAR datatype respects the length of the field and pads characters.
Kris

Where's the "Any" key?-Homer Simpson
SAMEENA
Participant
Posts: 31
Joined: Fri Aug 18, 2006 12:13 am
Location: INDIA

Post by SAMEENA »

Hi everyone,
I have a similar problem.

The database we are using is DB2.

In my job I read data from a table using DB2 API stage and write it in a sequential file.

Now in the table I have a field with char(30).When I insert a record with empty string in this column and after doing a ftp; open the sequential file in wordpad I notice a square shaped character used as pad character.This is I suppose a non printable character.

Now if I change the datatype of the column to varchar,I still notice the character , but only one in numbe and not 30 as in the earlier case.

My problem is when I try to filter this record using len() function it does not get filtered out.Trim() is also of no help.

Please help me out.

thanks in advance.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Your Char column IS padded, with ^@ (\x00 if you prefer that notation). These are invisible except with a hex editor. The pad character is set using APT_STRING_PADCHAR environment variable.
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