|
Am 22.03.2026 um 00:02 schrieb Buck Calabro <kc2hiz@xxxxxxxxx>:
Richard said:
Recordset processing with SQL. I can definitely see putting INSERT, UPDATE and DELETE logic in a sub procedure and a DB access service program perhaps, but what about queries that select resulting recordsets. Can I run an SQL from a sub procedure and return the resultset or cursor to the main program like I would in other languages ?
Yes! You can do it as a result set with ASSOCIATE RESULT SET LOCATORS
but it's sometimes convenient to use a callback; have the service
program do the actual access and have the caller 'do something' with
the records. Why a service program? Because you can do things like set
the authority on the table/view to public(*EXCLUDE) and then have the
service program apply whatever programmatic access, auditing,
notifications the business wants. For example, Accounting can get an
account balance but not the employee birth dates. What sort of 'do
something?' Imagine that you want to give an identical result set to a
DDS subfile, a JSON export for a web service, and an Excel file. With
a callback, the three different UIs each present the data as needed,
and none of them need to know anything about the actual structure of
the database - the service program uses SQL, F-specs, or a combination
to aggregate and return the data...
Also does a named cursor open survive across calls ?
It can, depending on activation group and cursor scope, but the caller
needs to track state and signal when it's done with the I/O. That's
kind of close coupling, but they pay us to make these decisions :-)
--buck
--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.
As an Amazon Associate we earn from qualifying purchases.
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.