Char / varchar reading and trimming trailing Nulls char(0)

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
jking123
Premium Member
Premium Member
Posts: 29
Joined: Tue Mar 23, 2004 9:18 pm

Char / varchar reading and trimming trailing Nulls char(0)

Post by jking123 »

Am trying to read a fixed width char field from the database.
I can see that the file on the output has trailling 0s so in HEX it would be say
50 2D 00 00 00 00
I want to trim these or atleast replace with spaces.
I have tried convert(char(000)," ", ..)
also have set the APT_PADCHAR to 0x20

This doesn't seem to be working.
roy
Participant
Posts: 2598
Joined: Wed Jul 30, 2003 2:05 am
Location: Israel

Post by roy »

Hi,
From what I understand you simply need to change the data type to varchar to resolve your issue.

Please reply if this is not the case.

IHTH,
Roy R.
Time is money but when you don't have money time is all you can afford.

Search before posting:)

Join the DataStagers team effort at:
http://www.worldcommunitygrid.org
Image
jking123
Premium Member
Premium Member
Posts: 29
Joined: Tue Mar 23, 2004 9:18 pm

Re: Char / varchar reading and trimming trailing Nulls char

Post by jking123 »

Hi roy.I have tried with datatype varchar with no lenght and also with max length.
Here are the diff examples
ie.e if the input is HEX= "50 2D 00 00 00 00"
Then if I put a varchar(max=2) I will get "50 2D" correctly,
If I put varchar I get "50 2D 00 00 00 00"
If I put varchar(max=4) I will get "50 2D 00 00"
roy
Participant
Posts: 2598
Joined: Wed Jul 30, 2003 2:05 am
Location: Israel

Post by roy »

Reading with varchar won't do, but reading char and type-casting to varchar should do it.
Roy R.
Time is money but when you don't have money time is all you can afford.

Search before posting:)

Join the DataStagers team effort at:
http://www.worldcommunitygrid.org
Image
jking123
Premium Member
Premium Member
Posts: 29
Joined: Tue Mar 23, 2004 9:18 pm

Re: Char / varchar reading and trimming trailing Nulls char

Post by jking123 »

Roy,
I changed the reading column type from varchar to char(8).
In a transformer I mapped it to varchar.
Same issue.
Is there some other way I should be converting
jking123
Premium Member
Premium Member
Posts: 29
Joined: Tue Mar 23, 2004 9:18 pm

Re: Char / varchar reading and trimming trailing Nulls char

Post by jking123 »

If I perform a simpel tr on the file the nulls vanish.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Try the convert after setting APT_PADCHAR to ' ' (Space).
You can optionally perform the tr in the filter command if its a sequential file or in External filter stage if the source is database.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
jking123
Premium Member
Premium Member
Posts: 29
Joined: Tue Mar 23, 2004 9:18 pm

Post by jking123 »

Thanks kumar. I had tried both ' ' and " ". Will try aging and see if I missed soemthng.
Yes am currently putting tr in the filter while writing and reading. One thing I notices though is while writing if you have 2 seq files and if you put tr on both my job seems to hang as in, it doesn't finish.
Post Reply