RPG Tutorial: Example Program 8 - Using a Record Address File for ISAM Access

  1  H                                                                    EXAMP8
  2  H*
  3  H* PRINT STUDENT GRADE REPORT
  4  H*
  5  FSTMASTR UP  F 250 250R 7KI     2 DISK14       S
  6  FRAF     IRE F5000  50  7        ETAPE         S
  7  FTABLE   IT  F  80  80           ETAPE         S
  8  FREPORT  O   F 132 132     OF    LPRINTER
  9  E    RAF     STMASTR
  10 E    TABLE           TABCNR  1 120  5  ATABCNA 51
  11 LREPORT    101 6012
  12 ISTMASTR AA  01   1 CA
  13 I       OR   91   1 CD
  14 I                                        9  43 NAME
  15 I                                      136 1410CN1N            11
  16 I                                      136 140 CN1
  17 I                                    P 142 1442CN1G
  18 I                                      145 1500CN2N            12
  19 I                                      145 149 CN2
  20 I                                    P 151 1532CN2G
  21 I                                      154 1590CN3N            13
  22 I                                      154 158 CN3
  23 I                                    P 160 1622CN3G
  24 I                                      163 1680CN4N            14
  25 I                                      163 167 CN4
  26 I                                    P 169 1712CN4G
  27 I                                      172 1770CN5N            15
  28 I                                      172 176 CN5
  29 I                                    P 178 1802CN5G
  30 I                                      181 1860CN6N            16
  31 I                                      181 185 CN6
  32 I                                    P 187 1892CN6G
  33 I                                      190 1950CN7N            17
  34 I                                      190 194 CN7
  35 I                                    P 196 1982CN7G
  36 I                                      199 2040CN8N            18
  37 I                                      199 203 CN8
  38 I                                    P 205 2072CN8G
  39 I                                    P 208 2102GPA
  40 C*
  41 C*  FOR EACH COURSE IN THE STUDENT RECORD WHICH CONTAINS A COURSE
  42 C*  NUMBER, COMPUTE EARNED GRADE POINTS AND ACCUMULATE ATTEMPTED
  43 C*  HOURS AND GRADE POINTS
  44 C*
  45 C   01                Z-ADD0         THOURS  30
  46 C   01                Z-ADD0         TGPTS   52
  47 C*
  48 C   01                SETOF                     21
  49 C   01N11   CN1       LOKUPTABCNR    TABCNA 51      21
  50 C   01 21             MOVE TABCNA    CRSHRS  10
  51 C   01 21   THOURS    ADD  CRSHRS    THOURS
  52 C   01 21   CN1G      MULT CRSHRS    GPTS    52
  53 C   01 21   TGPTS     ADD  GPTS      TGPTS
  54 C*
  55 C   01                SETOF                     21
  56 C   01N12   CN2       LOKUPTABCNR    TABCNA 51      21
  57 C   01 21             MOVE TABCNA    CRSHRS
  58 C   01 21   THOURS    ADD  CRSHRS    THOURS
  59 C   01 21   CN2G      MULT CRSHRS    GPTS
  60 C   01 21   TGPTS     ADD  GPTS      TGPTS
  61 C*
  62 C   01                SETOF                     21
  63 C   01N13   CN3       LOKUPTABCNR    TABCNA 51      21
  64 C   01 21             MOVE TABCNA    CRSHRS
  65 C   01 21   THOURS    ADD  CRSHRS    THOURS
  66 C   01 21   CN3G      MULT CRSHRS    GPTS
  67 C   01 21   TGPTS     ADD  GPTS      TGPTS
  68 C*
  69 C   01                SETOF                     21
  70 C   01N14   CN4       LOKUPTABCNR    TABCNA 51      21
  71 C   01 21             MOVE TABCNA    CRSHRS
  72 C   01 21   THOURS    ADD  CRSHRS    THOURS
  73 C   01 21   CN4G      MULT CRSHRS    GPTS
  74 C   01 21   TGPTS     ADD  GPTS      TGPTS
  75 C*
  76 C   01                SETOF                     21
  77 C   01N15   CN5       LOKUPTABCNR    TABCNA 51      21
  78 C   01 21             MOVE TABCNA    CRSHRS
  79 C   01 21   THOURS    ADD  CRSHRS    THOURS
  80 C   01 21   CN5G      MULT CRSHRS    GPTS
  81 C   01 21   TGPTS     ADD  GPTS      TGPTS
  82 C*
  83 C   01                SETOF                     21
  84 C   01N16   CN6       LOKUPTABCNR    TABCNA 51      21
  85 C   01 21             MOVE TABCNA    CRSHRS
  86 C   01 21   THOURS    ADD  CRSHRS    THOURS
  87 C   01 21   CN6G      MULT CRSHRS    GPTS
  88 C   01 21   TGPTS     ADD  GPTS      TGPTS
  89 C*
  90 C   01                SETOF                     21
  91 C   01N17   CN7       LOKUPTABCNR    TABCNA 51      21
  92 C   01 21             MOVE TABCNA    CRSHRS
  93 C   01 21   THOURS    ADD  CRSHRS    THOURS
  94 C   01 21   CN7G      MULT CRSHRS    GPTS
  95 C   01 21   TGPTS     ADD  GPTS      TGPTS
  96 C*
  97 C   01                SETOF                     21
  98 C   01N18   CN8       LOKUPTABCNR    TABCNA 51      21
  99 C   01 21             MOVE TABCNA    CRSHRS
 100 C   01 21   THOURS    ADD  CRSHRS    THOURS
 101 C   01 21   CN8G      MULT CRSHRS    GPTS
 102 C   01 21   TGPTS     ADD  GPTS      TGPTS
 103 C*
 104 C* COMPUTE FINAL GRADE POINT AVERAGE
 105 C*
 106 C   01      TGPTS     DIV  THOURS    GPA       H
 107 OSTMASTR D        01
 108 O                         GPA      210P
 109 OREPORT  H  201   1P
 110 O       OR        OF
 111 O                                   34 'STUDENT GRADE REPORT'
 112 O        D  1     01
 113 O                         GPA       55 '  0.  '
 114 O                         NAME      40

