|
Yeah, that's really the best way to handle the variability of my
parameters, Brad, but the issue is that I'm trying to make this is
unobtrusive as possible for the programmers. I want them to just be
able to add a single line of code in the midst of the program without
really breaking up the program flow. Eventually some of this logging
will be permanently in the program and then just turned on and off
externally.
On 4/2/2019 3:32 PM, B Stone wrote:
Here's how I did it with things like that so that I didn't need to worrytoo
about every having to change the interface.. I used "setters".
logCommon_setValue('name':value);
then actually running the log:
logCommon_exec();
So it may look like this:
logCommon_init();
logCommon_setValue('type':type_value);
logCommon_setValue('code':code_value);
logCommon_setValue('parm':parm_value);
...
...
logCommon_exec();
Inside the function you have a big select that sets values:
select;
when (parm = 'code');
code = inputValue;
when (parm = 'type');
type = inputValue;
....
endsl;
Just a different way of thinking of it. I ran into too many cases where
the interface could change and the mix of omitting parms, etc just got
complicated. This way you can add anything at any time and just add itto
the select.function,
Using constants (from a /copy member) for the names of the values is
probably your best bet as well.
Yes, it does require the use of Global variables internal to the
but I haven't run into an issue yet.. even using them recursively. Aslong
as the init() functions as it should and is called, things should befine.
wrote:
Bradley V. Stone
www.bvstools.com
Need to interface with Braintree with your IBM i? Contact me
<https://www.bvstools.com/contact.html> for more information!
On Tue, Apr 2, 2019 at 3:13 PM Joe Pluta <joepluta@xxxxxxxxxxxxxxxxx>
Every time I get close to a solution, I get whacked.
Here's my simple case. I want to write this procedure:
dcl-proc LogData;
dcl-pi *n;
iTYPE like(dsLOGDTA.L0TYPE) const;
iCODE like(dsLOGDTA.L0CODE) const;
iPARM1 like(dsLOGDTA.L0PARM1) const options(*nopass);
iPARM2 like(dsLOGDTA.L0PARM2) const options(*nopass);
iPARM3 like(dsLOGDTA.L0PARM3) const options(*nopass);
end-pi;
It's really pretty simple. A type, a code, and up to 3 optional
parameters, all of which can be literals or expressions. The above
works. However, I'd like to encapsulate those further so users can call
them without the type and code, like so:
dcl-proc LogCode;
dcl-pi *n;
iCODE like(dsLOGDTA.L0CODE) const;
iPARM1 like(dsLOGDTA.L0PARM1) const options(*nopass);
iPARM2 like(dsLOGDTA.L0PARM2) const options(*nopass);
iPARM3 like(dsLOGDTA.L0PARM3) const options(*nopass);
end-pi;
dcl-proc LogType;
dcl-pi *n;
iTYPE like(dsLOGDTA.L0TYPE) const;
iPARM1 like(dsLOGDTA.L0PARM1) const options(*nopass);
iPARM2 like(dsLOGDTA.L0PARM2) const options(*nopass);
iPARM3 like(dsLOGDTA.L0PARM3) const options(*nopass);
end-pi;
dcl-proc LogOnlyParms;
dcl-pi *n;
iPARM1 like(dsLOGDTA.L0PARM1) const options(*nopass);
iPARM2 like(dsLOGDTA.L0PARM2) const options(*nopass);
iPARM3 like(dsLOGDTA.L0PARM3) const options(*nopass);
end-pi;
I'd like these three functions all to call LogData. Each of them
defaults the values that are not passed in. I know I can pass "special
values" for type and code, but for various reasons I'd really like to be
able to call without those parameters. This seemed like an easy thing
to do, but I ran into difficulties. Clearly I can't just call this way
from LogCode:
LogData( C_DEFAULT_TYPE: iCODE: iPARM1: iPARM2: iPARM3);
I'll get an MCH pointer exception if I don't pass all three variables.
I tried being a little sneakier and did this:
LogCommon( C_DEFAULT_TYPE: iCODE: %parms:
%addr(iPARM1): %addr(iPARM2): %addr(iPARM3));
I wrote a new routine LogCommon that instead of the parameters accepts
pointers to the parameters along with (for belt and suspenders security)
passing the number of parameters. I only then used the actual number of
parameters that were passed, and ignore the others. Initial testing
looked good with the address of unpassed parameters being sent as *NULL.
Unfortunately, it turns out you can't get the address of a parameter
defined this way:
iPARM1 like(dsLOGDTA.L0PARM1) const options(*nopass);
You can only get the address of this:
iPARM1 like(dsLOGDTA.L0PARM1) options(*nopass);
Specifying /const/ angers the compiler and it won't let you take the
address of the parameter.
So now I'm stuck. My guess is I'll end up with a common routine with no
optional parameters and code like this in every front end:
if %parms = 0;
LogCommon( C_DEFAULT_TYPE: C_DEFAULT_CODE: ' ': ' ': ' ');
elseif %parms = 1;
LogCommon( C_DEFAULT_TYPE: C_DEFAULT_CODE: iParm1: ' ': ' ');
elseif %parms = 20;
LogCommon( C_DEFAULT_TYPE: C_DEFAULT_CODE: iParm1: iParm2: ' ');
else;
LogCommon( C_DEFAULT_TYPE: C_DEFAULT_CODE: iParm1: iParm2: iParm3);
endif;
Has anybody else dealt with this? It's a common pattern in Java, and
I'd like to be as clean about it as possible as I start to build some
library functions.
--
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@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 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@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 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.