Updating a file random acess in
In some situations, the programs require to access a particular record immediately.
The API consists of a few, easy to use, methods: giving you access to more advanced features, such as mapping a region of the file directly into memory for faster access, locking a region of the file, or reading and writing bytes from an absolute location without affecting the channel's current position.
The following code snippet opens a file for both reading and writing by using one of the .
permit nonsequential, or random, access to a file's contents.
To access a file randomly, you open the file, seek a particular location, and read from or write to that file.
You can also plan for an invalid key condition on the first attempt to find a record with a specified key value that is not present in the file.
You can, as shown in Example 7-2, read through an indexed file for all records with a specific duplicate key and produce a report from the information in those records.
IF END-OF-FILE NOT = "Y" AND DELETE-KEY = ICE-CREAM-STORE-STATE PERFORM A300-DELETE-MASTER. The invalid key condition, although fatal if not planned for, can be to your advantage when used properly. PERFORM A500-READ-DUPLICATES UNTIL ANY-MORE-DUPLICATES = "N". The relative and indexed file processing statements that allow you to do this within the INVALID KEY phrase are DELETE, READ, REWRITE, START, and WRITE (that is, all the record I-O verbs except READ NEXT).
IF END-OF-FILE NOT = "Y" AND REWRITE-KEY = ICE-CREAM-STORE-CODE PERFORM A200-REWRITE-MASTER. REWRITE ICE-CREAM-MASTER INVALID KEY DISPLAY "Bad rewrite - ABORTED" STOP RUN. If the primary or alternate key you specify allows duplicates, only the first occurrence of a record with a matching value will be updated. This condition is fatal to the program, if the program does not check for the condition when it occurs and if no applicable Declarative USE procedure exists (see Section 7.4). Your program has two options: Build an error recovery routine into the statement.
Random-access file is used in instant access systems such as banking system, sale system, air-line reservation system…etc.Tags: Adult Dating, affair dating, sex dating