You need two SQL modules ( if you will make it the clean way) :

1) Create a stored procedure that wraps the RPG *PGM - your can use the
basic parameter style. That is basically just a parameter template for SQL
to know how it calls your program - no real object is created here.

2) Create a scalar function that calls the procedure and and returns the
output parameter from the stored procedure.

We do it all the time, so we can "call an RPG program" within a select from
statement.



On Thu, Jan 22, 2026 at 5:46 PM Daniel Gross <daniel@xxxxxxxx> wrote:

Yes - I looked it up again in the SQL reference.


https://www.ibm.com/docs/en/i/7.5.0?topic=statements-create-function-external-scalar

For PARAMETER STYLE SQL to work, your program needs the following
parameters - quote from the SQL reference:

The parameters are defined to be in the following order:
- n parameters for the input parameters that are specified for the
function.
- A parameter for the result of the function.
- n parameters for indicator variables for the input parameters.
- A parameter for the indicator variable for the result.
- A CHAR(5) output parameter for SQLSTATE. ...
- A VARCHAR(517) input parameter for the fully qualified function name.
- A VARCHAR(128) input parameter for the specific name.
- A VARCHAR(1000) output parameter for the message text.

And that works quite good. But you will need a "wrapper" program or
procedure if you don't want to modify the original program.

If you have specific entry parameters, please show them, so we can try to
help you.

HTH
Daniel


Am 22.01.2026 um 17:23 schrieb Daniel Gross <daniel@xxxxxxxx>:

Yes - that shouldn't be a big problem.

You have to use

PARAMETER STYLE DB2SQL

in the function definition. AFAIK "SQL" does also work, but I always use
"DB2SQL".

With this you will have a parameter the contains the return value for
the function.

Still one of the best resources for UDFs and UDTFs is Scott's
presentation:

https://www.scottklement.com/presentations/RPG%20User%20Defined%20Functions%20&%20Table%20Functions.pdf

Scott's example is with a *SRVPGM procedure, but it works the same with
a *PGM - it differs only in the EXTERNAL NAME clause.

HTH
Daniel


Am 22.01.2026 um 17:09 schrieb Justin Taylor <jtaylor.0ab@xxxxxxxxx>:

I'd wager this is a long shot, but it can't hurt to ask.

I have an RPGLE *PGM that has a parameter that's basically an output
parameter. Is there a way to create an SQL UDF that can use that *PGM
object and make that output parameter an actual return value?

*SRVPGM is off the table. Don't ask... :(


Thanks
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription
related questions.

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription
related questions.

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related
questions.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

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

This mailing list archive is Copyright 1997-2026 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.