Field Reference file in AS400

Field Reference file in AS400
Field Reference file in AS400,REF and REFFLD keywords in PF in IBMi AS400,REF keyword,reffld keyword in PF,REF keyword in pf,reffld keyword in pf,syntax for ref in pf as400,syntax for reffld in pf in as400,usage of REF and REFFLD in IBMi AS400,usage of ref and reffld in ibmi as400,ref and reffld keywords in pf in ibmi as400,as400 and sql tricks,ibmi,as400,as400 tutorial,reffld keyword in as400,as400 basic introduction,as400 training,create pf in as400 for beginenrs
Field Reference file in AS400

Introduction

A Field Reference file or simply a Reference file in AS400 is a physical file that does not contain any data and keeps only field descriptions i.e its data type, length, and CCSID information, etc.

DDS keywords REF and REFFLD allow us to refer to a field description in an exiting file.

Using REF(Reference) keyword in Physical File

REF keyword is a file-level keyword in DDS physical files and this can be used to specify files from where the field descriptions are to be retrieved in the current DDS PF.

  • REF keyword with Library name(optional)and Filename and Record format name(optional)

REF(LibraryName/FileName RecordFormatName)

  • REF keyword with File name

REF(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.

Warning!
So basically, you can use the REF keyword when all the referred fields are from the same file because you can define it only once in the DDS PF.

Warning!
You must specify the record format name if there is more than one record format in the file.

Example of using REF keyword in DDS PF

  • Suppose FILE1 is a Reference file and DDS is as follows


A          R FILE1R               
A            ID             5A    
A            NAME          10A    
A            ID2            5P 0  
A          K ID

  • Let's create a file FILE2 that refers to the field description from Reference file FILE1 using the REF keyword


A                                      REF(FILE1)
A          R FILE2R                                 
A            ID        R                            
A            NAME      R                            
A            ID2       R                            
A          K ID                                     

  • The above DDS code can be written as below as well


A                                      REF(EASYCLASS1/FILE1 FILE1R)
A          R FILE2R                                 
A            ID        R                            
A            NAME      R                            
A            ID2       R                            
A          K ID                                     

So, all the fields in FILE2 have the same field attributes as defined in FILE1 after using the REF keyword.

Using REFFLD(Referenced Field) keyword in Physical File

REFFLD keyword is a field-level keyword in DDS Physical files and this can be used to refer to field descriptions either from one file or multiple files.

  • 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)

  • REFFLD with Referenced Field Name and *SRC when referring to the same DDS file field

REFFLD(ReferenceFieldName *SRC)
When the Referenced field name is from same DDS file then you may use *SRC instead of File name.
  • *SRC is the default value when you do not specify Library name and File name.

Example of using REFFLD keyword in DDS PF

  • Suppose FILE1 is a Reference file and DDS is as follows


A          R FILE1R               
A            ID             5A    
A            NAME          10A    
A            ID2            5P 0  
A          K ID

  • Let's create a file FILE2 that refers to the field description from Reference file FILE1 and from the same file FILE2 using the REFFLD keyword


A          R FILE2R                                 
A            FLAG1          5A    
A            FLAG2     R               REFFLD(FLAG1)
A            FLAG3     R               REFFLD(FILE2R/FLAG1)
A            ID        R               REFFLD(ID FILE1)             
A            NAME      R               REFFLD(NAME EASYCLASS1/FILE1)              
A            ID2       R               REFFLD(FILE1R/ID2 EASYCLASS1/FILE1)
A            FLD       R               REFFLD(FLAG1 *SRC)
A          K ID                                     

  • Here in the above example field FLAG1 is the field defined in FILE2 itself
  • Field FLAG2 is referred from field FLAG1 in the same DDS FILE2
  • Field FLAG3 is again referred from the same field FLAG1 in the same DDS FILE2
  • Field ID is referred from field ID in file FILE1
  • Field NAME is referred from field NAME in file FILE1
  • Field ID2 is referred from field ID2 in file FILE1
  • Field FLD is referred from field FLAG1 in the same DDS file FILE2

Finally, CRTPF command is used to create the Field Reference File

Did you find the information listed in this article helpful? If you enjoyed this article, share it with your friends and colleagues!

Thanks!

Related Post

Physical file in AS400
Multimember physical file in AS400
Logical file in AS400

Post a Comment

© AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain