![]() |
- IR |Insert records from another file
n records from the specified reference file are copied to the current Display file.
n Number of records to be copied. Standard: n = 1.
The character '$' instead of a number n indicates the highest possible number 99999
file Reference file from which the records should be copied. This file can be either SAM or ISAM format.
Standard: If file is not specified, the last reference file used is accessed.
params W | NW | K | KN | NK | B
or a combination of these values, separated by commas.
W Wrap. When the end of the reference file is reached, the internal pointer is reset to the beginning of the file. In this way, records from the reference file can be repeated in the Display file.
NW No Wrap. After reaching the end of the reference file, the internal pointer remains there. No additional records are copied to the Display file. The pointer can be reset to the beginning of the reference file with the B parameter (see below).
Standard: NW.
K Keys. This parameter may only be specified for a reference file with FCBTYPE= ISAM. CFS will insert the records from the reference file in the Display file according to their original key values (seeded insertion).
In K mode, records from the reference file with identical keys will overwrite those of the Display file.
A previously activated DUPK command in K mode will allow records from the reference file with identical keys to those in the Display file to be inserted (not overwritten). It is therefore possible to create records with identical ISAM keys in the Display file.
KN Keys No overwrite. Same function as K (see above), except that records from the reference file with identical keys to those in the Display file are not overwritten.
NK No Keys. The original ISAM keys from the reference file are not included in the insertion. The reference file will be treated as a sequential file. The records from the reference file will be inserted between the first and the second records currently displayed. New ISAM keys will be generated by CFS.
Standard: NK.
B Beginning. The reference file is read from the beginning again. This option should be used if the error message "EOF on source-file" is encountered.
Notes:
The IR command is the counterpart to the W command, or the Search command with Rewrite (S...=W...). Using the Write command, records in a particular format from a Display file may be written to an output file. After some additional processing of these records in the Write file, the IR command can be used to copy them back to the original file.
If both the Display and the IR files are ISAM files, then the KEYPOS and KEYLEN of both files must correspond.
When the end of the reference file is reached, the internal pointer remains there. The reference file will be re-read from the beginning by specifying IR [n],,B.
Leaving the Display mode does not close the reference file. Closing the reference file explicitly can be achieved by issuing a new IR command and specifying a non-existent file (e.g. *DUMMY).
Examples:
IR 9999,CFS.FIL1
A maximum of 9999 records from the file CFS.FIL1 are inserted between the first record displayed and the second. A restriction is that only so many records will be inserted as allowed by the number of free keys between the first and second records. If need be the insertion process is aborted with a DUPKEY error message.
IR 20,CFS.DAT2,W
Assuming that the reference file CFS.DAT2 contains only one record, then the above command will insert this record 20 times between the first and the second record being displayed.
IR 999,CFS.DAT3,K
It is assumed that the reference file CFS.DAT3 and the Display file are ISAM files with the same file format. As many records as appear in the file CFS.DAT3 will be transfered, with keys, up a a maximum of 999 (K option). If the file already contains records with these keys, then these records will be overwritten (only if NDUPK mode of CFS is switched on).
Merging of two sequential files.
In the output file, record 1 of file 1 should be followed by record 2 of file 2, and so on.
ONXCONV' '='.ISAM',FCBTYPE=ISAM,IK (IK: Insert Keys)
The sequential files 1 and 2 are first converted into ISAM files using the ONXCONV Variable Action.
Enter M as an Action Code for the first ISAM file (File-1). Set DUPKEY mode on with the DUPK command.
IR 9999,file-2,K
Records from the second ISAM file will be inserted into the first file according to the respective key positions.
ONXCONV'.ISAM'='.SAM',FCBTYPE=SAM,EK
Terminate the display of file 1 with K1 and convert it back to a sequential file. The ISAM keys will be deleted (EK).
A string 'ABC' in the keys should be replaced by 'XYZ' in an ISAM file with KEYPOS=10 and KEYLEN=20. The resulting records will be sequenced according to their new keys. This can be achieved as described below.
S9999,:6-13:'ABC'=W CFS.DAT3
S9999,:6-13:'ABC'=D
ONXCONV' '='.SAM',FCBTYP=SAM
S9999,:6-13:'ABC'='XYZ'
ONXCONV'.SAM'='',FCBTYP=ISAM,KEYPOS=10,KEYLEN=20
IR9999,CFS.DAT3,K
All records from a Display file containing the string 'ABC' will be transfered to the file CFS.DAT3. These records must them be deleted from the Display file, since they will be re-inserted into the file as a last step, but with different keys, and at different positions.
The file CFS.DAT3 can be processed separately. Keys may not be amended using Search and Replace in CFS Editor, since it is an ISAM file. This is only possible if the ISAM file is converted to a temporary sequential file, CFS.DAT3.SAM, and the ISAM key is then amended as normal data with Search and Replace. The sequential file is then converted back to an ISAM file with its original format. Bringing the file CFS.DAT3 into the original Display file is achieved with the command IR 9999,CFS.DAT3,K.