EXAMPLE PROGRAM 1 (Sequential-by-Key Using Primary File)

In this example, the employee master record (EMPREC) and the weekly hours worked record (RCWEEK) are contained in the same logical file EMPL1. The EMPL1 file is defined as a primary input file and is read sequentially by key. In the data description specifications for the file, the key for the EMPREC record is defined as the ENUM (employee number) field, and the key for the RCWEEK record is defined as the ENUM field plus the WEEKNO (week number) field, which is a composite key.

Figure 1. Sequential-by-Key Processing, Example 1
      *****************************************************************
      *  PROGRAM NAME:  YTDRPT1                                       *
      * RELATED FILES:  EMPL1    (Logical File)                       *
      *                 PRINT    (Printer File)                       *
      *   DESCRIPTION:  This program shows an example of processing   *
      *                 records using the sequential-by-key method.   *
      *                 This program prints out each employee's       *
      *                 information and weekly hours worked.          *
      *****************************************************************
     FPRINT     O    F   80        PRINTER
     FEMPL1     IP   E           K DISK
      *  A record-identifying indicator is assigned to each record; these
      *  record-identifying indicators are used to control processing for
      *  the different record types.
     IEMPREC        01
     I*
     IRCWEEK        02
     I*

      *  Since the EMPL1 file is read sequentially by key, for
      *  a valid employee number, the ENUM in a RCWEEK record
      *  must be the same as the ENUM in the last retrieved EMPREC
      *  record.  This must be checked for and is done here by saving
      *  ENUMs of the EMPREC record into the field EMPNO and comparing
      *  it with the ENUMs read from RCWEEK records.
      *  If the ENUM is a valid one, *IN12 will be seton. *IN12 is
      *  used to control the printing of the RCWEEK record.

     C                   SETOFF                                       12
     C   01              MOVE      ENUM          EMPNO             5 0
     C*
     C                   IF        (*IN02='1') AND (ENUM=EMPNO)
     C                   SETON                                        12
     C                   ENDIF

     OPRINT     H    1P                     2  6
     O                                           40 'EMPLOYEE WEEKLY WORKING '
     O                                           52 'HOURS REPORT'
     O          H    01                     1
     O                                           12 'EMPLOYEE: '
     O                       ENAME               32
     O          H    01                     1
     O                                           12 'SERIAL #: '
     O                       ENUM                17
     O                                           27 'DEPT: '
     O                       EDEPT               30
     O                                           40 'TYPE: '
     O                       ETYPE               41
     O          H    01                     1
     O                                           20 'WEEK #'
     O                                           50 'HOURS WORKED'
     O          D    12                     1
     O                       WEEKNO              18
     O                       EHWRK         3     45

Feedback