RPG Tutorial: Example Program 7 - Matching Records file update

  1  H                                                                    EXAMP7
  2  H*
  3  H* UPDATE STUDENT MASTER WITH GRADE INFORMATION
  4  H*
  5  FGRADES  IPEAF2080 104            TAPE         S
  6  FSTMASTR USEAF 250 250  7KI     2 DISK14       S
  7  FREPORT  O   F 132 132     OF    LPRINTER
  8  LREPORT    101 6012
  9  IGRADES  011 01           
  10 I                                        1   7 GIDENT  M1
  11 I                                        9  140C1N             11
  12 I                                       16  192C1G
  13 I                                       21  260C2N             12
  14 I                                       28  312C2G
  15 I                                       33  380C3N             13
  16 I                                       40  432C3G
  17 I                                       45  500C4N             14
  18 I                                       52  552C4G
  19 I                                       57  620C5N             15
  20 I                                       64  672C5G
  21 I                                       69  740C6N             16
  22 I                                       76  792C6G
  23 I                                       81  860C7N             17
  24 I                                       88  912C7G
  25 I                                       93  980C8N             18
  26 I                                      100 1032C8G
  27 ISTMASTR 011 02   1 CA
  28 I       OR   92   1 CD
  29 I                                        2   8 SIDENT  M1
  30 I                                        9  43 NAME
  31 C*
  32 C* COUNT RECORDS PROCESSED FOR SUMMARY AT END OF REPORT
  33 C*
  34 C   01      GCOUNT    ADD  1         GCOUNT  30
  35 C   02      SCOUNT    ADD  1         SCOUNT  30
  36 C   02 MR   UCOUNT    ADD  1         UCOUNT  30
  37 OSTMASTR D        02 MR
  38 O                         C1G      144P
  39 O                         C2G      153P
  40 O                         C3G      162P
  41 O                         C4G      171P
  42 O                         C5G      180P
  43 O                         C6G      189P
  44 O                         C7G      198P
  45 O                         C8G      207P
  46 OREPORT  H  201   1P
  47 O       OR        OF
  48 O                                   43 'STUDENT MASTER'
  49 O                                   29 'GRADES TO '
  50 O                                   19 'POST COURSE '
  51 O        D 11     01
  52 O                N14      C4G      111 ' 0.  '
  53 O                N14      C4N      105 '0  -   - '
  54 O                N13      C3G       95 ' 0.  '
  55 O                N13      C3N       89 '0  -   - '
  56 O                N12      C2G       79 ' 0.  '
  57 O                N12      C2N       73 '0  -   - '
  58 O                N11      C1G       63 ' 0.  '
  59 O                N11      C1N       57 '0  -   - '
  60 O                NMR                45 'STUDENT MASTER ***'
  61 O                NMR                27 '*** NO MATCHING '
  62 O                         GIDENT    11
  63 O        D  1     01
  64 O                N18      C8G      111 ' 0.  '
  65 O                N18      C8N      105 '0  -   - '
  66 O                N17      C7G       95 ' 0.  '
  67 O                N17      C7N       89 '0  -   - '
  68 O                N16      C6G       79 ' 0.  '
  69 O                N16      C6N       73 '0  -   - '
  70 O                N15      C5G       63 ' 0.  '
  71 O                N15      C5N       57 '0  -   - '
  72 O        D  1     02
  73 O                 MR                57 'UPDATED'
  74 O                         NAME      47
  75 O                         SIDENT    11
  76 O        T 31     LR
  77 O                         GCOUNTZ    7
  78 O                                   26 'GRADE RECORDS READ'
  79 O        T  1     LR
  80 O                         SCOUNTZ    7
  81 O                                   23 'STUDENT MASTER '
  82 O                                   35 'RECORDS READ'
  83 O        T  1     LR
  84 O                         UCOUNTZ    7
  85 O                                   22 'STUDENT MASTER'
  86 O                                   38 'RECORDS UPDATED'

Statements 5-6 are the File Description specifications for the two input files which will be "matched".  The primary file (GRADES) is the transaction file.  The secondary file (STMASTR) is the master file which will be updated whenever a matching record is read from the transaction file.  Notice that E has been entered in End of File (column 17) for both files to indicate that LR (last record) is not to be set on until both files have been completely processed.  Also, an 'A' has been entered in Sequence (column 18) for both files to indicate that the records in each file are in ascending sequence on the field which will be used for matching records.  For the STMASTR file, note that Mode of Processing (column 28) is blank to denote that the file is processed sequentially.

Statements 10 and 29 specify the matching field for the two files.  M1 entered in columns 61-62 causes the MR indicator (matching record) to be turned on when a record has been selected from either file which has a matching record available from the other file.

The Calculation specifications are very simple - all that is being done is the counting of records read from each input file plus a count of records which will be updated from the STMASTR file.

Statement 37 specifies that when a student master record has been read which had a matching transaction record (indicators 02 and MR are on), the student master record is to be updated.  Statements 38-45 write the grade fields from the transaction record into the corresponding grade fields in the student master record.

Statements 51-71 specify lines to be printed on the report for each transaction record.  Two lines will be printed (conditioned by indicator 01), each containing the information for four courses (course number and grade).  On the first line, if there is not a matching student master record for the grade record (MR will not be on), an error message is printed.

Statements 72-75  specify a line to be printed on the report for each student master record (conditioned by indicator 01).  If there was a matching transaction record (MR will be on), the literal 'UPDATED' will be printed beside the student's name.

The compiler listing and the output reports are available for viewing here:  Example 7 SYSOUT.

The jobstream, complete with JCL and RPG source are available for download here:  Example 7 jobstream.   The transaction file data (GRADES) is contained on a single AWS Tape image file - jay804.aws (also in the archive).   You will need to ensure that the volume serial number for the student master (STMASTR) is correct for your MVT system before running the jobstream.



Return to Site Home Page 


This page was last updated on January 17, 2015 .