Null handling in transformer

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

shalini11
Participant
Posts: 74
Joined: Thu Jan 22, 2009 3:00 am

Null handling in transformer

Post by shalini11 »

Hi All,

In the transformer, I have given a condition for a column as:

If Trim(NullToEmpty(Col1))='' Then 'Unknown'
Else Trim(NullToEmpty(Col1))

But the records having Col1 as blank are getting rejected. I dont want to reject the record, rather replace it with "Unknown" if it is blank.

The same condition is working for other 3 columns but not with column.

Can you pls help.

Thanks
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

And 'blank' means what here, exactly?
-craig

"You can never have too many knives" -- Logan Nine Fingers
shalini11
Participant
Posts: 74
Joined: Thu Jan 22, 2009 3:00 am

Post by shalini11 »

Blank means that the value is not present in the input file.The file is tab delimited
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Trim() will not remove all blank spaces, it will leave one. You may need to re-think your logic. For example

Code: Select all

NullToEmpty(Trim(InLink.TheField)) <= " "
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sureshreddy2009
Participant
Posts: 62
Joined: Sat Mar 07, 2009 4:59 am
Location: Chicago
Contact:

Use another logic

Post by sureshreddy2009 »

:oops:
Hi
as you said the file has a Tab delimiter then the sequential file in datastage extracts the data from the file, if any value in file contains null then use this funtion to handle null values in transformer, if your aim is to replace null with 'unknown' then use this funtion If IsNull(Column) then 'Unknown'

in another case, if the field contains empty that is 1 or more spaces then use this funtion
If IsNull(Trim(column)) then 'unknown'
Suresh Reddy
ETL Developer
Research Operations

"its important to know in which direction we are moving rather than where we are"
naveen19
Participant
Posts: 52
Joined: Tue Mar 06, 2007 9:08 am
Location: India
Contact:

Re: Use another logic

Post by naveen19 »

Hi,

You can use this in ur derivation part..

If IsNull(DsLink12.INPUT_COLUMN) Then 'UNKNOWN' Else If Len(TrimB(DsLink12.INPUT_COLUMN)) =0 Then 'UNKNOWN' Else DsLink12.INPUT_COLUMN

Regards...Naveen.K
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Ur was a city in ancient Babylon. The second person personal pronoun in English is spelled "your". Please maintain a professional standard of written English on DSXchange, which is used by many people whose first language is not English.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
shalini11
Participant
Posts: 74
Joined: Thu Jan 22, 2009 3:00 am

Post by shalini11 »

Sorry to say but none of the above solutions are working. The records are still getting rejected. The condition is working fine for other fields. Only 2 fields are creating problem.

Please suggest what to do.

Thanks
preetiv
Participant
Posts: 12
Joined: Tue May 26, 2009 12:58 am

Post by preetiv »

Hi,

What is the datatype of the column? Also, did you check the log to see if there is any info message about why the records are getting rejected?

Thanks,
Preeti
shalini11
Participant
Posts: 74
Joined: Thu Jan 22, 2009 3:00 am

Post by shalini11 »

Column is Varchar. In the log following error is displayed:

Xfm,0: Field 'BodyType' from input dataset '0' is NULL. Record sent to reject dataset.
Swaruparani
Participant
Posts: 5
Joined: Wed Sep 12, 2007 1:54 am
Location: Bangalore

Post by Swaruparani »

hi,

can u try this one:( NullToValue(DSLink3.sal,'Unknown'))
Swarupa
samsuf2002
Premium Member
Premium Member
Posts: 397
Joined: Wed Apr 12, 2006 2:28 pm
Location: Tennesse

Post by samsuf2002 »

Try making the column nullable and if it's an integer then make it varchar ....if it suits your requirement..... later do the nullhandling.

Null handling for integer will be ---> if Isnull(col1) = 0 then 'Unknown'......
hi sam here
shalini11
Participant
Posts: 74
Joined: Thu Jan 22, 2009 3:00 am

Post by shalini11 »

I have tried NullToValue. All the columns are varchar. It is not working.
Earlier I was giving "Null Field Value" in input Sequential file as '' then the records with nulls were getting rejected. So I changed the "Null Field Value" to null.Now records are not getting rejected but I am getting many warnings :
Xfm,0: Null string argument.

These warnings are much more than 50.Please help in getting rid of this warning.

I am not able to understand why the derivations are working by giving "Null Field Value" as null not ''. Can you pls help.
samsuf2002
Premium Member
Premium Member
Posts: 397
Joined: Wed Apr 12, 2006 2:28 pm
Location: Tennesse

Post by samsuf2002 »

Are those columns set as not nullable ? If yes then set them to nullable in seq file and transformer.

What is your job design ?
When you make it as nullable then edit the column and set the null field values = ''.
hi sam here
shalini11
Participant
Posts: 74
Joined: Thu Jan 22, 2009 3:00 am

Post by shalini11 »

The columns are nullable in seq file and transformer. In Seq file, in Formats tab, I have given the Null Field Value as '' but now I have changed it to null.
Post Reply