TABLE.IMPORT Function

Syntax

V Import()

Description

Import records from specified input file to the table.

Discussion

Specify the required values in the Import dot variable, then use the following command:

import.type

Type: N ---- You use the Import Type Codes to specify the file format of the source file:

Export Format Type Code
Details
FILE_FORMAT_ASCII

Number: 0, Extension: .ASC, Character-Separated ASCII

FILE_FORMAT_TABLE_ASCII

Number: 1, Extension: .TBL, Table ASCII

FILE_FORMAT_RICH_TEXT

Number: 2, Extension: .RTF, Rich Text Format (RTF)

FILE_FORMAT_EXCEL_VERSION_3

Number: 3, Extension: .XLS, Microsoft Excel, Version 3.0

FILE_FORMAT_EXCEL_VERSION_

Number: 4, Extension: .XLS, Microsoft Excel, Version 4.0

FILE_FORMAT_123_VERSION_1

Number: 5, Extension: .WKS, Lotus 1-2-3, Version 1.0/1A

FILE_FORMAT_123_VERSION_2

Number: 6, Extension: .WK1, Lotus 1-2-3, Version 2.0

FILE_FORMAT_123_VERSION_3

Number: 7, Extension: .WK3, Lotus 1-2-3, Version 3.0

FILE_FORMAT_SYMPHONY_VERSION_1

Number: 8, Extension: .WRK, Lotus Symphony, Version 1.0

FILE_FORMAT_SYMPHONY_VERSION_2

Number: 9, Extension: .WR1, Lotus Symphony, Version 2.0

import.names

Type C ---- Optional. Default = NONE. The data in the source file is often preceded by the field names. If the file does have field names, you can specify one of the following options:

"USE" = use field names
"IGNORE" = ignore field names
import.file

Type: C ---- The name of the file to be imported.

import.db

Type: C ---- The name you assign for the resulting table file.

import.skip_lines

Type: N ---- Optional. Default = 0. For ASCII-import and damaged table files to set the number of lines at the beginning of the source file that should be ignored.

import.skip_bytes

Type: N ---- Optional. Default = 0. For ASCII-import and damaged table files to set the number of bytes at the beginning of the source file that should be ignored.

import.field_sep, import.rec_sep

Type: C ---- Define how the end of fields and records are denoted in the source file. These strings can include any characters, including the following special separator characters:

Separator
Description
<CR> <LF>

Carriage return and line feed combination

<CR>

Carriage return

<LF>

Line feed

<ESC>

Escape Escape

<TAB>

Tab

import.record_len

Type: C ---- Specifies the character length (including spaces and carriage returns) of one record in a source file that is in ASCII table format.

import.rem_blanks

Type: L ---- Specifies whether or not leading blanks should be imported along with the data.

.T. (TRUE) = Import leading blanks
.F. (FALSE) = Do not import leading blanks
import.text_qualifier

Type: C ---- Specify the character in which fields in a character-separated file are enclosed. The import.text_qualifier parameter is used to specify the character in which fields in a character-separated file are enclosed. For example, if your import file looks like this: "Alpha Software","168 Middlesex Tpke","01803" you would specify " \" " as the Text Qualifier. (NOTE: The quote qualifier is prefixed with a \ to distinguish it from the enclosing quotes.) If the import file looks like this: 'Alpha Software','168 Middlesex Tpke','01803' you would specify "'" as the Text Qualifier. (A single quote between double quotes.) If the text is not enclosed in qualifiers, then specify a NULL string (e.g., "").

import.fields

Type: N ---- Specifies how many fields are to be imported.

import.field1 ... import.fieldN

Type: C ---- Specify the field name, type, offset, width, and decimal values in a comma delimited string for each of the field(s) to be imported. Refer to the example below for the format. In the case of a table ASCII file, the offset is the starting position of the field. In the case of all other files, the offset if the field number. The field number starts with 0. i.e., for import.field1, the offset is 0.

The TABLE.IMPORT() method is a high-level utility function you use to import the records of a file of a different format into a new table file. Most parameters passed to import through the Import function variable correspond directly with the prompts and options appearing on the Import Builder.

Example

This script imports a character separated ASCII file into the desired table.

filename = ui_get_file("File To Import","ASCII(*.asc)",
"c:\a5\a_sports\customer.asc","X")
choice = ui_get_radio("Field Name Status",1,"use","ignore","none")
import.type = 0
import.names = choice
import.file = filename
import.db = "c:\a5\a_sports\cust_new.dbf"
import.skip_lines = 0
import.skip_bytes = 0
import.field_sep = ","
import.record_sep = "<CR><LF>"
import.record_len = 0
import.rem_blanks = .T.
import.text_qualifier = ""
import.fields = 5
import.field1 = "cust_id,c,0,8,0"
import.field2 = "salutation,c,1,11,0"
import.field3 = "first_name,c,2,19,0"
import.field4 = "last_name,c,3,19,0"
import.field5 = "home_phone,c,4,15,0"
Table.import()

See Also