Static ProDataSet and its Data-Relations
- Last Updated: January 17, 2024
- 4 minute read
- OpenEdge
- Version 12.8
- Documentation
Syntax
As with other ABL objects, there is a DEFINE statement
for a static ProDataSet, which allows you to name the ProDataSet,
identify the temp-table buffers it incorporates, and define the
Data-Relations between those buffers in a single statement. The Data-Relation
is not defined as a separate object because the relations have no significance
outside the scope of a particular ProDataSet.
This is the
syntax for the static DEFINE DATASET statement:
|
Where:
- dataset-name is a standard ABL object name.
- buffer-name is a static buffer name for a previously defined temp-table whose scope includes the procedure where the ProDataSet definition is.
-
data-rel-name is the optional name given
to an optional Data-Relation, which can be used to obtain the handle of
the Data-Relation at run time. The default name is
Relationn (with n starting at 1 for each ProDataSet). The presence of this option requires theFORkeyword. - This is the syntax for a data-rel-spec:
parent-buffer-name, child-buffer-namefield-mapping-phrase [REPOSITION] [NESTED] [RECURSIVE] [NOT-ACTIVE]. -
parent-buffer-name and child-buffer-name are
member buffer-names from the
FORphrase of the definition, identifying the parent and child of a relation. - This is the syntax for a field-mapping-phrase:
RELATION-FIELDS (parent-field1, child-field1 [, parent-fieldn, child-fieldn ] …)
The first field of each pair of RELATION-FIELDS is from
the parent buffer, the second field is from the child.
In some cases, there might be a relation between two buffers that cannot be
defined in terms of an equality match between fields. This might be if the relation is based
on a concatenation of fields or some other expression, or if special application logic is
required to identify the related records. It is then the responsibility of the developer to
define a query on the child buffer's Data-Source that identifies the correct records, or to
supply custom logic in response to the FILL events to take
over complete responsibility for filling that level of the ProDataSet. Any fields in this
query that are not also in the data-relation will not be used by the ProDataSet for
navigation after it has been filled.
Because a ProDataSet is made up of ABL temp-tables, you must define those temp-tables before you reference them in the ProDataSet.
For the example window, there are three temp-table definitions. To make it easier to use those definitions in more than one procedure, the definitions are in the include file dsOrderTT.i, as shown:
|
The first temp-table, ttOrder,
is based on the Order database table but adds three
fields to it:
- The first additional field is a calculated
field that shows the total of all
OrderLinesfor theOrder. You will write event logic later on to calculate this field for each selectedOrder. - The second field is the
Customer Namefrom theCustomertable. You will define the join for this table in the query for thettOrdertable's Data-Source. - The third field is the
Sales Repname from theSalesReptable. You will also join this table into your Data-Source.
The second temp-table, ttOline,
is exactly like the OrderLine database table. The
third temp-table, ttItem, uses a subset of the
fields in the Item database table.
Note that
the ttOrder and ttOline temp-tables
are defined using the LIKE-SEQUENTIAL option. This
option is preferable to the LIKE option, especially
in a client-server deployment scenario. Unlike the LIKE option,
which creates temp-table fields in metaschema _field._field-rpos
order (POSITION order in the .df schema definition
file) of the source table's fields, LIKE-SEQUENTIAL creates
fields in _field._order sequence, as defined in the Data Dictionary.
DEFINE TEMP-TABLEtableLIKE or LIKE-SEQUENTIAL option
requires that the client have a connection to the database, otherwise
the compile will fail. You can always compile your application on
the server, where the database connection exists, then deploy your
client-side components where there is no database connection.Once you have defined the temp-tables your ProDataSet needs, you define the ProDataSet itself. In this case, the ProDataSet definition is also in an include file, dsOrder.i, as shown:
|
Note that in this exmaple, the parent and child fields in the field mapping phrases happen
to have the same names, OrderNum and ItemNum, but this is
not always the case.
Each Data-Relation defines an implicit
query for the FILL operation. When you attach a
Data-Source to ttOline at run time that uses the OrderLine table
in the database, then the predicate for this implicit query is:
|
This way the ProDataSet automatically loads
all OrderLines for the current record in the parent temp-table ttOrder.
Likewise,
the Data-Relation from ttOline to ttItem selects
the Item for each record in ttOline as
the ttOline table is filled. This results in the
ProDataSet containing all Items for the OrderLines that
are part of the specified top-level Orders. Later,
you will modify the ProDataSet so that it also loads all Items into
the ttItem table. The initial definition provides
the flexibility to load various combinations of data into the ProDataSet
at run time by changing or deactivating relations.