Joining three or more physical files to create Join Logical File in AS400 |
Introduction
In this blog, we will be seeing an example that tells us how to create a Join Logical file (JLF) to join three or more physical files (PF).
You can join as many as 32 physical files (PF) to create a Join Logical File (JLF). We must define these files in the JFILE keyword. The first file specified in the JFILE keyword is the Primary file and all other files are Secondary files. We must join the files in pairs and each pair must be defined with the JOIN keyword and each file being paired must have one or more join fields defined in the JFLD keyword.
Create first physical file PF1
PF1 has 2 fields namely ROLLNO of 10 chars and STUNAME of 15 chars respectively and record format name as RPF1.Use the CRTPF command to create the object for file PF1.
A R RPF1 A ROLLNO 10A A STUNAME 15A
Create second physical file PF2
PF2 has 2 fields namely ROLLNO of 10 chars and CLASS of 2 numeric respectively and record format name as RPF2.Use the CRTPF command to create the object for file PF2.
A R RPF2 A ROLLNO 10A A CLASS 2P 0
Create third physical file PF3
PF3 has 2 fields namely ROLLNO of 10 chars and AGE of 2 numeric respectively and record format name as RPF3.Use the CRTPF command to create the object for file PF3.
A R RPF3 A ROLLNO 10A A AGE 2P 0
Create a Join Logical file (JLF)
JLF1 would have 3 fields namely ROLLNO, STUNAME, and CLASS from files PF1 and PF2, where the ROLLNO field is common in both the physical files PF1 and PF2.
A R RJLF1 JFILE(PF1 PF2 PF3) A J JOIN(PF1 PF2) A JFLD(ROLLNO ROLLNO) A J JOIN(PF2 PF3) A JFLD(ROLLNO ROLLNO) A ROLLNO JREF(PF1) A STUNAME A CLASS A AGE
Data in PF1
ROLLNO STUNAME 1 NAME1 2 NAME2 3 NAME3 5 NAME5 ******** End of data ********
Data in PF2
ROLLNO CLASS 1 1 2 1 4 1 ******** End of data ********
Data in PF3
ROLLNO AGE 1 15 2 16 ******** End of data ********
Data in join logical file (JLF1) - We only get ROLLNO 1 and 2 since ROLLNO 3 and 5 are not present in secondary file PF2 and also ROLLNO 4 is not selected from PF2 since ROLLNO 4 is not present in PF3.
ROLLNO STUNAME CLASS AGE 1 NAME1 1 15 2 NAME2 1 16 ******** End of data ********
R
R denotes the Record format of the join logical file. Here in this example, JLF1 has a record format name as RJLF1.
JFILE(PF1 PF2 PF3)
JFILE keyword accepts parameters as file names. Here you must specify at least two physical files (PF) where the first file is the primary file and the second file is the secondary file. Here, we are joining three files.
J
J denotes the beginning of the Join specification. At least one Join specification must be defined in the Join logical file (JLF). The next J would be on the next line.
JOIN(PF1 PF2)/JOIN(PF2 PF3)
JOIN denotes that which two files will be joined using the JOIN keyword. Let me tell you if only two physical files are joined then this JOIN keyword is optional to use in Join logical file (JLF).
JFLD(ROLLNO ROLLNO)
JFLD keyword denotes join fields that will join rows from the physical files specified on the JOIN keyword.JFLD keyword must be specified at least once for each join keyword. Let me tell you the join fields are those fields that are common to both the physical files. All the fields must be of the same type, the length specified on the JFLD if they are not character types.
Field Name
At least one field name must be specified from the physical file and you can use keywords such as CONCAT, SST, RENAME here.
JREF(PF1)
JREF keyword is used for the field names which must specify that from which files this field is referred from in Join logical file (JLF). Here, in this example, ROLLNO fields are present in both the files PF1 and PF2 and JLF must know in advance that from where the field comes from.
K
Please note that in this example PF1 and PF2 do not have key fields. So Join logical file (JLF) is an arrival sequence file in this case, but in case we have defined any key fields then the Join logical file would be an indexed file(keyed sequence).
Note and Warning
Click the below button to navigate to the Note and Warning page
Notes and WarningPoints to remember
Click the below button to navigate to the Points to remember page
Points to rememberRelated Post
- Logical file in AS400
- Non-Join Logical file in AS400
- Join Logical file in AS400
- Join two physical files to create Join logical file in AS400
- Join more than one physical file field to create Join logical file in AS400
- Use JDUPSEQ keyword to arrange duplicate records in secondary file in join logical file in AS400
- Join fields with different attributes to create a Join logical file in AS400
- Fields that never appear in Record format in Join Logical File in AS400
- Specify the key fields in the Join Logical File in AS400
- Joining physical file to itself in Join Logical File in AS400
- Select and Omit criteria in Logical file in AS400