What is the Difference between Physical and Logical Files?

What is the IBM i Database?

The IBM i System has a database which stores data.

The database is broken down into libraries, which contain main files.

Think of this as a bookshelf that contains many books. The same book could be on different bookshelves. On one shelf the book may have been annotated by the author or read and on the other it might not. So the same book can contain different data, on different book shelves.

The same rules apply to Library -  files might exist in both, with the same names but have different data in them.

These are called physical files.

The Physical file stores the actual data.

The data is written to a physical file in arrival sequence. This data can be accessed by RRN (relative record number) where the first entry on the file (also known as a table) is relative record number 1. ie: the first record in the file. The next record is RRN=2 then RRN3 and so on.

If you want to access the data using a sequence of something on the file (for example CUSTOMER sequence) then you would design and create a logical view of this physical file specifying that you want it sequenced by customer.

A Logical File is a sequenced VIEW of the data in the Physical File.

Logicals can be used for updating, creating and deleting data within the physical that it is scoped over.

A logical file is a view of the physical file - perhaps sequenced in a certain way.

Think of a customer master file - one logical may sequence that data by customer name, while another logical file might sequence it by address. If you read logical file, you are reading the same physical data but just sequenced in different way. 

We call this sequencing a KEY for the data. For example, the logical CUSNAMES is over the CUSTOMER File but keyed by NAMES

Join Logicals – are a form of logical file selecting and sequencing data from more than one physical. I

physical and logical files on ibm i

You can add a KEY (the keyed sequence field used in a logical) to a physical file itself. This is OK, but most application designers leave the physical file with no key, so you can read it in arrival FIFO (first In First Out) sequence. A new logical will be added for each new sequenced view as it is required.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}