After the dataset is defined, it does not contain any data records. To populate a dataset with data using the FILL() method, you need to associate each temp-table buffer in the dataset with a data-source object. After the data-sources are defined and attached, the temp-tables in the dataset are populated automatically or explicitly. As a best practice, define your data-sources in an include file and in your server-side procedure file, write code to attach the temp-tables of the dataset to their data-sources.

A data-source specifies where the data comes from to populate a dataset. Typically, a data-source identifies a set of OpenEdge database tables. The data-source can also identify another database accessed through an OpenEdge DataServer as the source of the data.

Each temp-table buffer in a dataset can be supplied with data from a different data-source. Make sure to define each data-source that you want to use.

Define a data-source

Before you attach data-sources to a dataset, define the data-sources. Data-sources are defined independently from the dataset and are not passed when the dataset is transported from procedure to procedure. This design allows you to switch the data-source at any time to retrieve information from multiple sources.

The following is the simplified syntax to define a data-source:

DEFINE DATA-SOURCE data-source-name FOR [QUERY query-name  ]
    [ source-table [KEYS(field...]...].
data-source-name
The name you give to the data-source.
query-name
The name of an optional query that you have previously defined. Recommended if you want to filter what data is retrieved.
source-table
Specifies one or more database tables for the data-source.
field
Specifies the fields that are primary keys.

The following example defines a data-source for the OrderLine table:

DEFINE DATA-SOURCE srcOrderLine FOR OrderLine. 

The following example defines a data-source using a query for the Order table:

DEFINE QUERY qOrder FOR Order. 
QUERY qOrder:QUERY-PREPARE( "FOR EACH Order WHERE shipdate < TODAY" ).							
DEFINE DATA-SOURCE srcOrder FOR QUERY qOrder. 

Attach a data-source

After the data-source is defined, it must be attached to the dataset before it can be used to provide data to the dataset. The default mapping is to populate fields with matching names and ignore others. The ATTACH-DATA-SOURCE method associates temp-table buffers with their data-sources.

The following is the simplified syntax for attaching a data-source. Elements of the syntax allow you to modify this default behavior.

buffer-handle:ATTACH-DATA-SOURCE (data-source-handle).
buffer-handle
The handle of a temp-table buffer in the dataset.
data-source-handle
The handle to the data-source. You can also use DATA-SOURCE data-source-name:HANDLE to specify the handle.

The following example code shows how to attach data-sources.

BUFFER ttOrder:ATTACH-DATA-SOURCE(DATA-SOURCE srcOrder:HANDLE).
BUFFER ttOrderLine:ATTACH-DATA-SOURCE(DATA-SOURCE srcOrderLine:HANDLE).

See also

ATTACH-DATA-SOURCE( ) method in ABL Reference

DEFINE DATA-SOURCE statement in ABL Reference

Define a static Data-Source in Use ProDataSets

Attach Data-Sources in Use ProDataSets