Command reference / CL

CALLSUBR

Call Subroutine

Passes control to a subroutine within a CL program or ILE CL procedure. The name must match a SUBR command in that procedure. CALLSUBR can appear anywhere except as a program-level MONMSG. A return value can be stored in a 4-byte integer CL variable. Each call pushes a return address onto a subroutine stack, with a default depth of 99 that DCLPRCOPT's SUBRSTACK parameter can change. Exceeding the depth issues CPF0822 and leaves the stack unchanged.

Allowed environments: *BPGM, *IPGM. Use within a CL program. Positional parameters: 1.

Restrictions

Parameters

SUBR Subroutine

Names the subroutine that control is transferred to. It must be defined within the same procedure. Required. A CL variable cannot be used.

Type
*SNAME
Required
Yes
Length
10
Case
Uppercase

RTNVAL CL variable for returned value

Names a 4-byte signed integer CL variable that receives the subroutine's return value. The value is zero unless set by RTNSUBR or ENDSUBR.

Type
*VARNAME
Required
No
Default
*NONE
Length
10
Case
Uppercase

Suggested / special values: *NONE

*NONE
The value returned by the subroutine is ignored.

Examples

CALLSUBR SUBR(SUBR1) RTNVAL(&INT4VAR)

Calls subroutine SUBR1 and stores its return value in &INT4VAR, which is declared as a 4-byte integer.

IF (&A *LT 30) THEN(CALLSUBR LT30)

Calls subroutine LT30 only if &A is less than 30.

IBM command documentation

Generated from os/cl/catalog/CALLSUBR.json and os/cl/help/CALLSUBR.json.