Statement 5 is the File Description specification for the student master ISAM file which will be accessed using a Record Address File (RAF).  Note that it is still specified as the primary input file, even though the access is via the Record Address File.  End of File (column 17) is not specified as end of file is actually signaled by the exhaustion of records in the RAF file.  Mode of Processing (column 28) contains R since the mode of access under the control of a Record Address File is random.

Statement 6 is the specificaton for the Record Address File.  The important entries to note are:  File Designation (column 16), End of File (column 17), Length of Record Address Field (columns 29-30), and Extension (column 39).

The Extension specification for a Record Address File (statement 9) only needs the entries for From File (the Record Address File name, columns 11-18) and To File (the name of the ISAM file being accessed with the RAF file, columns 19-26). 

Statements 12-39 define the records and fields in the ISAM student master file.  There is no difference in Input specifications for accessing the file with a Record Address File versus processing the file directly.  There are no Input specifications required for the Record Address File itself.

The Calculation specifications are simple, although lengthy.  For each course in the student master in which the course number is not zero, the course is looked up in a table (TABCNR/TABCNA) to determine the number of credit hours for the course, the credit hours are accumulated, the earned grade is multipled by the credit hours to compute the earned credit hours, and the earned credit hours are accumulated.  This code must be coded repeatedly as RPG I does not possess the capability to define subroutines internally.

The final step of the Calculations (statement 106) is to compute the grade point average using the accumulated attempted hours and earned credit hours.  The result of the division, which is half adjusted to round the result, is placed in the GPA field from the student master record.

Statement 108 writes the updated GPA field back into the student master record.  

The report (statements 109-114) is to list the student name and computed grade point average.  Since the Record Address File is in order by the student name, the report will be in alphabetical order by student.

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

The jobstream, complete with JCL and RPG source are available for download here:  Example 8 jobstream.   The table files and the Record Address File are contained on a AWSTape files - jay801.aws and jay803.aws (also in the archive).   You will need to ensure that the volume serial numbers for the files are correct for your MVT system before running the jobstream.  Note:  There are two jobstreams in this archive, one is for MVS and the other is for MVT.  The difference is that the MVS jobstream uses the ISAM-VSAM interface to access an VSAM cluster instead of creating a native ISAM dataset.

Note:  ADDROUT and Record Address Files are typically created using the Sort/Merge Utility.  The MVT Sort/Merge Utility lacks the advanced features to select fields from input records to tailor the output record, so the Record Address File (included in the archive) was created using a simple RPG program to extract the student ID number and student name, which were then sorted to create the tape dataset.



Return to Site Home Page 


This page was last updated on January 17, 2015.