软盘文件的记录功能
使用下列记录功能来处理软盘文件:
_Rclose()_Rfeod()_Riofbk()_Ropen()_Ropfbk()_Rreadn()_Rupfb()_Rwrite()
示例:
以下示例显示如何写入软盘文件。
- 要创建软盘文件 T1520DKF,请输入:
CRTDKTF FILE(MYLIB/T1520DKF) DEV(DKT02) LABEL(FILE1) EXCHTYPE(*I) SPOOL(*NO) - Enter键:
CRTPF FILE(MYLIB/T1520DDI) SRCFILE(QCPPLE/QADDSSRC) SHARE(*YES)要使用以下 DDS 源创建物理文件 T1520DDI :A R CUST A NAME 20A A AGE 3B A DENTAL 6B - 在数据库文件 T1520DDI: 中输入以下记录:
Dave Bolt 35 350 Mary Smith 54 444 Mike Tomas 25 545 Alex Michaels 32 512 - 要仅选择在 DENTAL 字段中具有大于 400 的值的记录,请输入:
OPNQRYF FILE((MYLIB/T1520DDI)) QRYSLT('DENTAL *GT 400') OPNSCOPE(*JOB) - 要使用下面显示的源创建程序 T1520DSK ,请输入:
CRTBNDC PGM(MYLIB/T1520DSK) SRCFILE(QCPPLE/QACSRC)图 1。 T1520DSK -ILE C 源将记录写入软盘文件 /* This program illustrates how to write to a diskette file. */ #include <stdio.h> #include <stdlib.h> #include <recio.h> #define BUF_SIZE 30 int main(void) { _RFILE *dktf; _RFILE *dbf; char buf [BUF_SIZE]; /* Open the diskette file */ if (( dktf = _Ropen ( "*LIBL/T1520DKF", "wr blkrcd=y lrecl=100" )) == NULL ) { printf ( "DISKETTE file did not open \n" ); exit ( 1 ); }/* Open the database file. */ if ( ( dbf = _Ropen ( "*LIBL/T1520DDI", "rr") ) == NULL) { printf ( "DATABASE file did not open\n" ); exit ( 2 ); } /* Copy all the database records meeting the OPNQRYF selection */ /* criteria to the diskette file. */ while (( _Rreadn ( dbf, buf, BUF_SIZE,__DFT) ) -> num_bytes != EOF ) { _Rwrite ( dktf, buf, BUF_SIZE ); } _Rclose ( dktf ); _Rclose ( dbf ); }_Ropen()函数打开软盘文件 T1520DKF 和数据库文件 T1520DDI。_Rreadn()函数读取所有数据库记录。_Rwrite()函数将 DENTAL 字段中值大于 400 的所有数据库记录复制到软盘文件 T1520DKF。 - 要运行程序 T1520DSK,请输入:
CALL PGM(MYLIB/T1520DSK)软盘文件的输出如下:Mary Smith 444 Mike Tomas 545 Alex Michaels 512运行程序后,软盘文件仅包含满足选择标准的记录。