使用子文件来最小化 I/O 操作
您可以使用子文件在一个操作中读取或写入显示中的大量记录。
示例:
以下子文件示例使用来自 T1520DDG 和 T1520DDH 的 DDS 来显示名称和电话号码的列表。
- 要使用下面显示的 DDS 源创建显示文件 T1520DDG ,请输入:
CRTDSPF FILE(MYLIB/T1520DDG) SRCFILE(QCPPLE/QADDSSRC)图 1。 T1520DDG -子文件显示的 DDS 源 A DSPSIZ(24 80 *DS3) A R SFL SFL A NAME 10A B 10 25 A PHONE 10A B +5 A R SFLCTL SFLCTL(SFL) A SFLPAG(5) A SFLSIZ(26) A SFLDSP A SFLDSPCTL A 22 25'<PAGE DOWN> FOR NEXT PAGE' A 23 25'<PAGE UP> FOR PREVIOUS PAGE' - 要使用下面显示的 DDS 源创建物理文件 T1520DDH ,请输入:
CRTPF FILE(MYLIB/T1520DDH) SRCFILE(QCPPLE/QADDSSRC)R ENTRY NAME 10A PHONE 10A - 在 T1520DDH:
David 435-5634 Florence 343-4537 Irene 255-5235 Carrie 747-5347 Michele 634-4557 - 要使用下面显示的源创建程序 T1520SUB ,请输入:
CRTBNDC PGM(MYLIB/T1520SUB) SRCFILE(QCPPLE/QACSRC)/* This program illustrates how to use subfiles. */ #include <stdio.h> #include <stdlib.h> #include <recio.h> #define LEN 10 #define NUM_RECS 20 #define SUBFILENAME "*LIBL/T1520DDG" #define PFILENAME "*LIBL/T1520DDH" typedef struct{ char name[LEN]; char phone[LEN]; }pf_t; #define RECLEN sizeof(pf_t) void init_subfile(_RFILE *, _RFILE *); int main(void) { _RFILE *pf; _RFILE *subf; /* Open the subfile and the physical file. */ if ((pf = _Ropen(PFILENAME, "rr")) == NULL) { printf("can't open file %s\n", PFILENAME); exit(1); } if ((subf = _Ropen(SUBFILENAME, "ar+")) == NULL) { printf("can't open file %s\n", SUBFILENAME); exit(2); } /* Initialize the subfile with records from the physical file. */ init_subfile(pf, subf);/* Write the subfile to the display by writing a record to the */ /* subfile control format. */ _Rformat(subf, "SFLCTL"); _Rwrite(subf, "", 0); _Rreadn(subf, "", 0, __DFT); /* Close the physical file and the subfile. */ _Rclose(pf); _Rclose(subf); } void init_subfile(_RFILE *pf, _RFILE *subf) { _RIOFB_T *fb; int i; pf_t record; /* Select the subfile record format. */ _Rformat(subf, "SFL"); for (i = 1; i <= NUM_RECS; i++) { fb = _Rreadn(pf, &record, RECLEN, __DFT); if (fb->num_bytes != EOF) { fb = _Rwrited(subf, &record, RECLEN, i); if (fb->num_bytes != RECLEN) { printf("error occurred during write\n"); exit(3); } } } }此程序使用
_Ropen()来打开子文件 T1520DDG 和物理文件 T1520DDH。 然后,使用物理文件中的记录对子文件进行初始化。 使用_Rwrited()函数将子文件记录写入屏幕。 - 要运行程序 T1520SUB 并查看输出,请输入:
CALL PGM(MYLIB/T1520SUB)David 435-5634 Florence 343-4537 Irene 255-5235 Carrie 747-5347 Michele 643-4557 <PAGE DOWN> FOR NEXT PAGE <PAGE UP> FOR PREVIOUS PAGE