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



Elbert,

No, but as I said in my original post, if proc2 has CONST character
parameters, you can simply have a second prototype for it where each
parameter is a pointer passed by VALUE - in that case, passing a null
pointer will be treated by proc2 as if *OMIT had been passed in that
parameter.

In other words, if proc1 is defined like this:

P proc1 B
D PI
D parm1 10a const options(*nopass:*omit)
D parm2 10a const options(*nopass:*omit)
D parm3 10a const options(*nopass:*omit)
D parm4 10a const options(*nopass:*omit)
D parm5 10a const options(*nopass:*omit)

and proc2 is defined the same

P proc2 B
D PI
D parm1 10a const options(*nopass:*omit)
D parm2 10a const options(*nopass:*omit)
D parm3 10a const options(*nopass:*omit)
D parm4 10a const options(*nopass:*omit)
D parm5 10a const options(*nopass:*omit)

then change proc1 to use a second 'dummy' prototype for proc2 as e.g.:

P proc2_val B
D PI
D parm1 * const options(*nopass:*omit)
D parm2 * const options(*nopass:*omit)
D parm3 * const options(*nopass:*omit)
D parm4 * const options(*nopass:*omit)
D parm5 * const options(*nopass:*omit)

and have code like this in proc1 to call proc2:

D parms * dim(5) inz
...
if %parms >= 1;
parms(1) = %addr( parm1 );
if %parms >= 2;
parms(2) = %addr( parm2 );
if %parms >= 3;
parms(3) = %addr( parm3 );
if %parms >= 4;
parms(4) = %addr( parm4 );
if %parms >= 5;
parms(5) = %addr( parm5 );
endif;
endif;
endif;
endif;
endif;

callp proc2_val( parms(1) : parms(2) : parms(3) : parms(4) : parms(5) );

What this means is that if proc1 is called as

callp proc1( 'ABC' : *omit : MyName );

(with only 3 parameters of a possible 5, one of which is omitted), then
proc2 will be called by proc1 as if proc1 had specified this:

callp proc1( 'ABC' : *omit : MyName : *omit : *omit );

with all 5 parameters.

Works fine and makes code in proc1 very simple. There are a few caveats -
see my original post for those.

Rory

On Thu, Mar 10, 2011 at 3:41 PM, Elbert Cook <elbert@xxxxxxxxxxxxxxx> wrote:

Can you use a literal for *OMIT?
Would it make sense to have a literal value for *OMIT

If %parms > 0;
New1 = parm1;
Endif;

If %parms > 1;
New2 = parm2;
Else;
New2 = *OMIT;
Endif;

If %parms > 2;
New3 = parm3;
Else;
New3 = *OMIT;
Endif;

If %parms > 3;
New4 = parm4;
Else;
New4 = *OMIT;
Endif;

If %parms > 4;
New5 = parm5;
Else;
New5 = *OMIT;
Endif;

Callp proc2(new1: new2: new3: new3: new5);

-----Original Message-----
From: Rory Hewitt [mailto:rory.hewitt@xxxxxxxxx]
Sent: Thursday, March 10, 2011 5:51 PM
To: RPG programming on the IBM i / System i
Cc: Larry Ducie
Subject: Re: Calling similiar (overloaded) procedure that has *nopass *omit
in the parameter

Larry,

This thread has moved on somewhat from the OP's original question.

In his original question (someone tell me if I'm wrong) he was calling one
procedure (proc2) from another 'middleman' procedure (proc1), where the
middleman procedure accepted a long list of parameters, all of which had
*OMIT and *NOPASS defined. Therefore he was forced to use a long SELECT
statement to cater for all possible scenarios.

For instance, the below example simply checks for 5 parameters with *NOPASS
specified, and doesn't even get into the *OMIT problem:

if %parms = 1;
callp proc2( parm1 );
endif;
if %parms = 2;
callp proc2( parm1 : parm2 );
endif;
if %parms = 3;
callp proc2( parm1 : parm2 : parm3 );
endif;
if %parms = 4;
callp proc2( parm1 : parm2 : parm3 : parm4 );
endif;

and so on.

Sure, it works, but if the parameter names being passed into this procedure
are longer than the 5-character examples I give above (which of course they
are), then the code just gets very long and unwieldy, since each CALLP
statement would span many lines.

If you also have to check for parameters being omitted, then you
potentially
have to check for every possibility, e.g.:

if %parms = 3;
select;
when %addr( parm1 ) = *null and %addr( parm2 ) = *null and %addr( parm3
) = *null;
callp proc2 (*omit : *omit : *omit );
when %addr( parm1 ) = *null and %addr( parm2 ) = *null;
callp proc2 (*omit : *omit : parm3 );
when %addr( parm1 ) = *null and %addr( parm3 ) = *null;
callp proc2 (*omit : parm2 : *omit );
when %addr( parm1 ) = *null;
callp proc2 (*omit : parm2 : parm3 );
when %addr( parm2 ) = *null and %addr( parm3 ) = *null;
callp proc2 (parm1 : *omit : *omit );
when %addr( parm2 ) = *null;
callp proc2 (parm1 : *omit : parm3 );
when %addr( parm3 ) = *null;
callp proc2 (parm1 : parm2 : *omit );
other;
callp proc2 (parm1 : parm2 : parm3 );
endsl;
endif;

and that's only with 3 parms being passed in...

Various posters then started discussing about why the middleman couldn't
simply call proc2 as:

callp proc2 (parm1 : parm2 : parm3 );

even when some of the parms might have been omitted in the call to the
middleman.

At least, that's how I understand the conversation...

Rory

p.s. I actually posted a solution for the OP's problem which is only about
15 lines total, but no-one had anything to say about it, which may be just
as well :)


On Thu, Mar 10, 2011 at 1:47 PM, Larry Ducie <larry_ducie@xxxxxxxxxxx
wrote:


Hi All,

OK, admittedly I am coming into this thread very late and probably
ill-informed about the ongoing debate but...

I fail to see the problem with the way in which we check for valid
parameter access in RPG.

What is difficult about:


parm3 in proto with *OMIT : *NOPASS
local3 like parm3 in local D-specs (optionally initialised to a
non-default
value)

if %parms() >= 3 and %addr(parm3) <> *null;
local3 = parm3;
endif;

work with local3...


This logic is obvious and clean. the procedure ONLY accesses local3, with
the exception of populating it from parm3, if passed.
It ensures you ALWAYS check %parms() BEFORE %addr() if *OMIT and *NOPASS
is
specified for a parameter:
1) *NOPASS: Is a parameter passed?
2) *OMIT: Is the address of the passed parameter a null?

As *OMIT passes an address (albeit a null address) it will count as a
parameter when checking %parms(). Calling myProc(*OMIT : parm2 : *OMIT :
parm4) will set %parms() to 4 inside myProc. So check it is passed before
checking its address is null.

This code also gives you the ability to initialise local3 with a
non-default value to be used if parm3 is not passed. Parm3 is simply an
override value.

When using this in a procedure overloading scenario - you simply call the
other procedure passing the additional data using the local variables.

This is a similar mechanism to overloading constructors. The constructor
that takes the most parms usually performs the work. The other variants
simply supplement the missing parms with locals (derived or otherwise)
and
call the full constructor.

Cheers

Larry Ducie

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



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

This thread ...

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.