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



A few other things you end up having to think about when you start using
sub-procedures:

- You now want to return a value to be sensibly used in an expression -
but how do you tell the caller when something goes wrong?
- Generally I THROW an error in the sub-procedure and catch it in a
monitor block surrounding the sub procedure call (at some level) If you
haven't seen this technique before it's a nice one to know.
Basically, you
THROW an error by having a routine to send an ESCAPE message to the job.
The exception is CAUGHT by the calling routine using a MONITOR block. The
exception data is retrieved using a routine to do a RCVPGMMSG. I'm sure
several of us can point you at examples should you be interested and
require some links.
- Sometimes you just know you want to return more than one thing - so
you can return a data-structure. You might even do something
like implement
a next() function that reads the next record on a file, return the fields
and you need to be able to signify EOF, so you could return a DS
which had
a sub-datastructure with the record in and a boolean with EOF in.
- At some point you ask yourself - will I allow myself to access global
variables from the sub procedure. For example file fields. If you only need
2 or 3, you might pass them in. If you need 20 or more - what then? Allow
global access? Pass 20+ fields in? Have a local file definition (that's one
thing I haven't played with yet... ) I've seem some people take the stance
that they will NEVER access globals from inside a sub-procedure but that
approach, in my view at least, is not very pragmatic.
- On the subject of file fields and globals, there is a nice gotcha
where you call a sub procedure and pass some file fields to be
used as keys
to read a child table. You've defined the fields as CONST on the
prototype
definition, so you think the sub procedure can't change them - and it
can't, DIRECTLY. But remember those fields are still global so if the
subprocedure performs some FILE operation that causes the field values to
change - when you get back to the calling procedure the CONST values will
actually have changed!
- Another thing some people do once they start using sub procedures is
to declare they will never again use subroutines - why would they when they
have this great new subprocedure thing which can recurse and return a value
to be used in expressions! I personally don't hold with that theory.
Sometimes a simple subroutine is still all you need. Subroutines can also
be defined inside sub-procedures and obviously live in that namespace and
so can be useful for helping organise you code.

Just a few of my random thoughts on subprocedures..

On Sun, 17 Feb 2019 at 00:20, Stuart Rowe <rowestu@xxxxxxxxx> wrote:

And testability/reliability



On Sat, Feb 16, 2019 at 3:00 PM Jay Vaughn <jeffersonvaughn@xxxxxxxxx>
wrote:

And readability

Jay

On Feb 16, 2019, at 3:15 PM, Mihael Schmidt <mihael@xxxxxxxxxxxxxx>
wrote:


On 16.02.19 19:56, Buck Calabro wrote:
On Sat, 16 Feb 2019 at 01:35, Booth Martin <booth@xxxxxxxxxxxx>
wrote:

Ignore the idea that you are only looking for code that can
be reused: virtually every independent code block is better as a
function/sub-procedure than as mainline code. Find a bit of code that
seems like it returns one value from several inputs and make that into
a sub-procedure.

Exactly! Procedures are not solely about code reuse. They give your
program code a much better structure.

Best regards

Mihael

--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(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@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (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@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com

--
This is the RPG programming on the IBM i (AS/400 and iSeries) (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@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com


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