Sign in

docs RPG Guide

The Entire ARRSRPT Program

The Entire ARRSRPT Program

The ARRSRPT program consists of two modules: ARRSRPT and FMTPROCS. Figure 1 shows the different pieces of our mini-application.

Figure 1. The ARRSRPT Application

Figure 2 shows the source for the entire ARRSRPT module.

Figure 2. ILE RPG Complete Source for 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 definition specifications begin with the prototypes for the prototyped calls. A /COPY file is used to supply the prototype for the called procedure FmtAddr.

    The prototypes do not have to be first, but you should establish an order for the different types of definitions for consistency.

  • The date field CurDate is a global field, meaning that any procedure in the module can access it.

  • The main procedure is simple to follow. It contains calculation specifications for the two main tasks: the I/O, and an initialization routine.

  • Each subprocedure that follows the main procedure contains the details of one of the tasks.

Sample output for the program ARRSRPT is shown in Figure 3.

Figure 3. Output for ARRSRPT

     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 4 and Figure 5 show the DDS source for the files CUSTFILE and CUSTRPT respectively.

Figure 4. DDS for CUSTFILE

     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')

Figure 5. DDS for CUSTRPT

     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')