PreviousNextIndex

IMPORT statement

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

Syntax

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

IMPORT [ STREAM stream | STREAM-HANDLE handle ] { memptr | longchar } 

STREAM stream
STREAM-HANDLE handle
DELIMITER character
field
^
record
EXCEPT field
UNFORMATTED field
NO-LOBS
NO-ERROR
memptr
longchar
Examples

This procedure takes the data in file customer.d and enters it into the OpenEdge database table Customer. The procedure uses the DISABLE TRIGGERS statement to stop the AVM 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  NO-UNDO LIKE Customer.CustNum. 
DEFINE VARIABLE cname NO-UNDO LIKE Customer.Name. 
DEFINE VARIABLE cmax  NO-UNDO LIKE Customer.CreditLimit. 
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 NO-UNDO FORMAT "x(76)". 
INPUT FROM VALUE(SEARCH("hello")). 
DO WHILE TRUE ON ENDKEY UNDO, LEAVE: 
  IMPORT UNFORMATTED text-string. 
  DISPLAY text-string WITH DOWN FRAME x. 
  DOWN WITH FRAME x NO-LABELS. 
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 NO-UNDO. 
ASSIGN 
  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, Stream object handle, STRING function


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex