|
Purpose |
Opens an extract file | ||
|
Old name |
#define open_extract extract_open | ||
|
Syntax |
void extract_open(filename, header) | ||
|
Parameters |
char* filename |
Name of file to use in the extract | |
|
|
struct EXT_HEADER* header |
Pointer to extract header structure giving extraction parameters | |
|
Description |
The extract_open() function opens and prepares an extract file using the information in the extract header. The DP4 extract functions are used to sort a collection of records. The parameter header defines a C structure named EXT_HEADER that is used to determine which fields are used, in order of precedence, in a subsequent sort. The fields that make up the structure of an entry in the extract file are equivalent to a database record called EXTRACT. This is generated by LIBMAKE. The struct EXT_HEADER is declared in the file dp4capi.h To perform a sort on selected records from the database, follow the steps below: 1. Construct the header record and the corresponding extract record. Use LIBMAKE to do this automatically by including the #extract directive, as in: #extract <field>, [<field>], … [<field>]; Each <field> corresponds to an entry in the extract file of the same name. By default, the fields are assumed to be database fields. A <field> may include a role, for example address.invoice LIBMAKE determines the datatype, length and occurs value for each field from the database Non-database fields can be included by adding the datatype, length and occurs values after the field name separated by colons, for example address:c:4:16. You can leave out some of these values as there are defaults, so value:n corresponds to a double-precision value. LIBMAKE issues an error message if you attempt to specify a database field with this notation 2. Define the sort required by using the LIBMAKE directive #sorton, as below: #sorton <field>, [<field>], … [<field>]; This gives the list of fields in the extract file on which to sort, in order of precedence, starting with the highest 3. Call the function extract_open() to open an extract file. LIBMAKE normally generates this call in the function init 4. Write records to the extract file by assigning the required fields to the extract record and calling the function extract_write() 5. Call the function extract_sort() to sort the collection of records 6. If the sort is successful, read each of the records in turn by calling the function extract_read() 7. The actual sorting of records is done by the DP4 SORTEXR program which is called by the function extract_sort(). SORTEXR is called when the function trm_run_program() is called with the parameter batch set to FALSE and the copy_screen parameter set to TRUE. You may wish the copy_screen parameter to be FALSE, in which case you should write your own version of extract_sort() as shown in the example below | ||
|
See also |
|||
|
Example |
| ||