IBM AS/400 Frozen Dessert Maker User Manual


 
Example of Module with Multiple Procedures
In order to format the name and address properly, FmtCust calls NumToChar to
convert the customer number to a character field. Because FmtCust wants to use
the return value, the call to NumToChar is made in an expression. Figure 16 on
page 36 shows the call.
*--------------------------------------------------------------
* CUSTNAME and CUSTNUM are formatted to look like this:
* A&P Electronics (Customer number 157)
*--------------------------------------------------------------
C EVAL Name = CUSTNAME + ' '
C + '(Customer number '
C + %trimr(NumToChr(CUSTNUM)) + ')'
Figure 16. Calling the NumToChar Procedure
The use of procedures to return values, as in the above figure, allows you to write
any user-defined function you require. In addition, the use of a prototyped call inter-
face opens up a number of new options for parameter passing.
Prototyped parameters can be passed in several ways: by reference, by value
(for procedures only), or by read-only reference. The default method for RPG is
to pass by reference. However, passing by value or by read-only reference
gives you more options for passing parameters.
If the prototype indicates that it is allowed for a given parameter, you may be
able to do one or more of the following:
Pass *OMIT
Leave out a parameter entirely
Pass a shorter parameter than is specified (for character and graphic
parameters, and for array parameters)
Example of Module with Multiple Procedures
Now let us look at an example of a multiple procedures module. In this 'mini-
application' we are writing a program ARRSRPT to produce a report of all cus-
tomers whose accounts are in arrears. We will create the basic report as a module,
so that it can be bound to other modules, if necessary. There are two main tasks
that are required for this module:
1. Determine that a record of an account from a customer file is in arrears.
2. Format the data into a form that is suitable for the report.
We have decided to code each task as a subprocedure. Conceptually, the module
will look something like that shown in Figure 17 on page 37.
36 ILE RPG for AS/400 Programmer's Guide