Introduction to subfiles

Introduction to subfiles

Basically subfiles are display-file-concept. Whenever we have to display some tabular data we have two options

  • Define as many required fields
  • Here, We can define as many fields as we wish to display at a time. For example if we have to display 15 sets of customer number, customer name at a time, total 30 fields need to be defined. Each field with unique name so the names of fields of screen would typically be $CusNam1, $CusName2....$CusName15. Similarly the customer numbers.

    This much is fine, we can handle it very easily. But what if the number of rows the table is too large say 1500 instead of 15. In that situation the programming will become a mess!.

  • Use Subfiles
  • Subfiles in a sense are display physical file, with several limitations. However, subfiles do free you up from defining innumerable fields. In the case discussed above, you need to define only two fields $CusName and $CusNo. That's all. Few of the limitations of subfiles as compared to physical files are as under

    • Subfiles are not objects. They are not files where you store data permanently.
    • A maximum 9999 records can be written to a subfile at a time.
    • A subfile can be used to store data only during runtime. You end the program you clear the subfile data.
    • Several PF opcodes will not work with subfiles. Only READC and CHAIN and UPDATE are allowed opcodes.
    • Subfiles can be CHAINed using record numbers only.
    • You can not DELETE any subfile record. You can only UPDATE it. You you need to remove it from subfile, you have clear the subfile and reload all the records minus the delete record.

    Some points in the above discussion might seem foreing to you. But do not mind you will learn each of them when you read the EDITABLE subfiles.

    Anyway this much is good for starting!


    How subfiles are handled in ILE RPG IV

    Subfiles processing in ILE RPG IV is a two step process.

    1. Loading the subfile: First of all a subfile needs to be loaded before it can be further used in an ILE RPG IV program. By loading we mean adding records to subfile by explicitly WRITEing to the subfile. (There are certain conditions where you can achieve writing in some other way by using SFLINZ keyword.)
    2. Displaying the subfile: Once a subfile is loaded with records you are free to use it. The subfile once loaded is ready to be displayed. Display part is important because we have to do lots of work when we process the user inputs. Hence by displaying a subfile we will mean that processing the user inputs. Afterall their's nothing difficult if we would have to just display a subfile! (EXFTM control Format. That's all!)

    Types of subfiles
    Before learning anything else let us learn the types of subfiles. We will learn the subfile concepts of these types one by one.
    1. Load all Subfile: All records (Upto 9999) are loaded into subfiles at a time.
    2. Expandable Subfile: Records, fitting one page in number, are loaded at a time. They are added to the already loaded records of the subfile.
    3. Single Page Subfile: Only that many records are loaded at time which can fit on a sinble page. These records are cleared whenever new records are loaded.