The ARRSRPT program consists of two modules: ARRSRPT and FMTPROCS. Figure 21 shows the different pieces of our mini-application.
Figure 22 shows the source for the entire ARRSRPT module.
//=================================================================
// Source for module ARRSRPT. Contains a cycle-main procedure and
// two subprocedures: InArrears and FmtCust.
//
// Related Module: CVTPROCS (CharToNum called by InArrears)
//=================================================================
//--------------------------------------------------------------
// F I L E S
//
// CUSTFILE - contains customer information
// CUSTRPT - printer file (using format ARREARS)
//--------------------------------------------------------------
FCUSTFILE IP E DISK
FCUSTRPT O E PRINTER
*--------------------------------------------------------------*
* P R O T O T Y P E S
*--------------------------------------------------------------*
/COPY QRPGLE,FMTPROC_P
*--------------------------------------------------------------*
* InArrears returns '1' if the customer is in arrears
*--------------------------------------------------------------*
D InArrears PR 1A
*--------------------------------------------------------------*
* FmtCust formats CUSTNAME, CUSTNUM, STREETNAME etc into
* readable forms
*--------------------------------------------------------------*
D FmtCust PR
D Name 100A
D Address 100A
*--------------------------------------------------------------*
* G L O B A L D E F I N I T I O N S
*--------------------------------------------------------------*
D CurDate S D
ICUSTREC 01
*--------------------------------------------------------------*
* M A I N P R O C E D U R E
*--------------------------------------------------------------*
C IF InArrears() = '1'
C CALLP FmtCust(RPTNAME : RPTADDR)
C EVAL RPTNUM = CUSTNUM
C WRITE ARREARS
C ENDIF
C *INZSR BEGSR
C MOVEL UDATE CurDate
C ENDSR
*--------------------------------------------------------------*
* S U B P R O C E D U R E S
*--------------------------------------------------------------*
//--------------------------------------------------------------
// InArrears
//
// Parameters: (none)
// Globals: DUEDATE, AMOUNT, CurDate
//
// Returns: '1' if the customer is in arrears
//--------------------------------------------------------------
P InArrears B
D InArrears PI 1A
// Local declarations
D DaysLate S 10I 0
D DateDue S D
// Body of procedure
/free
DateDue = %date (DUEDATE: *ISO);
DaysLate = %diff (CurDate: DateDue: *d);
// The data in the input file comes from another type
// of computer, and the AMOUNTC field is a character
// string containing the numeric value. This string
// must be converted to the numeric AMOUNT field
// for printing.
AMOUNT = %dec(AMOUNTC : 31 : 9);
if DaysLate > 60 AND AMOUNT > 100.00;
return '1';
endif;
return '0';
/end-free
P InArrears E
//--------------------------------------------------------------
// FmtCust formats CUSTNAME, CUSTNUM, STREETNAME etc into
// readable forms
//
// Parameters: Name (output)
// Address (output)
// Globals: CUSTNAME, CUSTNUM, STREETNUM, STREETNAME, CITY
// STATE, ZIP
//--------------------------------------------------------------
P FmtCust B
D FmtCust PI
D Name 100A
D Address 100A
/free
//--------------------------------------------------------------
// CUSTNAME and CUSTNUM are formatted to look like this:
// A&P Electronics (Customer number 157)
//--------------------------------------------------------------
Name = CUSTNAME + ' ' + '(Customer number '
+ %char(CUSTNUM) + ')';
//--------------------------------------------------------------
// Call the FmtAddr procedure to handle the address
//--------------------------------------------------------------
Address = FmtAddress (STREETNUM : STREETNAME :
CITY : STATE : ZIP);
/end-free
P FmtCust E
Note the following about ARRSRPT:
The prototypes do not have to be first, but you should establish an order for the different types of definitions for consistency.
Sample output for the program ARRSRPT is shown in Figure 23.
Customer number: 00001
ABC Electronics (Customer number 1)
15 Arboreal Way, Treetop MN 12345
Amount outstanding: $1234.56 Due date: 1995-05-01
Customer number: 00152
A&P Electronics (Customer number 152)
27 Garbanzo Avenue, Smallville MN 51423
Amount outstanding: $26544.50 Due date: 1995-02-11
Figure 24 and Figure 25 show the DDS source for the files CUSTFILE and CUSTRPT respectively.
A*================================================================*
A* FILE NAME : CUSTFILE
A* RELATED PGMS : ARRSRPT
A* DESCRIPTIONS : THIS IS THE PHYSICAL FILE CUSTFILE. IT HAS
A* ONE RECORD FORMAT CALLED CUSTREC.
A*================================================================*
A* CUSTOMER MASTER FILE -- CUSTFILE
A R CUSTREC
A CUSTNUM 5 0 TEXT('CUSTOMER NUMBER')
A CUSTNAME 20 TEXT('CUSTOMER NAME')
A STREETNUM 5 0 TEXT('CUSTOMER ADDRESS')
A STREETNAME 20 TEXT('CUSTOMER ADDRESS')
A CITY 20 TEXT('CUSTOMER CITY')
A STATE 2 TEXT('CUSTOMER STATE')
A ZIP 5 0 TEXT('CUSTOMER ZIP CODE')
A AMOUNTC 15 TEXT('AMOUNT OUTSTANDING')
A DUEDATE 10 TEXT('DATE DUE')
A*================================================================*
A* FILE NAME : CUSTRPT
A* RELATED PGMS : ARRSRPT
A* DESCRIPTIONS : THIS IS THE PRINTER FILE CUSTRPT. IT HAS
A* ONE RECORD FORMAT CALLED ARREARS.
A*================================================================*
A R ARREARS
A 2 6
A 'Customer number:'
A RPTNUM 5 0 2 23
A TEXT('CUSTOMER NUMBER')
A RPTNAME 100A 3 10
A TEXT('CUSTOMER NAME')
A RPTADDR 100A 4 10
A TEXT('CUSTOMER ADDRESS')
A 5 10'Amount outstanding:'
A AMOUNT 10 2 5 35EDTWRD(' $0. ')
A TEXT('AMOUNT OUTSTANDING')
A 5 50'Due date:'
A DUEDATE 10 5 60
A TEXT('DATE DUE')