Progress
Language Reference


IMPORT Statement

Interfaces
OS
SpeedScript
All
All
Yes

Reads a line from an input file that might have been created by EXPORT.

SYNTAX

IMPORT [ STREAM stream ]
  {    [ DELIMITER character ] { field | ^ } ...
     | [ DELIMITER character ] record [ EXCEPT field  ... ]
     | UNFORMATTED field
  }
  [ NO-ERROR ] 

IMPORT [ STREAM stream ] memptr 

STREAM stream

Specifies the name of a stream. If you do not name a stream, Progress uses the unnamed stream.

DELIMITER character

The character used as a delimiter between field values in the file. The character parameter must be a quoted single character. The default is a space character.

field

The name of a field or variable to which you are importing data. The field or variable must have either the CHARACTER or RAW data type. If the data type is RAW, the IMPORT statement reads enough characters to fill the current length of the variable. If not enough characters are available to fill the current length, the length is reset to the number of characters read.

^

Use a caret (^) to skip a data value in each input line when input is being read from a file.

record

The name of a record buffer. All of the fields in the record are processed exactly as if you had named each of them individually. The record you name must contain at least one field. To use IMPORT with a record in a table defined for multiple databases, qualify the record’s table name with the database name. See the Record Phrase reference entry for more information.

EXCEPT field

Tells Progress to import all the fields except those listed in the EXCEPT phrase.

UNFORMATTED field

Treats each line of the input file as a single string value. In this case, the field parameter must be a single CHARACTER field or variable. You can use this option to read text files one line at a time.

NO-ERROR

Suppresses any errors that occur in the attempt to import the text. After the IMPORT statement completes, you can check the ERROR-STATUS system handle for information on errors that have occurred.

memptr

A variable of data type MEMPTR that contains the imported text. The IMPORT statement my contain a MEMPTR in its field list as long as it is the only field in the list.

EXAMPLES

This procedure takes the data in file customer.d and enters it into the Progress database table customer. The procedure uses the DISABLE TRIGGERS statement to stop Progress from executing any triggers for the CREATE, WRITE, and ASSIGN events when loading the data.

NOTE: The imported files, customer.d and custdump2, in the next two examples are created by running the example programs under EXPORT.

r-imprt.p
INPUT FROM customer.d.

DISABLE TRIGGERS FOR LOAD OF customer.

REPEAT:
    CREATE customer.
    IMPORT customer.
END.

INPUT CLOSE. 

If the file uses a delimiter other than a space to separate fields, use the DELIMITER option of the IMPORT statement.

r-cstin.p
DEFINE VARIABLE cnum     LIKE customer.cust-num.
DEFINE VARIABLE cname    LIKE customer.name.
DEFINE VARIABLE cmax     LIKE customer.credit-limit.

INPUT FROM custdump2.

FOR EACH customer:
   IMPORT DELIMITER ";" cnum cname cmax.
   DISPLAY cnum cname cmax.
END.

INPUT CLOSE. 

You can use the UNFORMATTED option to read the contents of a standard text file. For example, the following procedure reads and displays the contents of the hello file.

r-hello.p
DEFINE VARIABLE text-string AS CHARACTER FORMAT "x(76)".

INPUT FROM VALUE(SEARCH("hello")).

DO WHILE TRUE:
   IMPORT UNFORMATTED text-string.
   DISPLAY text-string WITH DOWN FRAME x.
   DOWN WITH FRAME x.
END.

INPUT CLOSE. 

In the MEMPTR version of the IMPORT statement, the MEMPTR must be pre-allocated to the size needed for reading. To get the length to read for an imported file, use the FILE_INFO system handle and the SET-SIZE statement as follows:

r-impmem.p
DEFINE VARIABLE bb AS MEMPTR.
FILE-INFO:FILE-NAME = "big.in".
SET-SIZE(bb) = FILE-INFO:FILE-SIZE.
INPUT FROM "big.in" BINARY NO-CONVERT.
IMPORT bb.
INPUT CLOSE. 

NOTES

SEE ALSO

DEFINE STREAM Statement, DISABLE TRIGGERS Statement, DISPLAY Statement, EXPORT Statement, INPUT FROM Statement, INPUT CLOSE Statement, PUT Statement, STRING Function


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095