IBM AS/400 Frozen Dessert Maker User Manual


 
Example of Module with Multiple Procedures
1 All subprocedures begin and end with procedure specifications.
2 After the Begin-Procedure specification (B in position 24 of the proce-
dure specification), you code a procedure interface definition. The return
value, if any, is defined on the PI specification. Any parameters are
listed after the PI specification.
3 Any variables or prototypes that are used by the subprocedure are
defined after the procedure interface definition.
4 The return value, if specified, is returned to the caller with a RETURN
operation.
5 If the record is not in arrears, the subprocedure returns '0' to the main
procedure.
For all subprocedures, and also for a main procedure with prototyped entry param-
eters, you need to define a procedure interface. A procedure interface definition
is a repeat of the prototype information within the definition of a procedure. It is
used to define the entry parameters for the procedure. The procedure interface
definition is also used to ensure that the internal definition of the procedure is con-
sistent with the external definition (the prototype). In the case of InArrears, there
are no entry parameters.
Consider next the subprocedure FmtCust, which is shown in Figure 19 on
page 39. FmtCust is called by ARRSRPT to format the relevant fields of a record
into an output record for the final report. (The record represents an account that is
in arrears.) FmtCust uses global data, and so does not have any input parameters.
It formats the data into two output fields: one for the name, and one for the
address.
One of the formatting tasks requires converting a numeric field to a character field
to match the output field type. This conversion could be coded as part of the sub-
procedure itself. However, as this is a task that might be required by other reports,
we decided to code the conversion as a separate subprocedure, NumToChar.
NumToChar takes as input a numeric parameter that is passed by value. It con-
verts the number to a character field and returns that field to the caller, in this case
FmtCust.
38 ILE RPG for AS/400 Programmer's Guide