Flat file concepts

When I was writing articles on Data structures, I had also planned to write one article on Flat file processing on AS400 system. This is because Flat files and RPG Data structures go together.

However, due to some circumstances which I could well have avoided, I could not complete that thing. They say it’s never too late to begin, so here it is. But, before I delve into processing of flat files on AS400 system (Actually in RPG IV) I think, it would be better if I could write something about its concept.


What is a flat file? Ever heard of Flat file databases?
According to wikipedia, Mr. Herman Hollerith was the first person to conceptualize flat file databases way back in 1889. Since then flat has acquired several forms, so much so that now a days I do not hear anybody using flat file for the purpose it was actually meant for i.e. to act as database, to permanently store and process data.

Flat files are generally column less files (tables). All different columns are packed together in each row. To distinguish two columns, several ways are adopted. We can broadly define them into two methods.

  1. Using a delimiter.In this case whenever a column data ends, a specific, predetermined character is inserted. This delimiter could be any character e.g. comma (,), Spaces ( ), period (.) etc. It is up to the person storing data, to choose which delimiter he/she wants.
  2. Using fixed length.In AS400, we find this method to distinguish columns. Here, instead of using any ‘delimiter’ to mark end of one type of data, columns are assumed to be of fixed width (say 10 character long). All columns could have same or different column widths. Even if the data of a specific column ends well before the assigned length, next columns data starts at its fixed position only.

  3. Examples of flat file data storage.
    In the examples below, we can have a feel of how data is actually stored in the flat files.
    Using Delimiter comma.
    Maria,Sharapova,Female,23
    Brad,Pitt,Male,Male,44

    Using Fixed width

    
    1 ...+... 2 ...+... 3 ...+..
    Maria     Sharapova Female23
    Brad      Pitt      Male  44

    In the second example length of first names have been allocated 10 characters. Even if the first name occupies 5 characters, Last name begins only from the 11th place. Also, unlike the first example where the length of each record may vary, record length in the second case is fixed (which equals sum of lengths of individual columns.)To better understand how delimiter works, you may paste the data in example into an Excel worksheet. Now, you can change the data format from the data option given on the top.


    How flat files are used in AS400 system?
    I think flat files are generally used to transfer data from one system to another etc. This is because each system has its own way to store and process data. Flat file seems to fit in every system because, you have to pass data in specific order only. You do not need to define structure( Data type) or columns etc.


    Is there any alternative of flat file?
    Yes, XML has been invented for exactly the same purpose for what flat files are being used. i.e. to pass data from one system to another. With XML you do not need to worry about anything. The data file will contain enough information in standard format so that every system can understand it. Though AS400 system supports XML, it is still to get penetration into AS400 systems.

    That is all in this part of article. We will learn more about flat files on AS400 machine and actually process flat files using RPG IV in incoming pages.