A: When an RPG program opens a file for sequential output, by default the system determines when records are forced to auxiliary storage. For performance reasons, the system seeks to optimize I/O by calculating a blocking factor. After your program has written the number of records in the block (as calculated by the system), the records are forced to auxiliary storage. Once the records are forced to auxiliary storage, they appear in your file.
The system also forces records to auxiliary storage when it closes the file, in case there are still records that have not yet been written based on the blocking factor. When you exit your RPG program with the LR indicator on, you might expect the system to close the file, thereby forcing the records to auxiliary storage. This may or may not be true. If your application shares the file's open data path (ODP), the file is closed only after all the programs sharing the ODP close it (or when the job or activation group ends).
There are several options available for controlling when the system forces records to auxiliary storage. The method you should choose depends on your requirements. The options include the use of
- File attribute FrcRatio (Records to force a write)
- File attribute SeqOnly (Limit to sequential only)
- RPG operation code FEOD (Force end of data)
A file's FrcRatio attribute determines the number of output (i.e., add, update, delete) operations that can occur on records before they're forced to auxiliary storage. The default value, *None, indicates that the system calculates a blocking factor (to optimize performance) and determines when to force records to auxiliary storage.
When you specify an explicit value for this attribute, your program forces records to auxiliary storage when it has performed that number of output operations. To avoid inadvertent performance problems, I strongly advise that you never specify an explicit value for this attribute in the file object itself. Instead, if you must specify a FrcRatio value, you should do so temporarily with command OvrDbF (Override with Database File) in your applications.
Applications rarely specify a value for FrcRatio, and rightfully so. How-ever, if your application requires that each record be available immediately after it's written, you can specify a FrcRatio value of 1 to ensure that it is. Remember, though, that there's a performance penalty in so doing.
You can also use the SeqOnly parameter on command OvrDbF to specify the number of records the system transfers at once. This functions similar to the FrcRatio attribute. As with FrcRatio, you must be careful to avoid performance pitfalls when you use SeqOnly to specify the number of records to process as a group. If you specify a value of 1 for the number of records to process as a group, when your program writes a record, it will be immediately available.
Typically, a program that specifies a file as output-only writes a batch of records sequentially, with no need to access those records until the entire batch is written. In such a case, RPG's FEOD operation code is the answer. FEOD instructs the system to force records to auxiliary storage. After your program writes all records, and before exiting the program, simply code FEOD for the file in question, and your records will be available.