Consider, you have a physical file called MYPF that has 3 members: M1, M2, M3. To access the data contained in a particular member, say M2 of this physical file, we generally use OVRDBF (override database file) command in a CL program. After this OVRDBF command we call a RPG program say MYPGM, which does processing with the data of that particular member, i.e. M2. A small sample CL program could be written as below:
OVRDBF FILE(MYPF) TOFILE(SYNGRAP/MYPF) MBR(M2)
There is an alternative way to do this.
You can access the data contained in a member M2 of this physical file MYPF without using OVRDBF command also. All what you need to do is to create a logical file say MYLF based on the physical file MYPF. The record format name of logical file should be same as the physical file. You can change the key order in logical file or keep the same key order as defined in physical file. It's up to you as per your requirements.
In addition to the required parameters, while creating the logical file MYLF, you have to take care of one more parameter. On CRTLF command, there is a parameter called DTAMBRS. In this parameter you have to fill three fields, which are Physical file, Library, Members. By default, the field of Physical file will have *ALL in it. It means that by default, logical file refers to all the members of a physical file. The default value of other two fields Library, Members is blank.
You have to fill these three fields:
1. In the field for physical file, enter the name of the physical file, i.e MYPF on which you are making this logical file.
2. In the field for Library, enter the library name where physical file MYPF resides.
3. In the field for Members, enter the name of the member, i.e. M2 whose data you want to access by means of this logical file. Now, use this logical file MYLF (instead of physical file MYPF) in your RPG program and you'll see that you can access the data of member M2.
What you have done is create a logical file that points to a particular member M2 of physical file MYPF. You have done this by means of DTAMBRS parameter as described above.
Isn't it simple?
MORE INFORMATION ON THIS TOPIC
The Best Web Links: tips, tutorials and more.
Ask your programming questions--or help out your peers by answering them--in our live discussion forums.
Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.