You can update a record file by using a keyed sequence access path. The records are arranged based on the contents of one or more key fields in the record.
Example:
The following example updates data in the record file T1520DD3 by using the key field SERIALNUM. The _Rupdate() function is used.
CRTPF FILE(MYLIB/T1520DD3) SRCFILE(QCPPLE/QADDSSRC)
To create the physical file T1520DD3 that uses the following DDS source:
Figure 129. T1520DD3 -- DDS Source for Database Records
|
orange 1000222200
grape 1000222010
apple 1000222030
cherry 1000222020
Although you enter the data as shown, the file T1520DD3 is accessed by the program T1520KSP in keyed sequence. Therefore the program T1520KSP reads the file T1520DD3 in the following sequence:
grape 1000222010
cherry 1000222020
apple 1000222030
orange 1000222200
CRTBNDC PGM(MYLIB/T1520KSP) SRCFILE(QCPPLE/QACSRC)
This creates the program T1520KSP, using the following source:
Figure 130. T1520KSP -- ILE C Source to Process a Database Record File in Keyed Sequence
|
This program uses the _Ropen() function to open the record file T1520DD3. The default access path which is the keyed sequence access path is used to create the file T1520DD3. The _Rlocate() function locks the first record in the keyed sequence. The _Rupdate() function updates the record that is locked by _Rlocate() to PEAR 1002022244. (The first record becomes the second record in the keyed sequence access path because the key has changed.)
CALL PGM(MYLIB/T1520KSP)
because grape is the first record in the keyed sequence, it is updated, and the data file T1520DD3 is as follows:
orange 1000222200
PEAR 1002022244
apple 1000222030
cherry 1000222020
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.