处理键控序列中的数据库记录文件
您可以使用键控序列访问路径来更新记录文件。 根据记录中一个或多个关键字段的内容来排列记录。
示例:
以下示例使用键字段 SERIALNUM 更新记录文件 T1520DD3 中的数据。 将使用
_Rupdate() 函数。- 在命令行上,输入:
CRTPF FILE(MYLIB/T1520DD3) SRCFILE(QCPPLE/QADDSSRC)要创建使用以下 DDS 源的物理文件 T1520DD3 :图 1。 T1520DD3 -数据库记录的 DDS 源 A R PURCHASE A ITEMNAME 10 A SERIALNUM 10 A K SERIALNUM - 在 T1520DD3:
orange 1000222200 grape 1000222010 apple 1000222030 cherry 1000222020虽然按所示输入数据,但程序 T1520KSP 按键控顺序访问文件 T1520DD3 。 因此,程序 T1520KSP 按以下顺序读取文件 T1520DD3 :grape 1000222010 cherry 1000222020 apple 1000222030 orange 1000222200 - 在命令行上,输入:
CRTBNDC PGM(MYLIB/T1520KSP) SRCFILE(QCPPLE/QACSRC)这将使用以下源创建程序 T1520KSP: 此程序使用图 2。 T1520KSP -ILE C 用于处理键控序列中的数据库记录文件的源 /* This program illustrates how to update a record in a file using */ /* the _Rupdate() function. */ #include <stdio.h> #include <stdlib.h> #include <recio.h> int main(void) { _RFILE *in; char new_purchase[21] = "PEAR 1002022244"; /* Open the file for processing in keyed sequence. File is created */ /* with the default access path. */ if ( (in = _Ropen("*LIBL/T1520DD3", "rr+")) == NULL ) { printf("Open failed\n"); exit(1); }; /* Update the first record in the keyed sequence. The function */ /* _Rlocate locks the record. */ _Rlocate(in, NULL, 0, __FIRST); _Rupdate(in, new_purchase, 20); /* Force the end of data. */ _Rfeod(in); _Rclose(in); }_Ropen()函数来打开记录文件 T1520DD3。 缺省访问路径 (键控序列访问路径) 用于创建文件 T1520DD3。_Rlocate()函数锁定键控序列中的第一个记录。_Rupdate()函数将_Rlocate()锁定的记录更新为 PEAR 1002022244。 (由于密钥已更改,因此第一条记录将成为键控序列访问路径中的第二条记录。) - 要运行程序 T1520KSP,请输入:
CALL PGM(MYLIB/T1520KSP)因为grape是键控序列中的第一个记录,所以将进行更新,并且数据文件 T1520DD3 如下所示:orange 1000222200 PEAR 1002022244 apple 1000222030 cherry 1000222020