We use a loop to check if each parm is passed in order.
Doesn't work for *OMIT parms.
But it works well with OPTIONS(*NOPASS) parms.
DCL VAR(&PARMIDX) TYPE(*INT)
DCL VAR(&PARMNUMBER) TYPE(*INT)
DCL VAR(&PARMRESULT) TYPE(*INT)
DCL VAR(&PARMCOUNT) TYPE(*INT)
/*----------------------------------------------------------------------------*/
/* Set the To Value of the DOFOR to the Exact number of parms Allowed. */
/* CEETSTA will Halt if the TO value exceeds the actual number of parms. */
/*----------------------------------------------------------------------------*/
/* GET PARM COUNT - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
CHGVAR VAR(&PARMCOUNT) VALUE(0)
PARMCHECK: DOFOR VAR(&PARMIDX) FROM(1) TO(5)
CHGVAR VAR(&PARMNUMBER) VALUE(&PARMIDX)
CALLPRC PRC(CEETSTA) PARM(&PARMRESULT &PARMNUMBER *OMIT)
IF COND(&PARMRESULT *NE 1) THEN(DO)
LEAVE CMDLBL(PARMCHECK)
ENDDO
CHGVAR VAR(&PARMCOUNT) VALUE(&PARMCOUNT + 1)
ENDDO
After the check we can then load a local variable if we need to do something with the parameter:
CHGVAR VAR(&P_PARM3) VALUE(' ') /* set parm default value */
IF COND(&PARMCOUNT *GE 3) THEN(DO)
CHGVAR VAR(&P_PARM3) VALUE(&P#PARM3)
ENDDO
Chris Hiebert
Senior Programmer/Analyst
Disclaimer: Any views or opinions presented are solely those of the author and do not necessarily represent those of the company.
-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Helge Bichel
Sent: Thursday, March 16, 2017 4:12 AM
To: 'Midrange Systems Technical Discussion' <midrange-l@xxxxxxxxxxxx>
Subject: SV: Optional parameters in CLLE
Dear Roger.
Example on optional parms:
PGM PARM(&OPTION &REPORT &ORORID &pPMVM &pACB &pDIPD) /* last 3
parms are optional */
DCL VAR(&option) TYPE(*CHAR) LEN(02)
DCL VAR(&report) TYPE(*CHAR) LEN(35)
DCL VAR(&ORORID) TYPE(*DEC) LEN(9 0)
DCL VAR(&pPMVM) TYPE(*CHAR) LEN(1)
DCL VAR(&pACB) TYPE(*CHAR) LEN(1)
DCL VAR(&pDIPD) TYPE(*CHAR) LEN(1)
DCL VAR(&PMVM) TYPE(*CHAR) LEN(1)
DCL VAR(&ACB) TYPE(*CHAR) LEN(1)
DCL VAR(&DIPD) TYPE(*CHAR) LEN(1)
/* vars for processing optional parms */
DCL &p4 *CHAR 4
DCL &p5 *CHAR 4
DCL &p6 *CHAR 4
DCL &PARMNO *CHAR 4
/* init optional parms */
CHGVAR VAR(&PMVM) VALUE(' ')
CHGVAR VAR(&ACB) VALUE(' ')
CHGVAR VAR(&DIPD) VALUE(' ')
/* are optional parms passed ? */
CHGVAR VAR(%BIN(&PARMNO)) VALUE(4)
CALLPRC PRC(CEETSTA) PARM(&p4 &PARMNO *OMIT)
CHGVAR VAR(%BIN(&PARMNO)) VALUE(5)
CALLPRC PRC(CEETSTA) PARM(&p5 &PARMNO *OMIT)
CHGVAR VAR(%BIN(&PARMNO)) VALUE(6)
CALLPRC PRC(CEETSTA) PARM(&p6 &PARMNO *OMIT)
/* set value from optional passed parms */
IF COND(%BIN(&P4) *EQ 1) THEN(DO)
CHGVAR VAR(&PMVM) VALUE(&pPMVM)
ENDDO
IF COND(%BIN(&P5) *EQ 1) THEN(DO)
CHGVAR VAR(&ACB ) VALUE(&pACB )
ENDDO
IF COND(%BIN(&P6) *EQ 1) THEN(DO)
CHGVAR VAR(&DIPD) VALUE(&pDIPD)
ENDDO
-----Oprindelig meddelelse-----
Fra: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] På vegne af Roger Harman
Sendt: 16. marts 2017 00:34
Til: Midrange Systems Technical Discussion
Emne: Optional parameters in CLLE
I have a couple of processes where I'd like to have one or two optional parms.
In the past, I've just tried using them in a CHGVAR and monitor for MCH3601.
But... I'm wondering if %address() can be used instead. I think it would be cleaner. In my testing, I've seen hex zeros for the %address of a non-passed parm. That seems to indicate a *NULL will be returned. Since it's consistent and not a garbage address, I would think I could count on that logoc.
Does anyone know if this is a documented behavior? I haven't found a definitive answer.
Thanks.
Roger Harman
COMMON Certified Application Developer - ILE RPG on IBM i on Power
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at
http://archive.midrange.com/midrange-l.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link:
http://amzn.to/2dEadiD
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at
http://archive.midrange.com/midrange-l.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link:
http://amzn.to/2dEadiD
As an Amazon Associate we earn from qualifying purchases.