EXPORT statement
- Last Updated: January 18, 2024
- 5 minute read
- OpenEdge
- Version 12.8
- Documentation
Converts data to a standard character format and displays it to the current output destination (except when the current output destination is the screen) or to a named output stream. You can use data exported to a file in standard format as input to other ABL procedures.
Syntax
|
|
- STREAM stream
- The name of a stream. If you do not name a stream, the AVM uses the unnamed stream. See the DEFINE STREAM statement reference entry and the topics on alternate I/O sources in OpenEdge Programming Interfaces for more information on streams.
- STREAM-HANDLE handle
- Specifies the handle to a stream. If handle it is not a valid handle to a stream, the AVM generates a run-time error. Note that stream handles are not valid for the unnamed streams. See the topics on alternate I/O sources in OpenEdge Programming Interfaces for more information on streams and stream handles.
- DELIMITER character
- The character to use as a delimiter between field values. The character parameter
must be a quoted single character. The default is a space
character.
If you specify more than one character as a delimiter, ABL uses the first character as the delimiter.
- expression . . .
- One or more expressions that you want to convert into standard character format for display to an output destination.
- record
- The name of the record buffer with fields that you want to convert
into the standard character format to display to an output destination.
To use
EXPORTwith a record in a table name used in multiple databases, you must qualify the record's table name with the database name. See the record definition in the Record phrase reference entry for more information. - EXCEPT field . . .
- The AVM exports all fields except those fields listed in the
EXCEPTphrase.Note: TheEXCEPTphrase does not support individual elements of an array. If an array element is specified in theEXCEPTphrase, the entire array is omitted from the export, not just the element specified. - memptr
- A variable of data type MEMPTR that contains the data to export.
- longchar
- A variable of data type LONGCHAR that contains the data to export.
- NO-LOBS
- Directs the AVM to ignore large object data when exporting records that contain BLOB or CLOB fields.
Examples
This procedure converts the data in the Customer table into standard character format and sends that data to the customer.d file:
r-exprt.p
|
The next procedure shows how each EXPORT statement
creates one line of data (that is, fields are not wrapped onto several lines):
r-exprt2.p
|
That procedure creates a text file, custdump,
with one line for each Customer. This is a typical line of output:
|
Use the DELIMITER option to specify a character other
than a space to separate fields in the output file. For example, the following procedure
uses a semicolon:
r-cstout.p
|
This is a typical line of output from this code:
|
The following example uses the EXCEPT phrase to exclude a field from the
export:
|
The following example displays using a MEMPTR to EXPORT
mixed character and binary data:
r-expmem.p
|
Notes
- The
EXPORTstatement must follow an OUTPUT TO statement, which redirects the output destination. - Other procedures can use the data exported with the
EXPORTstatement as input by reading the file with theINSERT,PROMPT-FOR,SET,UPDATEorIMPORTstatements, orBUFFER-IMPORT()orBUFFER-IMPORT-FIELDS()methods, naming one field or variable to correspond to each data element. - The data is in a standard format to be read
back into ABL. All character fields are enclosed in quotes (
"") and quotes contained in the data you are exporting are replaced by two quotes (""). A single space separates one field from the next. An Unknown value (?) is displayed as an unquoted question mark (?). - There are no trailing blanks, leading zeros, or formatting characters (for example, dollar signs) in the data.
- ABL exports logical fields as the value YES or NO.
- A Format phrase with an
EXPORTstatement is ignored. - If you use a single qualified identifier with the
EXPORTstatement, the Compiler first interprets the reference as dbname.tablename. If the Compiler cannot resolve the reference as dbname.tablename, it tries to resolve it as tablename.fieldname. - When exporting fields, you must use table names that are different from field names to avoid ambiguous references. See the Record phrase reference entry for more information.
- When exporting RECID fields, you must explicitly state the RECID field
name in the
EXPORTstatement. - When exporting ROWID variables or fields in a work table, you must convert the ROWID variable or field to a character string using the STRING function.
- When exporting a LONGCHAR variable, the code page name is written to the header of the export file.
- Never use
APPENDwhile exporting a LONGCHAR variable. - When exporting records that contain a BLOB or CLOB field, the AVM
creates a separate object data file with the code page embedded in the filename and with a
file extension of .blb. The filename is stored in the BLOB or CLOB
field of the exported record. (When importing records that contain a BLOB or CLOB field,
the AVM uses this filename to locate the object data file associated with each record.) If
the BLOB or CLOB field contains the Unknown value (
?), the AVM stores the Unknown value (?) in the BLOB or CLOB field of the exported record, and does not create an object data file. If the BLOB or CLOB field contains a zero-length object, the AVM creates a zero-length object data file.The AVM raises the ERROR condition if an object data file cannot be created.
- When dealing with Unicode CLOB and LONGCHAR variables, avoid using the
EXPORTstatement. The AVM uses the UTF-8 codepage for all UnicodeEXPORTs. Use theCOPY-LOBstatement to avoid this conversion. - The
EXPORTstatement creates large object data files in the directory specified as the output destination in theOUTPUT TOstatement, by default. You can use theLOB-DIRoption on theOUTPUT TOstatement to specify the directory in which theEXPORTstatement creates the BLOB and CLOB data files. - Use the
NO-LOBSoption with theEXPORTstatement to ignore large object data when exporting records that contain BLOB or CLOB fields. When you specify theNO-LOBSoption, the AVM stores the Unknown value (?) in the BLOB or CLOB field of the exported records and does not create the associated object data files. - When exporting DATETIME and DATETIME-TZ data, the data format is fixed and conforms to
the ISO 8601 standard for date/time representations
(
YYYY-MM-DDTHH:MM:SS.SSS+HH:MM). For DATETIME, there is no time zone offset. - If you use the
DELIMITERoption of theEXPORTstatement to specify a delimiter other than a space character, you must specify the same delimiter character in a subsequentIMPORTstatement that loads the data. EXPORTis sensitive to the Date format (-d), Century (-yy), and European numeric (-E) startup parameters. When loading data with theIMPORTstatement, use the same settings that you used with theEXPORTstatement.- In the MEMPTR version of the
EXPORTstatement, the MEMPTR's size will determine how much is written to the file. If the size of a MEMPTR is 100, and it only contains a string of length 10, the entire 100 bytes will still be written to the file. ThePUT-BYTESstatement andGET-BYTESfunction may be used to move portions of MEMPTRs to areas with varying sizes.You can read and write parts of a file by using MEMPTRs of varying sizes, and multipleEXPORT/IMPORTstatements on the same file.
See also
BUFFER-EXPORT( ) method, BUFFER-EXPORT-FIELDS( ) method, BUFFER-IMPORT( ) method, BUFFER-IMPORT-FIELDS( ) method, COPY-LOB statement, DEFINE STREAM statement, DISPLAY statement, IMPORT statement, OUTPUT CLOSE statement, OUTPUT TO statement, PUT statement, Stream object handle, STRING function