HP 3000 Manuals

Using Source Libraries [ HP RPG/XL Programmer's Guide ] MPE/iX 5.0 Documentation


HP RPG/XL Programmer's Guide

Using Source Libraries 

Source libraries help to standardize parts of RPG programs and reduce the
manual effort in coding programs.  You enter commonly-used source code
into a source library, then copy that code into programs rather than
recoding it in each of them.

An RPG source library is a standard text file containing RPG
specifications.  You can create a source library using any text
processor, such as EDITOR. Enter the RPG specifications exactly as they
should appear in a source program.  When you want to use the source
libraries in a program, enter a $COPY statement at the beginning of the
program.  $COPY enables the source library facility of RPG. At the point
in the program where you want to insert the source library text, enter an
$INCLUDE statement.

Figure 6-1 lists a program that extracts records from the D-ACCOUNTS data
set (see the MARKET schema in Figure 3-23).  It prints the extracted
records and writes them to the file EXTRACT. There are two $INCLUDE
statements in the program.  The first (line 3) copies the input field
definitions for D-ACCOUNTS. The second (line 5) copies the output field
definitions for the detail report record.  Figure 6-2 and Figure 6-3 list
the contents of the source library files and Figure 6-4 shows what the
compiled source program listing looks like.

	       Click here to view figure.
          Figure 6-1.  A Source Program Before Compilation 

	       Click here to view figure.
          Figure 6-1.  A Source Program Before Compilation (Continued) 

            Comments 

 1       This $COPY subsystem command specifies that the preprocessor
         utility (RPGCOPY.PUB.SYS) is used during compilation.  RPGCOPY
         processes $INCLUDE statements.  $COPY must be the first
         statement in the program.

 2       This $CONTROL subsystem command contains the RSPACE option.
         RSPACE directs the compiler to add 2 spaces between each output
         field having relative end positions.

 3       This $INCLUDE subsystem command directs the compiler to insert
         source library text at this point in the program.  The text
         comes from the file, DACT1, in group SOURCE.

 4       This line begins the specifications for the report headings.

 5       This $INCLUDE command directs the compiler to insert source
         library text at this point in the program.  The text comes from
         the file, DACT2, in group SOURCE.

Figure 6-2 lists the entries in the source library file, DACT1.
________________________________________________
|                                              |
|     IDACCOUNTNS   01             3    8 ACTNO|
|     I                            9   18 FNAME|
|     I                           19   34 LNAME|
|     I                           35   62 ADDR1|
|     I                           63   90 ADDR2|
|     I                           91  118 ADDR3|
|     I                          119  128 ZIPCD|
|     I                          129  134OPHONE|
|     I                          135  136OPHEXT|
|     I                          137  144 MAILC|
|     I                          145  148OBDATE|
|     I                          149  152 SRCCD|
|     I                          153  154 TYPEC|
|     I                          155  162 ADATE|
|                                              |
________________________________________________

          Figure 6-2.  Contents of the Source Library DACT1.SOURCE 

Figure 6-3 lists the entries in the source library file, DACT2.
_____________________________________
|                                   |
|     O                 ACTNO       |
|     O                 FNAME       |
|     O                 LNAME       |
|     O                 ADDR1       |
|     O                 ADDR2       |
|     O                 ZIPCD       |
|                                   |
_____________________________________

          Figure 6-3.  Contents of the Source Library DACT2.SOURCE 

Figure 6-4 shows, in effect, what the program looks like after the source
text is inserted.  Source library text is inserted during the compilation
process; it is not incorporated as a permanent part of the source
program.  In the listing, a "C" precedes the text that has been copied
and $COPY and $INCLUDE are changed to *COPY and *INCLUDE.

     ---------------------------------------------------------------

         *COPY
         $CONTROL  RSPACE=2
         H*  EXTRACT  RECORDS  FROM  D-ACCOUNTS
         HDUMPRPG

         FDACCOUNTIP  F  200  200    AM    DISC
         F                                          KIMAGE MARKET62
         F                                          KLEVEL READER
         F                                          KDSNAMED-ACCOUNTS
         FDEXTRACTO   F       200          DISC
         FREPORT  O   F  132  132          LP
         *INCLUDE DACT1
      1  CIDACCOUNTNS 01
         CI                                       3    8 ACTNO
         CI                                       9   18 FNAME
         CI                                      19   34 LNAME
         CI                                      35   62 ADDR1
         CI                                      63   90 ADDR2
         CI                                      91  118 ADDR3
         CI                                     119  128 ZIPCD
         CI                                     129  134OPHONE
         CI                                     135  136OPHEXT
         CI                                     137  144 MAILC
         CI                                     145  148OBDATE
         CI                                     149  152 SRCCD
      2  MI                                     153  154 TYPEC
         CI                                     155  162 ADATE
      3  I                                       1  200 RECORD

          C*  PERFORM  FIELD  COMPARES  FOR  RECORD  SELECTION
          C*        .
          C*        .
          C*        .

     ---------------------------------------------------------------

          Figure 6-4.  A Source Program After Compilation 

     ----------------------------------------------------------------

          ODEXTRACTD     01  20
          O                         RECRD    200
          OREPORT   H    1P
          O                                    6 "ACCT #"         R
          O                                   18 "FIRST NAME"     R
          O                                   36 "LAST NAME  "    R
          O                                   66 "ADDRESS 1  "    +019
          O                                   96 "ADDRESS 2  "    +019
          O         D    01                  108 "ZIP CODE  "     R
          O
          *INCLUDE  DACT2
      4  CO                        ACTNO       6                  R
         CO                        FNAME      18                  R
         CO                        LNAME      36                  R
         CO                        ADDR1      66                  R
         CO                        ADDR2      96                  R
         CO                        ZIPCO     108                  R
     -----------------------------------------------------------------
          Figure 6-4.  A Source Program After Compilation (Continued) 

            Comments 

 1       This is the first line copied from source library, DACT1.  Each
         of the lines in DACT1, except for lines 2 and 3, are copied.

 2       This line remains the same as that in the original program.
         Fields with the same names remain unaltered.

 3       This field does not exist in the source library; therefore, it
         remains unaltered.

 4       This is the first line copied from source library, DACT2.



MPE/iX 5.0 Documentation