× 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.



That is all good advice, thanks Scott.

Robert Newton
EDPS
Electronic Data Processing Services
Software Engineer
rnewton@xxxxxxxxxxxxxxxxx

This communication is confidential and is intended to be privileged. If
there is a problem with this transmission, please contact the sender. If
the reader of this message is not the intended recipient, or the employee
or agent responsible to deliver it to the intended recipient, you are
hereby notified that any dissemination, distribution or copying of this
communication is strictly prohibited.



Scott Klement
<rpg400-l@scottkl
ement.com> To
Sent by: RPG programming on the AS400 /
rpg400-l-bounces@ iSeries <rpg400-l@xxxxxxxxxxxx>
midrange.com cc

Subject
11/27/2007 01:28 Re: Wrap an RPG Procedure with an
PM SQL External Procedure


Please respond to
RPG programming
on the AS400 /
iSeries
<rpg400-l@midrang
e.com>






Hello Robert,

By the way... how did you guys know this? The documentation does not
mention anything about staying away from srvpgm's with procs that return
a
value. Was I missing it?

Heh... I don't think it's reasonable for a reference manual to include
everything that an SQL statement DOES NOT do. It can only list what it
does... listing everything it doesn't do would be kinda tedious. :)

Here's the SQL reference manual for the CREATE PROCEDURE statement:

http://tinyurl.com/2da5rc

In the CREATE PROCEDURE statement you posted in your original message,
you had 'parameter style SQL'. If you scroll down in the documentation
(i.e. the link, above) you'll see that it explains what 'parameter style
SQL' consists of. It's important to understand that which parameters
are/are not required in your program is entirely dependent on which
parameter style you're using.

The other parameter styles are explained as well -- and none of them
include a return value as one of the parameters detailed (which makes
sense, since the syntax of a procedure call (CALL XXXX()) does not
provide a place to return a value. So even if you could return it,
you'd have no way to use that return value in an SQL statement. (A UDF,
by contrast, can be used in situations where it's possible to set
something equal to it's return value.)

FWIW, when I write ILE RPG service programs and wrap them with a stored
procedure, I generally create the regular procedure with parameters and
return values that make it as easy and useful for ILE RPG programs as
possible.

Then, I create another procedure that acts as a "wrapper" or "interface"
for stored procedure usage. This wrapper generally changes the
parameters around a little bit to conform to the stored procedure
parameter style that I'm using. I also like to have any of the output
data from the procedure be returned as part of a result set (instead of
using parameters). Even if it's just a 1-row result set. I like that
method because a result set carries meta-data for the columns it
returns.... i.e. it has the column name, data type, length, etc, all
embedded in the result set itself. This makes it easier for callers
written in languages like C, Java, PHP, etc to be able to get
information about the columns returned without having to hard-code the
field definitions into their source.

When you want to have a return value to indicate success or failure, it
might make sense to use parameter style SQL, and have your wrapper
receive the return value and use it to set the SQLSTATE parameter that's
provided by parameter style SQL. That way, SQL itself will know when an
error has occurred, and the same error handling procedures used for any
other SQL statement can be used to handle errors returned by your stored
procedure.

However, if that seems to complicated, you can always just have an
output field in your result set for "error number" and "error message".
and the caller can check for those.

But.... because the parameter styles and error handling between stored
procedures and ILE procedures ARE so different, I always code a wrapper
around my stored procedures. That way, it's the best of both worlds
for both ILE callers and non-ILE callers (who are the ones using the
stored procedures.)
--
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.