|
You're right, it is ugly.
By the way, does this work?
If parm <> *OMIT
I thought it was:
If %addr(parm) <> *NULL
I ran into this while righting RPG xTools a few years ago and solved it by
including the following in the start of my subprocedures:
D bP1 S 10I 0
D bP2 S 10I 0
D bP3 S 10I 0
D bP4 S 10I 0
D bP5 S 10I 0
C if %Parms >= 1
C CallP IsParmOmit(bP1 : 1 : *OMIT)
C if %Parms >= 2
C CallP IsParmOmit(bP2 : 2 : *OMIT)
C if %Parms >= 3
C CallP IsParmOmit(bP3 : 3 : *OMIT)
C if %Parms >= 4
C CallP IsParmOmit(bP4 : 4 : *OMIT)
C if %Parms >= 5
C CallP IsParmOmit(bP5 : 5 : *OMIT)
C endif
C endif
C endif
C endif
C endif
This at least isolates the crappy looking stuff to the top of the subproc.
Then in my code, if I need to know if parm 3 was passed in, I check for bP3=1
Whether it is *NOPASS'd or *OMIT'd test above provides for that.
By the way, the "IsParmOmit() proc is the CEETSTA API, as follows;
D IsParmOmit PR ExtProc('CEETSTA')
D nParmPassed 10I 0
D nParmNum 10I 0 Const
D szParmError 12A OPTIONS(*OMIT)
Been working consistently great since V4R4 for me.
-Bob Cozzi
www.RPGxTools.com
RPG xTools - Enjoy programming again.
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On
Behalf Of Wilt, Charles
Sent: Friday, April 21, 2006 3:32 PM
To: RPG programming on the AS400 / iSeries
Subject: *NOPASS and *OMIT make calling easier but boy are the procedures
ugly,any tips/tricks?
All,
I really like the idea coding optional parameters as (*NOPASS : *OMIT).
Particularly when the parameter is question ends up in a null capable
file field.
However, as far as I can tell actual implementation is ugly beyond
belief.
/free
if bin_Required();
wToBin = AskUserForBin();
Inventory_MoveSerialized(wPlant:wSerial:wToStkRm:wToBin);
else;
Inventory_MoveSerialized(wPlant:wSerial:wToStkRm);
endif;
*INLR = *ON;
return;
/end-free
p Inventory_MoveSerialized...
p b export
d Inventory_MoveSerialized...
d pi n
d plant like(t_PlantID) const
d serial like(t_SerialNumber) const
d toStkRm like(t_StockRoom) const
d toBin like(t_BinLocation) const
d options(*NOPASS:*OMIT)
d parm5 10a const options(*NOPASS:*OMIT)
/free
if %parms >= 5;
if parm5 <> *OMIT;
SomeOtherProc1(plant:parm5);
else;
SomeOtherProc1(plant:*OMIT);
endif;
else
SomeOtherProc1(plant);
endif;
if %parms >= 4;
if parm4 <> *OMIT;
SomeOtherProc2(plant:serial:toStkRm:toBin);
else
SomeOtherProc2(plant:serial:toStkRm:*OMIT);
endif;
else
SomeOtherProc2(plant:serial:toStkRm);
endif;
if %parms >= 5;
if parm5 <> *OMIT;
if toBin <> *OMIT;
SomeOtherProc3(plant:toBin:parm5);
else;
SomeOtherProc3(plant:*OMIT:parm5);
endif;
elseif toBin <> *OMIT;
SomeOtherProc3(plant:toBin:*OMIT);
else
SomeOtherProc3(plant:*OMIT:*OMIT);
endif;
elseif %parms >= 4;
if toBin <> *OMIT;
SomeOtherProc3(plant:toBin);
else;
SomeOtherProc3(plant:*OMIT);
endif;
else
SomeOtherProc3(plant);
endif;
return;
/end-free
Calling SomeOtherProc1 & SomeOtherProc2 is ugly enough, but calling
SomeOtherProc3 which uses two *NOPASS:OMIT parms is horrible. I'd hate
to imagine what it would look like if there were more *NOPASS:*OMIT
parameters being passed to it.
So how are you all dealing with this wreak?
Somebody correct me if I'm wrong, but I'm thinking that it might be best
to drop the *NOPASS, since I believe that I can pass along (by const
reference) an *OMITted parameter to another procedure with no problems.
So for instance this would work with parm5 *OMITted or not:
/free
if parm5 <> *OMIT;
dsply parm5;
endif;
SomeOtherProc1(plant:parm5);
/end-free
It would really be nice if RPG allowed you to make a varible NULL
(*OMITted)
So for instance you could have:
d wToBin s like(t_BinLocation) inz(*OMIT)
/free
if bin_Required();
wToBin = AskUserForBin();
endif;
Inventory_MoveSerialized(wPlant:wSerial:wToStkRm:wToBin);
*INLR = *ON;
return;
/end-free
Then in the Inventory_MoveSerialized even with *NOPASS I could have
/free
if %parms >= 5;
wParm5 = parm5;
else
wParm5 = *OMIT;
endif;
if %parms >= 4;
wToBin = toBin;
else
wToBin = *OMIT;
endif;
SomeOtherProc1(plant:parm5);
SomeOtherProc2(plant:serial:toStkRm:toBin);
SomeOtherProc3(plant:toBin:parm5);
return;
/end-free
Thoughts?????
Thanks in advance,
Charles Wilt
--
iSeries Systems Administrator / Developer
Mitsubishi Electric Automotive America
ph: 513-573-4343
fax: 513-398-1121
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.