Use existing field descriptions and field reference files to describe a database file

If a field was already described in an existing file, and you want to use that field description in a new file you are setting up, you can request the system to copy that description into your new file description.

DDS keywords REF and REFFLD allow you to refer to a field description in an existing file. This helps reduce the effort of coding DDS statements. It also helps ensure that the field attributes are used consistently in all files that use the field.

In addition, you can create a physical file for the sole purpose of using its field descriptions. That is, the file does not contain data; it is used only as a reference for the field descriptions for other files. This type of file is known as a field reference file. A field reference file is a physical file containing no data, just field descriptions.

You can use a field reference file to simplify record format descriptions and to ensure that field descriptions are used consistently. You can define all the fields you need for an application or any group of files in a field reference file. You can create a field reference file using DDS and the Create Physical File (CRTPF) command.

After the field reference file is created, you can build physical file record formats from this file without describing the characteristics of each field in each file. When you build physical files, all you need to do is to refer to the field reference file (using the REF and REFFLD keywords) and specify any changes. Any changes to the field descriptions and keywords specified in your new file override the descriptions in the field reference file.

In the following example, a field reference file named DSTREFP is created for distribution applications. The following example shows the DDS needed to describe DSTREFP.

|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
     A* FIELD REFERENCE FILE (DSTREFP)
     A          R DSTREF                    TEXT('Field reference file')
     A
     A* FIELDS DEFINED BY CUSTOMER MASTER RECORD (CUSMST)
     A            CUST           5  0       TEXT('Customer numbers')
     A                                      COLHDG('CUSTOMER' 'NUMBER')
     A            NAME          20          TEXT('Customer name')
     A            ADDR          20          TEXT('Customer address')
     A
     A            CITY          20          TEXT('Customer city')
     A
     A            STATE          2          TEXT('State abbreviation')
     A                                      CHECK(MF)
     A            CRECHK         1          TEXT('Credit check')
     A                                      VALUES('Y' 'N')
     A            SEARCH         6  0       TEXT('Customer name search')
     A                                      COLHDG('SEARCH CODE')
     A            ZIP            5  0       TEXT('Zip code')
     A                                      CHECK(MF)
     A            CUTYPE         15         COLHDG('CUSTOMER' 'TYPE')
     A                                      RANGE(1 5)
     A
     A* FIELDS DEFINED BY ITEM MASTER RECORD (ITMAST)
     A            ITEM           5          TEXT('Item number')
     A                                      COLHDG('ITEM' 'NUMBER')
     A                                      CHECK(M10)
     A            DESCRP        18          TEXT('Item description')
     A            PRICE          5  2       TEXT('Price per unit')
     A                                      EDTCDE(J)
     A                                      CMP(GT 0)
     A                                      COLHDG('PRICE')
     A            ONHAND         5  0       TEXT('On hand quantity')
     A                                      EDTCDE(Z)
     A                                      CMP(GE 0)
     A                                      COLHDG('ON HAND')
     A            WHSLOC         3          TEXT('Warehouse location')
     A                                      CHECK(MF)
     A                                      COLHDG('BIN NO')
     A            ALLOC     R               REFFLD(ONHAND *SRC)
     A                                      TEXT('Allocated quantity')
     A                                      CMP(GE 0)
     A                                      COLHDG('ALLOCATED')
     A
     A* FIELDS DEFINED BY ORDER HEADER RECORD (ORDHDR)
     A            ORDER          5  0       TEXT('Order number')
     A                                      COLHDG('ORDER' 'NUMBER')
     A            ORDATE         6  0       TEXT('Order date')
     A                                      EDTCDE(Y)
     A                                      COLHDG('DATE' 'ORDERED')
     A            CUSORD        15          TEXT('Cust purchase ord no.')
     A                                      COLHDG('P.O.' 'NUMBER')
     A            SHPVIA        15          TEXT('Shipping instructions')
     A            ORDSTS         1          TEXT('Order status code')
     A                                      COLHDG('ORDER' 'STATUS')
     A            OPRNME    R               REFFLD(NAME *SRC)
     A                                      TEXT('Operator name')
     A                                      COLHDG('OPERATOR NAME')
     A            ORDAMT         9  2       TEXT('Total order value')
     A                                      COLHDG('ORDER' 'AMOUNT')
	  A            INVNBR         5  0       TEXT('Invoice number')
     A                                      COLHDG('INVOICE' 'NUMBER')
     A            PRTDAT         6  0       EDTCDE(Y)
     A                                      COLHDG('PRINTED' 'DATE')
     A            SEQNBR         5  0       TEXT('Sequence number')
     A                                      COLHDG('SEQ' 'NUMBER')
     A            OPNSTS         1          TEXT('Open status')
     A                                      COLHDG('OPEN' 'STATUS')
     A            LINES          3  0       TEXT('Lines on invoice')
     A                                      COLHDG('TOTAL' 'LINES')
     A            ACTMTH         2  0       TEXT('Accounting month')
     A                                      COLHDG('ACCT' 'MONTH')
     A            ACTYR          2  0       TEXT('Accounting year')
     A                                      COLHDG('ACCT' 'YEAR')
     A
     A* FIELDS DEFINED BY ORDER DETAIL/LINE ITEM RECORD (ORDDTL)
     A            LINE           3  0       TEXT('Line no. this item')
     A                                      COLHDG('LINE' 'NO')
     A            QTYORD         3  0       TEXT('Quantity ordered')
     A                                      COLHDG('QTY' 'ORDERED'
     A                                      CMP(GE 0)
     A            EXTENS         6  2       TEXT('Ext of QTYORD x PRICE')
     A                                      EDTCDE(J)
     A                                      COLHDG('EXTENSION')
     A
     A* FIELDS DEFINED BY ACCOUNTS RECEIVABLE
     A            ARBAL          8  2       TEXT('A/R balance due')
     A                                      EDTCDE(J)
     A
     A* WORK AREAS AND OTHER FIELDS THAT OCCUR IN MULTIPLE PROGRAMS
     A            STATUS        12          TEXT('status description')
     A     A
Assume that the DDS in the previous example is entered into a source file FRSOURCE; the member name is DSTREFP. To create a field reference file, use the CRTPF command as follows:
CRTPF FILE(DSTPRODLB/DSTREFP)
      SRCFILE(QGPL/FRSOURCE) MBR(*NONE)
      TEXT('Distribution field reference file')

The parameter MBR(*NONE) tells the system not to add a member to the file (because the field reference file never contains data and therefore does not need a member).

To describe the physical file ORDHDRP by referring to DSTREFP, use the following DDS example:

|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
     A* ORDER HEADER FILE (ORDHDRP) - PHYSICAL FILE RECORD DEFINITION
     A                                      REF(DSTREFP)
     A          R ORDHDR                    TEXT('Order header record')
     A            CUST      R
     A            ORDER     R
     A            ORDATE    R
     A            CUSORD    R
     A            SHPVIA    R
     A            ORDSTS    R
     A            OPRNME    R
     A            ORDAMT    R
     A            CUTYPE    R
     A            INVNBR    R
     A            PRTDAT    R
     A            SEQNBR    R
     A            OPNSTS    R
     A            LINES     R
     A            ACTMTH    R
     A            ACTYR     R
     A            STATE     R
     A

The REF keyword (positions 45 through 80) with DSTREFP (the field reference file name) specified indicates the file from which field descriptions are to be used. The R in position 29 of each field indicates that the field description is to be taken from the reference file.

When you create the ORDHDRP file, the system uses the DSTREFP file to determine the attributes of the fields included in the ORDHDR record format. To create the ORDHDRP file, use the CRTPF command. Assume that the DDS in the previous example was entered into a source file QDDSSRC; the member name is ORDHDRP.
   CRTPF FILE(DSTPRODLB/ORDHDRP)
         TEXT('Order Header physical file')
Note: The files used in some of the examples in this topic collection refer to this field reference file.