varchar to char truncate issue

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
koojo
Premium Member
Premium Member
Posts: 43
Joined: Sun Jul 11, 2004 1:30 pm
Location: USA

varchar to char truncate issue

Post by koojo »

I have data going in form a Varchar field to a char field.

varchar 255 (from file) to char 5 (db2). Input string string 1234567(varchar255) is loaded to db2 table as 12345 (char5)

The last two digits in the string are truncated without a warning or a database error, WITHOUT WRITING ANY CODE is it posible to generate a warning or a database error for this scenario? any APT_*** setting that would do this?

Where does the truncate happen in datastage or in db2?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

It doesn't really matter where it happens, there's just no way to shoehorn seven characters into a Char(5) column.

My guess would be that it happens in DataStage - you could check that easily enough by changing the target (or adding a second target) that is a text file.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Mike
Premium Member
Premium Member
Posts: 1021
Joined: Sun Mar 03, 2002 6:01 pm
Location: Tampa, FL

Post by Mike »

Run it through a copy stage with varchar(255) on the input side and char(5) on the output side and you'll generate a warning about an implicit conversion... in fact any stage other than a transformer will likely generate the implicit conversion warning.

Mike
Mike
Premium Member
Premium Member
Posts: 1021
Joined: Sun Mar 03, 2002 6:01 pm
Location: Tampa, FL

Post by Mike »

Of course you'll get the implicit conversion warning even if all of your input is less than 5 characters.

If it is important for your application to detect truncation, then design it into your application.

Mike
koojo
Premium Member
Premium Member
Posts: 43
Joined: Sun Jul 11, 2004 1:30 pm
Location: USA

Post by koojo »

ray.wurlod wrote:It doesn't really matter where it happens, there's just no way to shoehorn seven characters into a Char(5) column.
I do not want to shoehorn seven characters into a char(5) column datastage does that by truncating the last two digits.

I am trying to detect the records that have the seven characters in the file. One way that I can do it is by finding the length of the string and passing it down a link if it is greater than 5 char.
I want to detect the record with seven characters without making a code change and have datastage throw a warning or a error when the 7 characters is fed to a char(5) column. Can this be done? My guess from your response is NO. Do correct me if you think I am wrong.

Note: The copy stage throws an warning that I am trying to get varchar 255 to a char(5). I use varchar 255 to read the delimited flat file. I am only need the warning/error on the record if the length of the string is greater than 5.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Use a Modify or Transformer stage and use an explicit function to effect the truncation, and the warning should go away.
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