Problems with Null representation

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
avi21st
Charter Member
Charter Member
Posts: 135
Joined: Thu May 26, 2005 10:21 am
Location: USA

Problems with Null representation

Post by avi21st »

Hi

I am having a strange problem with Datastage :roll:

In the job I am getting Input File as fixed width and in place of null we have blank.

I generally TRIM then value and then check ISNULL - then handle it accordingly{ ISNULL(TRIM(LinkName.ColumnName)}

But Datastage cannot understand that TRIM(" ") is equal to Null.

Even I tried in a routine:

Code: Select all

If TRIM(' ') = @NULL Then Ans='NULL WORKING' Else Ans='NULL NOT WORKING'
But I am always getting 'NULL NOT WORKING'

But generally as far sa I know I always handle Null with the ISNULL. I have no clue-please help me in this regard.

Is there a internal representation of NULLs in Datastage- if so what is the representaion.

Thanks
Avishek Mukherjee
Data Integration Architect
Chicago, IL, USA.
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

I think DataStage is performing correctly. Trimming all spaces will result in an "empty" string and not in a NULL.

That is why,

TRIM(' ') can never be equal to NULL.

If you are trying handle spaces and NULLS in the incoming data, you can use to this code to check for both:

Code: Select all


If Len(Trim('InputLink.InputCol)) = 0
Then "it is spaces or NULL"
Else "It is not spaces or NULL"

Hope that helps,

Naveen.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

There is a difference between blank and NULL. NULL is a physical character on the ASCII chart, blank is a zero length string. You can NEVER, in SQL or DS BASIC, compare ANYTHING to a NULL. You can't do math on NULL values either. That's why there's a specific function in DS BASIC and SQL to handle the NULL value.

You should consider writing either a DS Function or DS Transform to handle both cases. I like to use a function called something like EXISTS.

DS Function logic for EXISTS:

Code: Select all

IF TRIM(Arg1) # "" OR NOT(ISNULL(Arg1)) Then Ans=@TRUE Else Ans=@FALSE
Now, you can just check if data "exists" using this function. It correctly handles both the blank and NULL condition.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You may find the following conceit useful. It applies in DataStage BASIC, please do not assume that it can be generalized beyond that.

LEN("") returns 0.

LEN(@NULL) also returns 0.

That is, Len(X) returns 0 both when X = "" and when X IS NULL.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
NBALA
Participant
Posts: 48
Joined: Tue Jul 11, 2006 11:52 am
Location: IL, USA

Post by NBALA »

Thanks Ray and guys.

I have faced similar issue with spaces in the date field from mainframe source. Before reading this post I used

Code: Select all

  If IsNull(Trim(lnk1.colA)) Then <defualt date> else lnk1.colA
It never worked.

Thanks again guys.

-NB
Post Reply