After you define the temp-tables, you use the DEFINE DATASET statement to define the dataset that is composed of those temp-tables. Similar to defining temp-tables in their own include files, you can define a dataset in its own include file. The DEFINE DATASET statement is a complex statement with multiple components. You use the statement to:
  • Name the dataset and specify the temp-tables that comprise the dataset.
  • Define any data-relations between those temp-tables.

Data-relations control how a dataset is populated. (Dataset population is typically done through the FILL() method, which is discussed later in this track). Data-relations in a dataset are different from OpenEdge database tables where there are no defined relationships. In a database the relationships are based on data values only and record retrieval of parent and children is based on a join query. In contrast in a dataset, any query used for filling the dataset is defined by each temp-table independently. So, the data-relation tells the AVM how the join is defined.

Syntax for the DEFINE DATASET statement

To define a dataset, you use the DEFINE DATASET statement. The following is the simplified syntax:

DEFINE DATASET dataset-name FOR buffer-name [,buffer-name ]...
    [ DATA-RELATION [data-relation-name] FOR parent-temp-table-name, child-temp-table-name  
    RELATION-FIELDS (parent-field1, child-field1 [, parent-fieldn, child-fieldn ]...) ]
dataset-name
Specifies the name of the dataset.
buffer-name
Specifies the name of the buffer on the temp-table(s) in the dataset.
data-relation-name
Specifies a data-relation. See ProDataSet relations in Use ProDataSets for more detail.
parent-temp-table-name, child-temp-table-name
Identifies the parent and child temp-tables for the data relation.
parent-fieldn, child-fieldn
Define the relationship between fields in the temp-tables. For the most efficient joins, the RELATION-FIELDS fields are indexed.

Examples of the DEFINE DATASET statement

The following example defines a dataset called dsOrderOrderLine. It is comprised of two temp-tables called ttOrder and ttOrderLine. It states that the relationship between the two tables is based upon the ordernum fields. In this example the fields in the two tables have the same name, but the names don't need to be the same. You can specify relation-fields that have different names.

DEFINE DATASET dsOrderOrderLine FOR ttOrder, ttOrderline 
  DATA-RELATION drOrderOrderLine FOR ttOrder, ttOrderline 
    RELATION-FIELDS (ordernum,ordernum). 

You can define more than one data-relation for a dataset and include more than two temp-tables. The following is an example:

DEFINE DATASET dsOrderOrderLineItem FOR ttOrder, ttOrderLine, ttItem 
  DATA-RELATION drOrderOrderLine FOR ttOrder, ttOrderLine 
    RELATION-FIELDS (Ordernum, Ordernum) 
  DATA-RELATION drOrderLineItem FOR ttOrderline, ttItem 
    RELATION-FIELDS (Itemnum, Itemnum).