Data editing > Using subroutines in the edit > Subroutines in the Quantum library > Using look-up files > The fetch statement
 
The fetch statement
To transfer data from the look-up file to the record in the C array, enter the fetch statement in your edit at the point at which data is to be copied. Fetch is a C routine
Syntax
call fetch($file_name$,key_col,put_col)
file_name
The name of the look-up file.
key_col
The start column of the key in the record.
put_col
The start column of the field into which the data is to be copied.
More information
Data copied from a look-up file does not retain its key at the beginning. If you look at the example in the previous section, the data transferred for records with key 1 will be $ 14$.
Suppose, in the chocolate survey, that the first brand bought is stored in c135, the second in c150 and the third in c165. Brands are coded 1 through 4 as noted above, and costs are to be copied into fields starting in columns 136, 151 and 166 respectively. To deal with all three purchases, you call fetch three times, once for each purchase. For the first purchase, write:
call fetch($costs$,c135,c136)
When the first record is read, Quantum inspects c135 and compares its contents with the first field of the look-up file. If c135’1’ (brand A was bought) and a matching key is found in costs, the information associated with that key is copied into the C array starting at c136. In the example, brand A chocolate bars cost 14 pence so c(136,138) contains $ 14$. If a matching key cannot be found in costs, the destination area c(136,138) will be blanked out.
Calls for the second and third purchases would be entered as:
call fetch($costs$,c150,c151)
call fetch($costs$,c165,c166)
When you read additional data in from fetch files, Quantum writes a summary of what it has done to the file out2. The format of the report is as shown here:
Records Used Unused Calls Hits Misses File
7 5 2 893 869 24 cost1
3 3 0 196 196 0 cost2
This tells you that the run used two fetch files. The first file, cost1, contained seven keys; five were present in the data and two were not. The file was called 893 times altogether and 869 times the key in the data was found in the fetch file. The 24 misses refer to keys that were present in the data but not in cost1.
The second file was called cost2 and contained three keys all of which were present in the data. The file was called 196 times and every time the key in the data was found in the cost2.
Nine digits are allowed for each column making the maximum count in a column 999,999,999.
See also
Using look-up files