IBM AS/400 Frozen Dessert Maker User Manual


 
Example of Module with Multiple Procedures
Open file, read record, write
output records, close files
Subprocedure to determine if
customer record is in arrears
Subprocedure to format
customer data into report form
Main Procedure
InArrears
FmtCust
ARRSRPT MODULE
Figure 17. Components of the ARRSRPT Module
Now consider the first subprocedure, InArrears, which is shown in Figure 18.
InArrears is called by the main procedure to determine if the current record is in
arrears.
TIP
When coding subprocedures that use global fields, you may want to establish a
naming convention that shows the item to be global. In this example, the upper-
case field names indicate DDS fields. Another option would be to prefix 'g_', or
some other string to indicate global scope.
If the record is in arrears, the subprocedure returns '1' to the main procedure.
*--------------------------------------------------------------*
* InArrears
*
* Parameters: (none)
* Globals: DUEDATE, AMOUNT, CurDate
*
* Returns: '1' if the customer is in arrears
*--------------------------------------------------------------*
P InArrears B 1
D InArrears PI 1A 2
* Local declarations
D DaysLate S 10I 0 3
D DateDue S D 3
* Body of procedure
C *ISO MOVE DUEDATE DateDue
C CurDate SUBDUR DateDue DaysLate:*D
C IF DaysLate > 60 AND
C AMOUNT > 100.00
C RETURN '1' 4
C ELSE
C RETURN '0' 4 5
C ENDIF
P InArrears E 1
Figure 18. Source for Subprocedure InArrears
Figure 18 shows the main elements that are common to all subprocedures.
Chapter 4. Creating an Application Using Multiple Procedures 37