Hi Scott,
Thanks for that. What exactly do you meand by a stateless procedure. Do you mean that with my suggestion, the new procedure is dependant upon the fact that the old one was called first?
With respect, nobody has really laid into my solution, so it can't be that bad, can it?
If I used the encapsulation method, I'd finish with something like this :
P GetProductName B
D PI
D ProductName
D PeckingOrder S
/free
GetProductNameAndPeckingOrder ( ProductName : PeckingOrder )
Etc.
Now, what would happen if I added a third parameter in the future? A second encapsulation procedure, I suppose.
In my example I'd simply add another GetNewParameter.
However, in the real example I have to modify, both the parameters are fields returned from a chain tothe same PF. I think maybe the PF record should be passed as a data structure to anticipate future modifications. Would that be reasonable?
Thanks again.
-----Message d'origine-----
De : rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] De la part de Scott Klement
Envoyé : lundi 16 mars 2009 18:16
À : RPG programming on the IBM i / System i
Objet : Re: New parameter needed for a subprocedure
Hi David,
It's my recommendation that you keep your procedures encapsulated and stateless -- that will lead to easier maintenance down the road. With that in mind, I suggest the following:
a) Add a new parameter with options(*nopass) as suggested by Michael Schutte.
- or, since you don't like that -
b) Rename the existing procedure to a different name. Let's say it's currently called GetWidget(). Rename it to getWidgetEx(), and add the new parameter to it.
c) Create a new procedure named GetWidget() -- the same name as the original procedure, and give it the same parameters as the original procedure.
d) Have GetWidget() call GetWidgetEx(). Have it add the extra parameter with a default value before calling.
Assuming that you're using binder source properly, GetWidget() (the new
one) will now be called by any existing callers. No need to change them. GetWidgetEx() will have the extra parameters, and can be called by new routines that need the extra parameters.
No need for global parameters, or separate routines to return them.
David FOXWELL wrote:
A new parameter is needed by one of the callers of an exported sub procedure.
Is there any harm in doing this :
Initialize the value of the new parameter in the exported sub procedure.
Add a new exported subprocedure GetNewParameter that returns NewParameter.
The caller that needs the parameter continues to call the original subprocedure as before and then calls GetNewParameter.
Other callers remain unchanged.
Does this make sense or is this just being lazy and are there any risks of it going wrong?
Thanks
--
This is the RPG programming on the IBM i / System i (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.