You can read and print records from a data file.
Example:
The following example uses the _Ropen(), _Rreadl(), _Rreadp(), _Rreads(), _Rreadd(), _Rreadf(), _Rrlslck(), _Rdelete(), _Ropnfbk(), and _Rclose() record I/O functions. The program T1520REC reads and prints records from the data file T1520DD4.
On the command line, enter:
CRTPF FILE(MYLIB/T1520DD4) SRCFILE(QCPPLE/QADDSSRC)
This creates the physical file T1520DD4 that uses the following DDS:
Figure 131. T1520DD4 -- DDS Source for Database Records
|
orange 1000222200
grape 1000222010
apple 1000222030
cherry 1000222020
CRTBNDC PGM(MYLIB/T1520REC) SRCFILE(QCPPLE/QACSRC).
This creates the program T1520REC that uses the following source:
Figure 132. T1520REC -- ILE C Source to Process a Database File Using Record I/O Functions
|
The _Ropen() function opens the file T1520DD4. The _Ropnfbk() function gets the library name MYLIB and file name T1520DD4. The _Rreadl() function reads the fourth record "cherry 1000222020". The _Rreadp() function reads the third record " apple 1000222030". The _Rrlslck() function releases the lock on this record so that _Rreads() can read it again. The _Rreadd() function reads the second record "grape 1000222010" without locking it. The _Rreadf() function reads the first record "orange 1000222200". The _Rdelete() function deletes the second record. All records are then read and printed.
CALL PGM(MYLIB/T1520REC)
The screen output is as follows:
+--------------------------------------------------------------------------------+ | Library: MYLIB | | File: T1520DD4 | | Fourth record: cherry | | Third record: apple | | Same record: apple | | Second record: grape | | First record: orange | | First record after deletion: orange | | Second record after deletion: apple | | Third record after deletion: cherry | | Press ENTER to end terminal session. | +--------------------------------------------------------------------------------+
The physical file T1520DD4 contains the following data:
ORANGE 1000222200
APPLE 1000222030
CHERRY 1000222020
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.