ENDSR (End of Subroutine)
Free-Form Syntax | ENDSR {return-point} |
Code | Factor 1 | Factor 2 | Result Field | Indicators | ||
---|---|---|---|---|---|---|
ENDSR | label | return-point |
The ENDSR operation defines the end of an RPG IV subroutine and the return point (return-point) to the cycle-main program. ENDSR must be the last statement in the subroutine. In traditional syntax, the label operand can be specified as a point to which a GOTO operation within the subroutine can branch. (You cannot specify a label in free-form syntax.) The control level entry (positions 7 and 8) can be SR or blank. Conditioning indicator entries are not allowed.
The ENDSR operation ends a subroutine and causes a branch back
to the statement immediately following the EXSR or CASxx operation
unless the subroutine is a program exception/error subroutine (*PSSR)
or a file exception/error subroutine (INFSR). For these subroutines,
the return-point operand of the ENDSR operation
can contain an entry that specifies where control is to be returned
following processing of the subroutine. This entry can be a field
name that contains a reserved keyword or a literal or named constant
that is a reserved keyword. If a return point that is not valid is
specified, the RPG IV error handler receives control.
Note: The return-point operand cannot be
specified for an ENDSR operation that occurs within a subprocedure
(including a linear-main procedure).
See File Exception/Error Subroutine (INFSR) for more detail on return points.
See Figure 1 for an example of coding an RPG IV subroutine.
For more information, see Subroutine Operations.