Tuesday, February 23, 2010

Setting Date Variables to Null in PeopleCode

If you try to assign a date variable a null value you will get an error saying that the left and right sides of the assignment are not compatible.

For instance, the following PeopleCode would error out:

Local date &myDate;

&myDate = null;

To perform this kind of assignment, you may use the Date function in the following way:

Local date &myDate;

&myDate = Date(0);


Neeraj Kholiya said...

Hi Sir

faced same issue last week , tried this one

local date &testdate ;

Record.field.value = &testdate;

by default &testdate is NUll :

Javier Delgado said...

That's right Neeraj, although I prefer to specifically assign values to variables rather than use their default vale. Anyway, that's more a question of programming style of each developer.

Thanks for your feedback.

Anand said...

Hello Javier,
Thanks for such a nice blog.
We would like to have your comments on below site being developed for peoplesoft developers to help PeopleSoft Community.
we expect response from you.
Thanks in advance for your time and comments.

Javier Delgado said...

Hi Anand

No problem, I'll be happy to contribute to your PeopleSoft community. It seems a good place to share information among PeopleSofters.


Parag said...

or you could simply do it with %DateNull

Javier Delgado said...

Hi Parag

The %DateNull seems to be Meta-SQL and as far as I tried would not work in PeopleCode (I've tried with PeopleTools 8.50). Also checked the PeopleBooks documentation and it does not appear as a system variable but only as Meta-SQL.

Which PeopleTools version were you using to make the %DateNull value work?

Thanks for your contribution.

wlaw said...
This comment has been removed by the author.
wlaw said...

Parag is right.

%DateNull is applicable for use in PeopleCode, AE, SQL

Rakesh @ Psoftsearch said...

Last week a delivered code was throwing an error like this. We found that the culprit was a month() to which a null value was being passed.

Eva Lona said...

Hi im eva peoplesoft consultant. I was just browsing blogs there I found your blog is interesting.. thanks for posting… keep on posting mypeoplesoft

Javier Delgado said...

Thanks Eva!

Peoplesoft forum said...

Great job keep it up.

Kyle Hall said...

Thanks Javier :)
I googled and your post helped me today.

-Kyle from Belize :)

Javier Delgado said...

You're welcome Kyle! Nice to see you here :)

David said...

Almost seven years later, and this blog entry is still helping people... :-)

David said...

And whaddya know, now I have a followup question....

How would you assign a datetime variable to null?

Javier Delgado said...

Hi David

I think the following should work:

Local datetime &dt;

&dt = Date(0) + Time(0);

Let me know if it doesn't.