From the ILE reference manual PDF page 849
The RETURN operation causes a return to the caller. If a value is returned to the
caller, the return value is specified in the expression operand.
The actions which occur as a result of the RETURN operation differ depending on
whether the operation is in a cycle-main procedure or subprocedure. When a
cycle-main procedure returns, the following occurs:
1. The halt indicators are checked. If a halt indicator is on, the procedure ends
abnormally. (All open files are closed, an error return code is set to indicate to
the calling routine that the procedure has ended abnormally, and control
returns to the calling routine.)
2. If no halt indicators are on, the LR indicator is checked. If LR is on, the
program ends normally. (Locked data area structures, arrays, and tables are
written, and external indicators are reset.)
3. If no halt indicator is on and LR is not on, the procedure returns to the calling
routine. Data is preserved for the next time the procedure is run. Files and data
areas are not written out. See the chapter on calling programs and procedures
in the IBM Rational Development Studio for i: ILE RPG Programmer’s Guide for
information on how running in a *NEW activation group affects the operation
When a subprocedure returns, the return value, if specified on the prototype of the
called program or procedure, is passed to the caller. Automatic files are closed.
Nothing else occurs automatically. All static or global files and data areas must be
closed manually. You can set on indicators such as LR, but this will not cause
program termination to occur. For information on how operation extenders H, M, and R are used, see “Precision
Rules for Numeric Operations” on page 486.
In a subprocedure that returns a value, a RETURN operation must be coded within
the subprocedure. The actual returned value has the same role as the left-hand side
of the EVAL expression, while the extended factor 2 of the RETURN operation has
the same role as the right-hand side. An array may be returned only if the
prototype has defined the return value as an array.