*---------*---------------*-----------------*----------------*---------------* | CODE | FACTOR 1 | FACTOR 2 | RESULT | INDICATORS | | | | | FIELD | | *---------*---------------*-----------------*----------------*---------------* | ENDSR | Label | Return point | | | *---------*---------------*-----------------*----------------*---------------*
The ENDSR operation defines the end of an RPG/400 subroutine and the return point to the main program. ENDSR must be the last statement in the subroutine. Factor 1 can contain a label that can be used as a point to which a GOTO operation within the subroutine can branch. 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 operation unless the subroutine is a program exception/error subroutine (*PSSR) or a file exception/error subroutine (INFSR). For these subroutines, factor 2 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/400 error handler receives control.
See Figure "Example of Coding Subroutines" for an example of coding an RPG/400 subroutine.
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.