Difference between revisions of "OptionalParameters"
(New page: ILE CL programs can accept optional parameters. One must use the CEETSTA procedure to know if the parameter has been passed. <nowiki> PGM PARM(&PARM1 &PARM2) ...) |
DaveLClarkI (talk | contribs) |
||
(7 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | ILE CL programs can accept optional parameters. | + | ILE CL programs can accept optional parameters. There are two methods for handling optional parameters in ILE CL programs — implicit and explicit. |
− | + | Implicit optional parameter handling employs the [[MONMSG]] command to trap the MCH3601 exception which results when missing parameters are referenced directly. In the following example note that the default value of the parameter variable is not lost during [[CHGVAR]] processing if the optional parameter was not supplied. | |
− | + | ||
− | + | PGM PARM(&OPTRUN) /* optional parameter */ | |
− | DCL VAR(&PARM1) TYPE(*CHAR) LEN(3) | + | |
− | DCL VAR(&PARM2) TYPE(*CHAR) LEN(3) | + | /* optional parameter definitions */ |
− | DCL VAR(&PARMRESULT) TYPE(*INT) LEN(4) | + | DCL VAR(&OPTRUN) TYPE(*CHAR) LEN(10) |
− | DCL VAR(&PARMNUMBER) TYPE(*INT) LEN(4) | + | |
− | + | /* parameter variable definitions */ | |
− | CHGVAR VAR(&PARMNUMBER) VALUE( | + | DCL VAR(&RUNOPT) TYPE(*CHAR) LEN(10) VALUE('*PRELIM') |
− | CALLPRC PRC(CEETSTA) PARM(&PARMRESULT &PARMNUMBER *OMIT) | + | |
− | IF COND(&PARMRESULT *EQ 1) THEN(DO) | + | /* receive optional parameters */ |
− | CALL PGM(PROGRAM2) PARM(&PARM1 &PARM2) | + | CHGVAR VAR(&RUNOPT) VALUE(&OPTRUN) /* optional run option */ |
− | ENDDO | + | MONMSG MSGID(MCH3601) EXEC(DO) /* parm not passed */ |
+ | RCVMSG MSGTYPE(*LAST) RMV(*YES) /* remove escape + | ||
+ | message from job log */ | ||
+ | ENDDO | ||
+ | |||
+ | On the other hand, explicit optional parameter handling requires a call to a CEE API to predetermine the presence or absence of an optional parameter. Use the [[CEETSTA]] procedure to determine if the parameter has been passed. Note that all CEE APIs are bound in by default and, thus, are always available. | ||
+ | |||
+ | PGM PARM(&PARM1 &PARM2) | ||
+ | |||
+ | DCL VAR(&PARM1) TYPE(*CHAR) LEN(3) | ||
+ | DCL VAR(&PARM2) TYPE(*CHAR) LEN(3) | ||
+ | DCL VAR(&PARMRESULT) TYPE(*INT) LEN(4) | ||
+ | DCL VAR(&PARMNUMBER) TYPE(*INT) LEN(4) | ||
+ | |||
+ | CHGVAR VAR(&PARMNUMBER) VALUE(2) | ||
+ | CALLPRC PRC(CEETSTA) PARM(&PARMRESULT &PARMNUMBER *OMIT) | ||
+ | IF COND(&PARMRESULT *EQ 1) THEN(DO) | ||
+ | CALL PGM(PROGRAM2) PARM(&PARM1 &PARM2) | ||
+ | ENDDO | ||
ELSE CMD(DO) | ELSE CMD(DO) | ||
− | CALL PGM(PROGRAM2) PARM(&PARM1) | + | CALL PGM(PROGRAM2) PARM(&PARM1) |
− | ENDDO | + | ENDDO |
− | + | ||
ENDPGM | ENDPGM | ||
− | + | ||
+ | ==Categories== | ||
+ | [[Category:Programming languages]] | ||
+ | [[Category:CLP]] |
Latest revision as of 18:52, 8 November 2016
ILE CL programs can accept optional parameters. There are two methods for handling optional parameters in ILE CL programs — implicit and explicit.
Implicit optional parameter handling employs the MONMSG command to trap the MCH3601 exception which results when missing parameters are referenced directly. In the following example note that the default value of the parameter variable is not lost during CHGVAR processing if the optional parameter was not supplied.
PGM PARM(&OPTRUN) /* optional parameter */ /* optional parameter definitions */ DCL VAR(&OPTRUN) TYPE(*CHAR) LEN(10) /* parameter variable definitions */ DCL VAR(&RUNOPT) TYPE(*CHAR) LEN(10) VALUE('*PRELIM') /* receive optional parameters */ CHGVAR VAR(&RUNOPT) VALUE(&OPTRUN) /* optional run option */ MONMSG MSGID(MCH3601) EXEC(DO) /* parm not passed */ RCVMSG MSGTYPE(*LAST) RMV(*YES) /* remove escape + message from job log */ ENDDO
On the other hand, explicit optional parameter handling requires a call to a CEE API to predetermine the presence or absence of an optional parameter. Use the CEETSTA procedure to determine if the parameter has been passed. Note that all CEE APIs are bound in by default and, thus, are always available.
PGM PARM(&PARM1 &PARM2) DCL VAR(&PARM1) TYPE(*CHAR) LEN(3) DCL VAR(&PARM2) TYPE(*CHAR) LEN(3) DCL VAR(&PARMRESULT) TYPE(*INT) LEN(4) DCL VAR(&PARMNUMBER) TYPE(*INT) LEN(4) CHGVAR VAR(&PARMNUMBER) VALUE(2) CALLPRC PRC(CEETSTA) PARM(&PARMRESULT &PARMNUMBER *OMIT) IF COND(&PARMRESULT *EQ 1) THEN(DO) CALL PGM(PROGRAM2) PARM(&PARM1 &PARM2) ENDDO ELSE CMD(DO) CALL PGM(PROGRAM2) PARM(&PARM1) ENDDO ENDPGM