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



I often write programs with both sub-procedures and sub-routines. They
are not the same and should not be thought of as if they were the same.
I don't use sub-routines as much as I did before procedures where
available, but there are cases where they are the correct tool for the
job. I even use them within large sub-procedures on occasion. I love
sub-procedures, but there are any number of instances where a procedure
is completely inappropriate. 

Sub-routines are useful if you want to reuse some code that needs to
have access to a large number of global variables and does not need to
have separate local variables, for instance if you want to clear a set
of variables. While you could do this with a sub-procedure you would
either have to pass all of the variables to the procedure, which would
be ugly, call the procedure for each variable you wanted to clear, at
which point why not just clear the variable instead of passing it to a
procedure, or you would need to access the global variables from within
the procedure, which is a very "bad thing".  Sub-routines are also
useful if you just want to break up your code into smaller chunks.
Especially if you aren't using /free this can make large nested selects
and ifs more readable. 

Sub-procedures are great for many things, such as when you have a
function that you want to be able to apply to multiple different input
values. You could of course do this with a sub-routine by moving the
value into a temporary variable, executing the routine, and then moving
the value back, but this is ugly. However they should be limited to
situations where they don't need access to global variables, if you need
the data you must pass it in. Unfortunately you currently must access
global variables if you are accessing a file from within the procedure.
Sub-procedures are of course most famously useful when you have them in
a service program available to multiple programs. But I rarely write a
program any more that doesn't contain at least one internal
sub-procedure. 

Joe Lee

>>> Lim.Hock-Chai@xxxxxxxx 08/19/2004 12:22:21 >>>
I don't see a reason to use sub-routine at all.  Sub-procedure can not
exsr to main procecdure's sub-routine.  If you mix them, you might endup
have to change sub-routine to sub-procedure because of that.


-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx 
[mailto:rpg400-l-bounces@xxxxxxxxxxxx]On Behalf Of
michaelr_41@xxxxxxxxxxxxxx 
Sent: Thursday, August 19, 2004 2:10 PM
To: RPG programming on the AS400 / iSeries
Subject: Re: Subroutines vs Subprocedures was RE: Indicators


It's all a matter of where you want to break the code. I tend to make
subprocedures more generic and subroutines more specific.

--


As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.