ABL provides four methods for exporting and importing data dynamically for a Buffer object handle:
  • BUFFER-EXPORT() method
  • BUFFER-IMPORT() method
  • BUFFER-EXPORT-FIELDS() method
  • BUFFER-IMPORT-FIELDS() method

These methods provide the same functionality as the IMPORT and EXPORT statements. They support the same use cases of exporting/importing data, while allowing you to supply a dynamic buffer handle rather than a hard-coded table name.

BUFFER-EXPORT() and BUFFER-IMPORT() support a primary use case of exporting all of the fields from a dynamic buffer. The other two methods, BUFFER-EXPORT-FIELDS() and BUFFER-IMPORT-FIELDS(), support a separate use case which is to export/import only a select set of fields, in a specified order, from a dynamic buffer.

BUFFER-EXPORT() method

The BUFFER-EXPORT() method converts data from the buffer object to a standard character format and writes it to the current output destination or to a named output stream. You can optionally specify a delimiter (the default is a space), a list of fields to exclude, and a parameter indicating that BLOB and CLOB fields should be excluded.

This is the method syntax:
BUFFER-EXPORT( [ stream-handle [ , delimiter [ , except-list 
               [ , no-lobs ] ] ] ] )

You can use data exported to a file in standard format as input to other ABL procedures. For more information, see the BUFFER-EXPORT() method in the ABL Reference.

BUFFER-IMPORT() method

The BUFFER-IMPORT() method reads a line from an input stream that might have been created by the EXPORT statement or BUFFER-EXPORT() method. You can optionally specify a delimiter (the default is a space), a list of fields to exclude, and a parameter indicating that BLOB and CLOB fields should be excluded.

This is the method syntax:
BUFFER-IMPORT( [ stream-handle [ , delimiter [ , except-list 
               [ , no-lobs ] ] ] ] )

For more information, see the BUFFER-IMPORT() method in the ABL Reference.

BUFFER-EXPORT-FIELDS() method

The BUFFER-EXPORT-FIELDS() method converts data from the buffer object to a standard character format and writes it to the current output destination or to a named output stream. Only fields specified in the field list are included and they are written in the order specified. The default delimiter is a space, but you can specify a different delimiter if desired.

This is the method syntax:
BUFFER-EXPORT-FIELDS( stream-handle , delimiter , field-list )

You can use the data exported as input to other ABL procedures.

For more information, see the BUFFER-EXPORT-FIELDS() method in the ABL Reference.

BUFFER-IMPORT-FIELDS() method

The BUFFER-IMPORT-FIELDS() method reads a line from an input stream that might have been created by the EXPORT statement or the BUFFER-EXPORT-FIELDS() method. Only fields specified in the field list are included and they are read in the order specified. The default delimiter is a space, but you can specify a different delimiter if desired.

This is the method syntax:
BUFFER-IMPORT-FIELDS( stream-handle , delimiter , field-list )

For more information, see the BUFFER-IMPORT-FIELDS() method in the ABL Reference.

Examples

In this example, a dynamic query reads all records from the Customer table and exports the records to the file opened by the OUTPUT TO statement:
VAR HANDLE hBuffer.
VAR HANDLE hQuery.

CREATE BUFFER hBuffer FOR TABLE "Customer".

CREATE QUERY hQuery.
hQuery:SET-BUFFERS(hBuffer).
hQuery:QUERY-PREPARE("FOR EACH " + hBuffer:NAME).
hQuery:QUERY-OPEN().
hQuery:GET-FIRST().

OUTPUT TO VALUE(hBuffer:NAME + ".d").

DO WHILE NOT hQuery:QUERY-OFF-END:
  hBuffer:BUFFER-EXPORT().
  hQuery:GET-NEXT().
END.

OUTPUT CLOSE.

hQuery:QUERY-CLOSE().
DELETE OBJECT hQuery.
DELETE OBJECT hBuffer.
This example shows how you can use a named stream:
DEFINE STREAM s1.
OUTPUT STREAM s1 TO "order.d".
...
hBuffer:BUFFER-EXPORT(STREAM s1:HANDLE).
...
This example shows how data can be read back into the Customer table dynamically:
VAR HANDLE hBuffer.

CREATE BUFFER hBuffer FOR TABLE "Customer".

INPUT FROM VALUE(hBuffer:NAME + ".d").

DO TRANSACTION:
  REPEAT ON ENDKEY UNDO, LEAVE:
    hBuffer:BUFFER-CREATE().
    hBuffer:BUFFER-IMPORT().
    hBuffer:BUFFER-RELEASE().        
  END.
END.

INPUT CLOSE.

DELETE OBJECT hBuffer.
This example shows how to use BUFFER-EXPORT-FIELDS() to export four fields from the Customer table.
VAR HANDLE hBuffer.
VAR HANDLE hQuery.

CREATE BUFFER hBuffer FOR TABLE "Customer".

CREATE QUERY hQuery.
hQuery:SET-BUFFERS(hBuffer).
hQuery:QUERY-PREPARE("FOR EACH " + hBuffer:NAME).
hQuery:QUERY-OPEN().
hQuery:GET-FIRST().

OUTPUT TO VALUE(hBuffer:NAME + ".d").

DO WHILE NOT hQuery:QUERY-OFF-END:
  hBuffer:BUFFER-EXPORT-FIELDS(?, ?, "Name,Country,State,City").
  hQuery:GET-NEXT().
END.

OUTPUT CLOSE.

hQuery:QUERY-CLOSE().
DELETE OBJECT hQuery.
DELETE OBJECT hBuffer.
This example shows how to use BUFFER-IMPORT-FIELDS() to import the four fields from the previous example into the Customer table:
VAR HANDLE hBuffer.

CREATE BUFFER hBuffer FOR TABLE "Customer".

INPUT FROM VALUE(hBuffer:NAME + ".d").

DO TRANSACTION:
  REPEAT ON ENDKEY UNDO, LEAVE:
    hBuffer:BUFFER-CREATE().
    hBuffer:BUFFER-IMPORT-FIELDS(?, ?, "Name,Country,State,City").
    hBuffer:BUFFER-RELEASE().        
  END.
END.

INPUT CLOSE.

DELETE OBJECT hBuffer.