I'm backed up on the list, and don't have time to continue to catch-up
at the moment, so if this was already mentioned, then please ignore.
Trap:
Passing a file field into a procedure as a reference parameter then
reading/chaining to that file within the procedure which results in
changing the parameter that was passed into the procedure.
I've been bitten by this before and I recall seeing a thread about this
not that long ago as well.
Kurt Anderson
Application Developer
Highsmith Inc
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Barbara Morris
Sent: Monday, March 31, 2008 2:33 PM
To: rpg400-l@xxxxxxxxxxxx
Subject: Re: subroutines are bug factories was: Classic Traps -- I need
yourinput!
Murphy, Mark wrote:
No, local variables do not make the code more bug prone because they
are only applicable to the subprocedure, and since a subprocedure only
does a single thing, it isn't all that big. Therefore, a subprocedure
isn't terribly hard to read and understand. And since a subprocedure
only does a single thing, and has no side-effects, it is easy to reuse
wherever it is needed; just like a BIF.
One gotcha with local variables: If you have procedure in a module with
a global file, and the procedure does a READ or WRITE without a result
data structure, then the I/O operation will use the global fields on the
I or O specs. If you have defined local fields with the same names as
the global fields, your procedure won't be able to see the values of the
changed fields from the READ, or the unchanged global fields' values
will get written out to the file.
Moral: If you want to do I/O to a global file in a procedure, don't
define local variables with the same names as fields that appear on any
I or O specs (in the compile listing).
--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing
list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.