Merging a field of data from an external file
Quick reference
To merge extra data from an external data file into the data currently in the C array, type:
int_variable=mergedata($ex_file$, key_field, key_start, copy_to, data_start)
where:
int_variable
The name of an integer variable in which the function can place its return value.
ex_file
The name of the file containing the extra data. It must be enclosed in dollar signs.
key_field
The location of the key in the main data file, entered using the standard Quantum notation for columns and fields.
key_start
The start column of the key in the external data file, for example, 1 if the key starts in column 1. The length of the key is taken from the length of key_field
copy_to
The field in the main data record in which to place the external data. The field is defined using the standard Quantum notation for columns and fields.
data_start
The start column of the data to be copied. Quantum copies as many columns as are defined by copy_to.
This statement returns 1 in int_variable if a match is found, 0 if no match is found.
More information
The mergedata statement merges a field of data from an external file with the main data at the datapass stage of the Quantum run. Merging is by means of a data key present in both the main records and the records in the external file. If a record in the external file has a key which matches that of a record in the main data file, the external data will be merged into a user-defined field of the main record when it is read into the C array.
For data to be merged correctly, both the main data file and the external file must be sorted in ascending order by key value. If the key is the record serial number, the data file is already sorted in the correct order (assuming, of course, that the data is sorted by serial number). If you are using a key that is not the record serial number, you must sort the data file so that it is ordered by key rather than by serial number.
There is no limit on the number of mergedata statements in a specification, but you can merge data from a maximum of 9 different files per record.
Example
t1 = mergedata($manuf_codes$,c(178,180),15,c(168,175),1)
tells Quantum to compare the key in columns 178 to 180 of the main record with the key which starts in column 15 of the external records in the file manuf_codes.
Because the key field in the main record is 3 columns long, Quantum reads columns 15 to 17 of each external record to obtain its key. If the keys match, Quantum copies the data from the external record into columns 168 to 175 of the main record in the C array. The external data to be copied starts in column 1 and, since the destination field is 8 columns long, Quantum copies 8 columns starting at that column.
This statement returns a value of 1 if a match was found (that is, merging took place), or 0 if not.
See
See also