IBM AS/400 Frozen Dessert Maker User Manual


 
Multiple Procedures Module
Subprocedures offer another feature. You can pass parameters to a subprocedure
by value, and you can call a subprocedure in an expression to return a value.
Figure 12 on page 34 shows what a module might look like with multiple proce-
dures.
P
D
C
P
specification
specifications - Data items visible only
to Subprocedure 1
specifications - Can access local and
global data items
specifications
P
D
C
P
specification
specifications - Data items visible
only to Subprocedure 2
specifications - Can access local and
global data items
specifications
H
F
D
I
C
O
specifications
specifications
specifications - Data items visible
throughout module
specifications
specifications
specifications
Main Procedure
Main
Source
Section
Global
Scope
Local
Scope
Local
Scope
Subprocedure 1
Subprocedure 2
Program Data - part of main source section
*MODULE
Figure 12. An ILE RPG module with Multiple Procedures
As the picture suggests, you can now code subprocedures to handle particular
tasks. These tasks may be needed by the main procedures or by other modules in
the application. Furthermore, you can declare temporary data items in subproce-
dures and not have to worry if you have declared them elsewhere in the module.
Prototyped Calls
To call a subprocedure, you must use a prototyped call. You can also call any
program or procedure that is written in any language in this way. A prototyped call
is one where the call interface is checked at compile time through the use of a
prototype. A prototype is a definition of the call interface. It includes the following
information:
Whether the call is bound (procedure) or dynamic (program)
How to find the program or procedure (the external name)
34 ILE RPG for AS/400 Programmer's Guide