|
CALL and CALLPRC command in CL |
CALL and CALLPRC Introduction
CALL Command is used to call another program whereas CALLPRC command calls a bound procedure named on the command.
CALLPRC command is not valid in OPM programs
If a CL source member is clp then we cannot use the CALLPRC program there.
If we are using the CALLPRC program then we can use only those procedures or modules which are created by using ILE way (module/srvpgm).
If a program is created using the CRTBNDRPG or CRTBNDCL commands we cannot call these programs using CALLPRC.
CALL has 2 parameters and CALLPRC has 3 parameters
2 parameters of CALL are program names and parameters list.
3 parameters of CALLPRC are procedures name, parameters(By value, By reference) and return value (*NONE if no return value).
CL program for CALL and CALLPRC command
PGM
DCL VAR(&NUM1) TYPE(*DEC) LEN(4 0) VALUE(52)
DCL VAR(&NUM2) TYPE(*DEC) LEN(4 0) VALUE(22)
DCL VAR(&res) TYPE(*DEC) LEN(4 0)
DCL VAR(&RESC) TYPE(*CHAR) LEN(4)
CALL PGM(OCT1A)
CALL PGM(OCT1D)
CALLPRC PRC(OCT1B)
CALLPRC PRC(OCT1E)
CALLPRC PRC(OCT1C)
CALLPRC PRC(OCT1F)
CALLPRC PRC(SUBTRACT) PARM((&NUM1 *BYVAL) (&NUM2 +
*BYVAL)) RTNVAL(&RES)
CHGVAR VAR(&RESC) VALUE(&RES)
SNDPGMMSG MSG(&RESC) MSGTYPE(*COMP)
CALLPRC PRC(SUBTRACTED) PARM((&NUM1 *BYREF) (&NUM2 +
*BYREF)) RTNVAL(&RES)
CHGVAR VAR(&RESC) VALUE(&RES)
SNDPGMMSG MSG(&RESC) MSGTYPE(*COMP)
ENDPGM
Explanation of the above code
DCL VAR(&NUM1) TYPE(*DEC) LEN(4 0) VALUE(52)
DCL VAR(&NUM2) TYPE(*DEC) LEN(4 0) VALUE(22)
DCL VAR(&res) TYPE(*DEC) LEN(4 0)
DCL VAR(&RESC) TYPE(*CHAR) LEN(4)
Here, we have taken 4 variables &NO and &NM also remember these variables’ names must start with the ‘&’ symbol and here the variables are of two types one is decimal and the other is character
CALL PGM(OCT1A)
CALL PGM(OCT1D)
Here, we call two programs named PGM(OCT1A) and PGM(OCT1D) which is called with no parameters being passed to it. The library list is used to locate the called program.
CALLPRC PRC(OCT1B)
CALLPRC PRC(OCT1E)
The Call Bound Procedure (CALLPRC) command calls a procedures named PRC(OCT1B) and PRC(OCT1E). When the called procedure completes running, control returns to the next command in the calling procedure.
CALLPRC PRC(OCT1C)
CALLPRC PRC(OCT1F)
CALLPRC PRC(SUBTRACT) PARM((&NUM1 *BYVAL) (&NUM2 +
*BYVAL)) RTNVAL(&RES)
CALLPRC command calls OCT1C and OCR1F procedure with no parameter and no return value. However, procedure SUBTRACT called using CALLPRC command and passed 2 parameters NUM1 and NUM2 (by value) and a return value would be placed in RES variable specified in RTNVAL parameter of the CALLPRC command.
CHGVAR VAR(&RESC) VALUE(&RES)
SNDPGMMSG MSG(&RESC) MSGTYPE(*COMP)
CALLPRC PRC(SUBTRACTED) PARM((&NUM1 *BYREF) (&NUM2 +
*BYREF)) RTNVAL(&RES)
Assign RES value to RESC variable using CHGVAR command and then the message being sent to program with MSG as RESC value and message type is Completion.Procedure SUBTRACTED called using CALLPRC command and passed 2 parameters NUM1 and NUM2 (by reference) and a return value would be placed in RES variable specified in RTNVAL parameter of the CALLPRC command.
CHGVAR VAR(&RESC) VALUE(&RES)
SNDPGMMSG MSG(&RESC) MSGTYPE(*COMP)
ENDPGM
Assign RES value to RESC variable using CHGVAR command and then the message being sent to program with MSG as RESC value and message type is Completion.