Now, Get RPG Codes in all three formats only on this website on every RPGLE related programming article.

Fixed, /Free and Fully Free RPG


Join more than one physical file field to create Join logical file in AS400

Using more than one field to Join the physical files and form a Join logical file in AS400
Join more than one physical file field to create Join logical file in AS400, join logical file, jlf, logical file, lf, as400, ibmi,iseries
Join more than one physical file field 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 more than one physical file field.

Create first physical file PF1

PF1 has 3 fields namely ROLLNO of 10 chars, CLASS of 2 numeric 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            CLASS          2P 0
A            STUNAME       15A        

Create second physical file PF2

PF2 has 3 fields namely ROLLNO of 10 chars and CLASS of 2 numeric and AGE 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 
A            AGE            2P 0

Create a Join Logical file (JLF)

JLF2 would have 4 fields namely ROLLNO, STUNAME, and CLASS and AGE from files PF1 and PF2, where the ROLLNO and CLASS fields are common in both the physical files PF1 and PF2.


A          R RJLF2                     JFILE(PF1 PF2)       
A          J                           JOIN(PF1 PF2)         
A                                      JFLD(ROLLNO ROLLNO) 
A                                      JFLD(CLASS CLASS)  
A            ROLLNO                    JREF(PF1)
A            CLASS                     JREF(PF1)  
A            STUNAME                                         
A            AGE                                               

Data in PF1


ROLLNO      CLASS  STUNAME     
1              1   NAME1       
2              1   NAME2       
********  End of data  ********

Data in PF2


 ROLLNO      CLASS  AGE         
 1              1     5         
 2              1     6         
 ********  End of data  ********

Data in join logical file (JLF2)


 ROLLNO      CLASS  STUNAME          AGE  
 1              1   NAME1              5  
 2              1   NAME2              6  
 ********  End of data  ********            

R

R denotes the Record format of the join logical file. Here in this example, JLF2 has a record format name as RJLF2.

JFILE(PF1 PF2)

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.

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

JFLD(CLASS CLASS)

Joined based on CLASS field in both the physical files PF1 and PF2 as well.

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 Warning

Points to remember

Click the below button to navigate to the Points to remember page

Points to remember

Related Post

Post a Comment

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