Creating a Logical File or Index
Page 1 of 1
Creating a Logical File or Index
A logical file provides a different view of a physical file. The most common and simplest use of logical files is to change the order of the data. To define a logical file, you use the DDS specifications. You must start the Programming Development Manager and create a member with TYPE of LF (for logical file). Usually, this goes in the object QDDSSRC.
Here is how to make a logical file named CUS01 which orders the CUS physical file by name. For simple logical files like this, the first line defines the record name of the physical file that has the data. This line also has the PFILE function that names the physical file. Then, add a K definition for each key file.
A R CUSREC PFILE(CUS01)
A*
A K NAME
Name the member in QDDSRC the same as the desired file. In this case, I named it CUS01.
Then, you must compile or create the file. In PDM you can do this with the option 14. When you use option 14, you actually execute the command:
CRTLF FILE(MYLIB/CUS01) SRCFILE(MYLIB/QDDSSRC) SRCMBR(CUS01)
The AS/400 knows to use this command because you specified that this member is describing a LF.
Add a SELECT spec to select only customers with STATUS of 'A'
A R CUSREC PFILE(CUS01)
A*
A K NAME
A S STATUS COMP(EQ 'A')
Or to omit records with a STATUS of 'D'
A R CUSREC PFILE(CUS01)
A*
A K NAME
A O STATUS COMP(EQ 'D')
An RPG program uses logical files almost identically to physical files.
Here is how to make a logical file named CUS01 which orders the CUS physical file by name. For simple logical files like this, the first line defines the record name of the physical file that has the data. This line also has the PFILE function that names the physical file. Then, add a K definition for each key file.
A R CUSREC PFILE(CUS01)
A*
A K NAME
Name the member in QDDSRC the same as the desired file. In this case, I named it CUS01.
Then, you must compile or create the file. In PDM you can do this with the option 14. When you use option 14, you actually execute the command:
CRTLF FILE(MYLIB/CUS01) SRCFILE(MYLIB/QDDSSRC) SRCMBR(CUS01)
The AS/400 knows to use this command because you specified that this member is describing a LF.
Add a SELECT spec to select only customers with STATUS of 'A'
A R CUSREC PFILE(CUS01)
A*
A K NAME
A S STATUS COMP(EQ 'A')
Or to omit records with a STATUS of 'D'
A R CUSREC PFILE(CUS01)
A*
A K NAME
A O STATUS COMP(EQ 'D')
An RPG program uses logical files almost identically to physical files.
sivakumar- Posts : 174
Join date : 2009-07-27
Age : 37
Location : Chennai
Similar topics
» Creating a Logical File or Index
» What are the reasons a logical file may be "dropped" during the File definition load process?
» Do the multi format logical file need to have same key field attributes for each record format? what is the significance of K *None in such Logical files?
» Phyical File & Logical File.
» Physical File & Logical File
» What are the reasons a logical file may be "dropped" during the File definition load process?
» Do the multi format logical file need to have same key field attributes for each record format? what is the significance of K *None in such Logical files?
» Phyical File & Logical File.
» Physical File & Logical File
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum