When to specify REF and REFFLD keywords for DDS files
When you decide whether to specify the REF (reference) keyword, the REFFLD (referenced field) keyword, or both, you need to consider some questions. You also need to know how to specify the parameter values for each REF or REFFLD keyword that you specify.
You must specify R in position 29 for each field that refers to another field that was previously defined.
Answer the following questions to determine which keyword to use:
- REF or REFFLD or both?
If all or most of the fields you refer to are defined REF at the file level.
Specify REFFLD for every field you reference:- That is not in the file you specify on the REF keyword.
or
- Whose name differs from the name of the field it references. This includes fields that reference fields in the file you are defining.
- That is not in the file you specify on the REF keyword.
- Do you need a database file name for each REFFLD keyword you specify?
The database file name specified on a REFFLD keyword overrides the database file name specified on the REF keyword.
On the REFFLD keyword, you can specify:- *SRC so that the IBM® i operating system searches the file you are defining for the referenced field. The referenced field must be defined before you define the field that references it.
- The name of the database file that the IBM i operating system is to search through to find the referenced field.
If you do not specify *SRC or a database file name on the REFFLD keyword, the default is *SRC if the REF keyword is not specified. If the REF keyword is specified, the default is the database file name specified on the REF keyword.
- Is a library name necessary for each database file you specify?
If the job that will create the file you are defining (perhaps your interactive job) has a library list, and the database file you specified is on the library list, enter only the file name (FILE1). Otherwise, specify the file name qualified by the library name (LIB1/FILE1).
- Do you need a record format name for each REF or REFFLD keyword you specify?
If the file you reference has only one record format, do not specify a record format name.
If it has more than one record format, specify a record format name.
The following example illustrates reference function specifications. It is not a valid example of any file except an ICF file. Display and printer files must have a location specified for each field. Physical files can have only one record format. The REF and REFFLD keywords are not allowed in logical files.
|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
00010A REF(FILE1) (1)
00020A R RECORD1
00030A FIELD1 R (1)
00040A FIELD2 R (1)
00050A FIELD3 R REFFLD(FLD3) (2)
00060A FIELD4 R REFFLD(FLD4 FILE2) (3)
00070A FIELD5 R REFFLD(FLD5 LIB1/FILE3) (4)
00080A FIELD6 R REFFLD(RECORDB/FLD6 LIB1/FILE4) (5)
00090A FIELD7 R REFFLD(FIELD6 *SRC) (6)
00100A FIELD8 R REFFLD(FLD6) (7)
00110A R RECORD2
00120A FIELD1 20 (8)
00130A
00140A R RECORD3
00150A FIELD1 R REFFLD(RECORD2/FIELD1 *SRC) (9)
00160A
00170A R RECORD4
00180A FIELD1 R REFFLD(FIELD1 *SRC) (10)
A
- 1
- FIELD1 and FIELD2 have the same attributes as FIELD1 and FIELD2 in FILE1.
- 2
- FIELD3 has the same attributes as FLD3 in FILE1.
- 3
- FIELD4 has the same attributes as FLD4 in FILE2.
- 4
- FIELD5 has the same attributes as FLD5 in FILE3 in LIB1.
- 5
- FIELD6 has the same attributes as FLD6 in record format RECORDB in FILE4 in LIB1.
- 6
- FIELD7 has the same attributes as FIELD6 (on the preceding line in this file).
- 7
- FIELD8 has the same attributes as FLD6 in FILE1.
- 8
- FIELD1 in RECORD2 has unique field attributes. (It does not use the reference function; notice that R is not specified in position 29.)
- 9
- FIELD1 in RECORD3 has the same attributes as FIELD1 in RECORD2.
- 10
- FIELD1 in RECORD4 has the same attributes as FIELD1 in RECORD1.