How can we help you?

We have hundreds of highly-qualified, experienced experts working in 70+ technologies.

IBM i e-Book

A Developer’s Guide to Mastering IBM i Concepts

Deep Dive into DDS and DDL

Field Reference Files

In AS400, Field Reference file or simply a Reference file is nothing but a physical file which does not contain any data. Only the field descriptions that is its data type, length, and CCSID information, etc. is present in source of physical file.

DDS Keywords:

  • REF – This is a file level keyword.
  • REFFLD – This is a field level keyword.
  • FORMAT – This is a record-level keyword.

The above DDS keywords allow us to refer to a field description in an existing file.

Utilizing these keywords eliminates the necessity to repeatedly specify the field and its description when used in another file.

A) Using REF(Reference) keyword in Physical File (PF)

REF keyword is a file-level keyword in DDS for physical files.

This REF keyword can be used to specify files from where the field descriptions are to be retrieved in the current DDS PF.

Syntax:
  • REF keyword with Library name(optional)and Filename and Record format name(optional).REF(LibraryName/FileName RecordFormatName)
  • REF keyword with file nameREF(FileName)
  • If you do not specify library name, then at the time of compilation *LIBL library list is searched for the file.
  • If you do not specify the record format name, then each record format is searched sequentially in the file to find the field description.

Example of using REF keyword in DDS physical file:

  • Suppose EMPLOYEE file is a Reference file and DDS is as follows in which all fields are declared with field name, field length, data type.
  • Let’s create the ACCOUNT file that refers to the field description from Reference file EMPLOYEE using the REF keyword.
  • The above DDS code can also be written below.

So, all the fields in ACCOUNT have the same field attributes as defined in EMPLOYEE file after using the REF keyword.

B) Using REFFLD(Referenced Field) keyword in Physical File

The REFFLD keyword is a field-level keyword in DDS Physical files.

This REFFLD keyword can be used to refer to field descriptions either from one file or multiple files.

Syntax:
  • REFFLD with only Referenced Field Name when referring to the same DDS file field.REFFLD(ReferenceFieldName)
  • REFFLD with Record format(optional) name and Referenced Field Name when referring to the same DDS file field.REFFLD(RecordFormatName/ReferenceFieldName)
  • REFFLD with Referenced Field Name and File Name when referring to the different DDS file field.REFFLD(ReferenceFieldName FileName)
  • REFFLD with Referenced Field Name and Library Name(optional) and File Name when referring to the different DDS file field.REFFLD(ReferenceFieldName LibraryName/FileName)
  • REFFLD with Record Format Name(optional) and Referenced Field Name and Library Name(optional) and File Name when referring to the different DDS file field.REFFLD(RecordFormatName/ReferenceFieldName LibraryName/FileName)

Example of using REFFLD keyword in DDS physical file:

    • Suppose EMPLOYEE File is a Reference file and DDS is as follows.
    • Let’s create a file ACCOUNT2 that refers to the field description from Reference file EMPLOYEE and from the same file ACCOUNT2 using the REFFLD keyword.
    • Here in the above example field ADDRESS1 is the field defined in ACCOUNT2 file itself.
    • Field ADDRESS2 is referred from field ADDRESS1 in the same DDS ACCOUNT2.
    • Field ADDRESS3 is again referred from the same field ADDRESS1 in the same DDS ACCOUNT2 only the record format name is used along with field name.
    • Field ACC_ID is referred from field EMP_ID in file EMPLOYEE.
    • Field ACC_NAME is referred from field EMP_NAME in file EMPLOYEE.
    • Field FIELD is referred from field ADDRESS1 in the same DDS file ACCOUNT2.

C) Format keyword in Physical File

This record-level keyword is used to specify that this record format is to share the field specifications for a previously defined record format. The name of the record format you are defining must be the name of the previously defined record format.

FORMAT is required when you want to refer to an existing record format.

Syntax:
FORMAT([library-name/] database-file-name)
  • The database-file-name parameter is required. It is the name of the physical or logical file from which the previously defined record format is taken.
  • The library name is optional. If you do not specify the library-name, the library list (*LIBL) in effect at file creation time is used.

The FORMAT keyword is not valid in join logical files, and you cannot specify a join logical file as the parameter value on the FORMAT keyword.

Example:

  • If you want to create a file with the same record format as another PF, you can use the FORMAT keyword below.
  • Below is the DDS for ACCOUNT2 file (LF) having the same record format name ACCOUNTR as the file ACCOUNT.
  • This means that the record format ACCOUNTR will have the same field names and attributes as the record format in the physical file ACCOUNT (mentioned in FORMAT keyword).
  • You do not need to specify the field names and attributes in this LF.
  • If necessary, you can Specify key specifications and select/omit specifications if you want them to be in effect for this file. (They can be the same as or different from the previously defined record format.)
  • Below is the DDS for ACCOUNT having the same record format name ACCOUNTR.
  • Below is the DDS for ACCOUNT2 having the same record format name ACCOUNTR.

How can we help you?

We have hundreds of highly-qualified, experienced experts working in 70+ technologies.

X

Awards and Certifications

company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo
company-logo