SetNull produces 0 instead of NULL for integer column?

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
IsNull
Participant
Posts: 10
Joined: Sat Dec 01, 2012 5:56 am

SetNull produces 0 instead of NULL for integer column?

Post by IsNull »

Disclaimer: I'm DataStage noob....

I have a IfThenElse function/derivation in the Transform stage:

If DSLink2.SalesAmount = 'NA' Then SetNull() Else DSLink2.SalesAmount

DSLink2.SalesAmount is an integer column. When populating this data into a sequential file, I get a value 0 instead of NULL in the column. To my understanding, SetNull() should produce NULL, not 0? What I'm missing here? Thanks!
SURA
Premium Member
Premium Member
Posts: 1229
Joined: Sat Jul 14, 2007 5:16 am
Location: Sydney

Re: SetNull produces 0 instead of NULL for integer column?

Post by SURA »

Integer hold the 0 is the reason.
Thanks
Ram
----------------------------------
Revealing your ignorance is fine, because you get a chance to learn.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

0 <> "NA"

Nor can "NA" ever be an integer value.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
IsNull
Participant
Posts: 10
Joined: Sat Dec 01, 2012 5:56 am

Post by IsNull »

Thanks for the reply. My parallel job data flow is

Seq. File --> transform --> seq. File

In the first seq. File there is data in the integer column

1, 5, NA, 8 ...

NA stands for a missing value. My intention is to convert NA --> NULL using

If col = 'NA' Then Setnull() else col

And this produces 0 instead of NULL in the text file. This is wrong because 0 denotes as a true integer value rather than a missing value. Anu ideas?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

How have you set the Null Field Value and Default Value properties for this column?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
IsNull
Participant
Posts: 10
Joined: Sat Dec 01, 2012 5:56 am

Post by IsNull »

Actually I figured it out, this works:

If DSLink2.Ozone = 'NA' Then 'NULL' Else DSLink2.Ozone

I was thinking this too complicated, thanks for your insights!
abhijain
Participant
Posts: 88
Joined: Wed Jun 13, 2007 1:10 pm
Location: India

Post by abhijain »

Good that you figured it out. but This can be handle using below logic as well.

Since your source is Sequential file. the particular INTEGER column can be read as "Varchar"
In transformer, you can validate it using below logic

If Num(Integer Column) Then Integer Column Else SetNull()

And, since your target is also Sequential file. You can set the file properties
- NulltoValue as ' '
this will give you empty in the target file, if your 'NA' or non-integer value appear in source.

This way, you will be able to handle all Non-integer values and not only NA.
Rgrds,
Abhi
IsNull
Participant
Posts: 10
Joined: Sat Dec 01, 2012 5:56 am

Post by IsNull »

@abhijain: very good point, thank you !
Post Reply