Are you going to need the element index from the original array in your result array? Just throwing that out as a possible consideration for whatever you implement.

Roger Harman
COMMON Certified Application Developer - ILE RPG on IBM i on Power



-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of David Gibbs via RPG400-L
Sent: Monday, November 10, 2025 1:48 PM
To: RPG programming on IBM i <rpg400-l@xxxxxxxxxxxxxxxxxx>
Cc: David Gibbs <david@xxxxxxxxxxxx>
Subject: Re: Idea submitted: Built in function to subset an array using a procedure to filter

On Mon, Nov 10, 2025 at 1:14 PM Mark Waterbury via RPG400-L <
rpg400-l@xxxxxxxxxxxxxxxxxx> wrote:

You might also consider creating a temporary table in Db2, and then load
the entire array into the temp table, and then you can use the full power
of SQL to query the temp table, and create a "results set" containing only
the subset that you are interested in. And, when done, you can just DROP
the temp table.

I think this should be much easier and more straight-forward than your
proposed "enhancement" to RPG IV.


DB2 adds a WHOLE lot of overhead for something that should be able to be
done in memory.

Alternatively, some kind of utility like qsort that takes two arrays and a
procptr to filter the entries

Hmmm ... I wonder how hard that kind of thing would be to write in RPG?

You've given me an idea.

david


All the best,

Mark S. Waterbury


On Tuesday, November 4, 2025 at 01:36:03 PM EST, David Gibbs via RPG400-L <
rpg400-l@xxxxxxxxxxxxxxxxxx> wrote:





So I submitted a enhancement request to the Ideas site to add a built in
function to subset an array using a procedure to determine if the array
element should be included.

https://ibm-power-systems.ideas.ibm.com/ideas/IBMI-I-4699

Create a new built in function to subset an array using a procedure to
filter.

Similar to the %SUBARR function, but allow a procedure to be specified to
determine if the array entry should be included in the result.

Something like ...

dcl-ds arraySpec_t qualified template;
subField1 char(10);
subField2 char(10);
end-ds;

dcl-ds newArray likeds(arraySpec_t);
dcl-ds oldArray likeds(arraySpec_t);
.
.
newArray = %FILTERARR(oldArray:1:%elem(oldArray):filterProc);
.
.
.
dcl-proc filterProc;
dcl-pi *n ind;
entry likeds(arraySpec_t) const;
end-pi;
return entry.subField1 = 'xyz';
end-proc;


Any comments on this?

david

--
IBM i on Power Systems: For when you can't afford to be out of business!

I'm riding in the American Diabetes Association's Tour de Cure to raise
money for diabetes research, education, advocacy, and awareness. You can
make a tax-deductible donation to my ride by visiting
https://mideml.diabetessucks.net/.

I may have diabetes, but diabetes doesn't have me!
--
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.

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



--
IBM i on Power Systems: For when you can't afford to be out of business!

I'm riding in the American Diabetes Association's Tour de Cure to raise
money for diabetes research, education, advocacy, and awareness. You can
make a tax-deductible donation to my ride by visiting
https://mideml.diabetessucks.net/.

I may have diabetes, but diabetes doesn't have me!
--
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 thread ...

Replies:

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

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