× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Birgitte

Although RPG itself cannot return a NULL, the SQL parameter style or the GENERALWITH NULLS makes it possible, with the use of NULL indicator parameters, for the calling SQL statement to get a NULL.

Vern

At 12:26 AM 12/19/2006, you wrote:

Hi Dan,

A RPG function cannot return NULL values, but instead of writing an RPG
function and registering it as external UDF, you also can write a UDF with
pure SQL. In an SQL defined UDF it is possible to return a NULL values.

The following example shows a script for an UDF, that converts 4 numeric
values into a real date. If an error occurs a NULL value will be returned:

Create Function MySchema/CvtNumToDate (
       ParCent  Decimal(2, 0), ParYear Decimal(2, 0),
       ParMonth Decimal(2, 0), ParDay  Decimal(2, 0))
       Returns Date
       Language SQL
       Deterministic
       Reads SQL Data
       Called on NULL Input
       Disallow Parallel
    Begin
       Declare Continue Handler for SQLException
               Return NULL;
       Return Date(Digits(ParCent) Concat Digits(ParYear)
                   Concat '-' concat Digits(ParMonth)
                   Concat '-' concat Digits(ParDay));
   End;

Mit freundlichen Gruessen / Best regards

Birgitta Hauser

"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)



-----Ursprüngliche Nachricht-----
Von: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] Im
Auftrag von Dan
Gesendet: Friday, December 15, 2006 22:39
An: Midrange Systems Technical Discussion; RPG400-L@xxxxxxxxxxxx
Betreff: Help with UDFs or stored procedures


(Cross-posted to midrange-l and rpg400-l)

Our legacy database files are littered with dates defined as four numeric
fields, with a 2-digit century, 2-digit year, month, and day.  I must work
with these dates in SQL and WrkQry, sometimes in RPG.  I would like to
define either a UDF or stored procedure or *something* that would convert
four input parameters into a date result.  It would be nice if I could use
the same function in an SQL statement and in RPG code, but not a
requirement.

So, I need to read up on how to do this, and how to choose UDF vs. stored
procedure.  I searched the archives, saw a few examples of code, but did not
see any reference on how to call the UDF or stored procedure.

Can anyone suggest good online references?

TIA,
Dan
--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or
change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.





--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or
change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.





--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.