how to avoid warngs when convert from varchar(10) to char(4)

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

rparimi
Participant
Posts: 20
Joined: Tue Oct 12, 2004 2:01 pm

how to avoid warngs when convert from varchar(10) to char(4)

Post by rparimi »

I am using a modify stage and in specification i specified

target_column:string = source_column

where target_column is specified as CHAR(4) and source column is defined as Varchar(10)

I am getting warning with possible trucation. how can i avoid this warning message.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Ensure that you don't send more than four characters to the target field.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

What Craig has stated is that in order to avoid real data truncation your source column cannot contain more than 4 characters. To avoid the warning your datatype's metadata needs to be 4 or less characters as well.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You can achieve this by truncating it earlier in the job, using probably a Modify stage or a Transformer stage.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Perhaps using the same Transofrmer stage to fetch first 4 char(may be after Trim()) and map to Char(4). If its sure that, the input may not contain more that 4 char.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
rparimi
Participant
Posts: 20
Joined: Tue Oct 12, 2004 2:01 pm

thanks all for the replies

Post by rparimi »

thanks every one for their reply. i can use Left() function to get the required four characters from the source_column. is there any other way of doing the same... without using Left/Right functions
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If that's all the transformation you need to do, prefer a Modify stage (it's far more light weight). Use the substring function in that stage.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
rparimi
Participant
Posts: 20
Joined: Tue Oct 12, 2004 2:01 pm

Post by rparimi »

thank you.... ithink that is more efficient than using a transformer
rparimi
Participant
Posts: 20
Joined: Tue Oct 12, 2004 2:01 pm

Post by rparimi »

Hi Ray,
I used a substring function and in the specification, i included

Code: Select all

target_column:string[4]=Handle_Null(substring[0,4](source_column),"").
though the field is converted from length(10) to length(4), i am getting a warning message
Modify_135: When checking operator: When binding output schema variable "outRec": When binding output interface field "target_column" to field "source_column": Conversion from source type "string[max=10]" to result type "string[max=10]": Taking substring of variable-length source string.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Your replacement value for null does not contain four characters. It must, if it's destined for a string[4] field.

Irrespective of that, Modify is very verbose about what it's doing. Create a message handler to demote this warning to an informational message.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
rparimi
Participant
Posts: 20
Joined: Tue Oct 12, 2004 2:01 pm

I am still getting warning message

Post by rparimi »

I am still getting warning messages though i converted the replacement string to 4 characters.. the specification looks like

Code: Select all

target_column:string[4]=Handle_Null(substring[0,4](source_column),"xxxx").
I am still getting the same warning message. Please suggest if there is any alternative
Modify_135: When checking operator: When binding output schema variable "outRec": When binding output interface field "target_column" to field "source_column": Conversion from source type "string[max=10]" to result type "string[max=4]": Taking substring of variable-length source string.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Try to trun off the RCP.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

I hate to say it and it probably makes me a lazy programmer but this is why I don't spend a lot of time trying to get warning messages to go away. :evil: You can lose days on it and the behaviour of the job does not change one whit. Go for the message handler if you are sure the warning is not harming your job and it has been accepted by your testers.
Meera
Premium Member
Premium Member
Posts: 21
Joined: Mon Nov 28, 2005 8:42 pm

Post by Meera »

Hi

Try this

targetcolumn:string[4] =Handle_null(string_trim(source_column),"xxxx")

It works for me
rparimi
Participant
Posts: 20
Joined: Tue Oct 12, 2004 2:01 pm

that works..

Post by rparimi »

Hi Meera..
this worked for me.. thanks for resolving the issue.

thanks everyone for their input and suggestion.
Post Reply