Справочник Пользователя для IBM AS/400

Скачать
Страница из 489
 
 
For Further Information
 
The automatic storage that is associated with earlier invocations is unaffected
by later invocations. All invocations share the same static storage, so later invo-
cations can affect the value held by a variable in static storage.
Recursion can be a powerful programming technique when properly under-
stood.
¹
The run-time behavior of a subprocedure differs somewhat from that of a main
procedure, because there is no cycle code for the subprocedure.
– When a subprocedure ends, it simply returns to the caller. None of the
usual termination activities, such as closing of files, occurs until the main
procedure that is associated with the subprocedure itself ends. You should
code a "cleanup" subprocedure that is called both by the program entry
procedure at application-end, and by a cancel handler enabled for the
program entry procedure.
An alternative is to code the NOMAIN module so that there is no implicit file
opening or data area locking, and that within any subprocedure, an open is
matched by a close, an IN by an OUT, a CRT
<
temp obj> by a DLT
<
temp
obj>, and so on. This alternative applies to modules that may have a sub-
procedure active when the main procedure is not active.
– Exception handling within a subprocedure differs from a main procedure
primarily because there is no default exception handler for subprocedures.
As a result, situations where the default handler would be called for a main
procedure correspond to abnormal end of the subprocedure.
For Further Information
To find out more about the topics discussed here, consult the following list:
 Main Procedures
Topic 
See
Exception handling
“Exception Handling within a Main Procedure” on
page  220
Main Procedure End
“Returning from a Main Procedure” on page 152
 Subprocedures
Topic 
See
Defining
Chapter on subprocedures, in the 
ILE RPG for AS/400
Reference
NOMAIN module
“Creating a NOMAIN Module” on page 75
Exception handling
“Exception Handling within Subprocedures” on
page  221
Procedure Specification
Chapter on procedure specifications, in the 
ILE RPG for
AS/400 Reference
Procedure Interface
Chapter on defining data and prototypes in the 
ILE
RPG for AS/400 Reference
Subprocedure End
“Returning from a Subprocedure” on page 154
   
Chapter 4. Creating an Application Using Multiple Procedures
47