End Subroutine (ENDSUBR)

The End Subroutine (ENDSUBR) command specifies the end of a subroutine, and must be paired with a previous Subroutine (SUBR) command. When the ENDSUBR command is processed, control is returned to the command immediately following the Call Subroutine (CALLSUBR) command that called the subroutine. If a value is to be returned, such as an error code, the returned value must be able to be stored into a 4-byte signed integer CL variable. The Return value (RTNVAL) parameter can be a variable or constant. If no RTNVAL parameter is defined, the value will default to zero.

Restrictions:

Parameters

Keyword Description Choices Notes
RTNVAL Return value Integer, 0 Optional

Return value (RTNVAL)

Specifies the value to be returned from the subroutine. This can be a variable or constant that can be stored in a 4-byte signed integer CL variable. If the Call Subroutine (CALLSUBR) command that called the subroutine specified a CL variable for returned value, the variable is set to this value.

0
The subroutine returns a zero.
integer-constant
Specify the constant integer value for the return value.
CL-variable-name
Specify the name of the CL variable to contain the return value from the called subroutine. This must be a signed integer CL variable.

Examples

PGM
 :
SUBR SUBR1
 :
ENDSUBR
ENDPGM

This CL subroutine is identified by a SUBR command that contains the subroutine name, SUBR1, and is ended by the ENDSUBR command.

PGM
 :
SUBR SUBR1
 :
ENDSUBR RTNVAL(-1)
ENDPGM

This CL subroutine has an ENDSUBR command that returns a -1.

Error messages

None