IBM AS/400 Frozen Dessert Maker User Manual


 
Returning from a Called Program or Procedure
All files that are open are closed.
Any data areas locked by the procedure are unlocked.
If the main procedure ended because of a cancel reply to an inquiry message,
then it was a function check that caused the abnormal end. In this case, the
function check is percolated to the caller. If it ended because of an error sub-
routine ending with '*CANCL', then escape message RNX9001 is issued
directly to the caller. Otherwise the caller will see whatever exception caused
the abnormal end.
On the next call to the procedure, a fresh copy is available for processing. (For
more information on exception handlers, see “Using RPG-Specific Handlers” on
page 226.)
Returning without Ending
A main procedure can return control to the calling procedure without ending when
none of the LR or H1 through H9 indicators are on and one of the following occurs:
The RETURN operation (with a blank factor 2) is processed.
The RT indicator is on and control reaches the *GETIN part of the RPG cycle,
in which case control returns immediately to the calling procedure. (For further
information on the RT indicator, see the
ILE RPG for AS/400 Reference
)
If you call a main procedure and it returns without ending, when you call the proce-
dure again, all fields, indicators, and files in the procedure will hold the same values
they did when you left the procedure. However, there are three exceptions:
This is not true if the program is running in a *NEW activation group, since the
activation group is deleted when the program returns. In that case, the next
time you call your program will be the same as if you had ended with LR on.
If you are sharing files, the state of the file may be different from the state it
held when you left the procedure.
If another procedure in the same module was called in between, then the
results are unpredictable.
You can use either the RETURN operation (with a blank factor 2) or the RT indi-
cator in conjunction with the LR indicator and the H1 through H9 indicators. Be
aware of the testing sequence in the RPG program cycle for the RETURN opera-
tion, the RT indicator, and the H1 through H9 indicators. A return will cause an end
if the LR indicator or any of the halt indicators is on and either of the following
conditions is true:
A RETURN operation is done
The RT would cause a return without an end
Returning from a Subprocedure
A subprocedure returns normally when a RETURN operation is performed suc-
cessfully or when the last statement in the procedure (not a RETURN operation) is
processed. However, other than the removal of the subprocedure from the call
stack no termination actions are performed until the main procedure of the program
ends. In other words, all the actions listed for the normal end of a main procedure
take place
only
for the main procedure.
154 ILE RPG for AS/400 Programmer's Guide