Consultor Eletrônico



Kbase P68785: How to define a ProDataSet?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   12/15/2010
Status: Verified

GOAL:

How to define a ProDataSet?

GOAL:

Steps to define a ProDataSet

FACT(s) (Environment):

OpenEdge 10.0x
All Supported Operating Systems

FIX:

The following code sample demonstrates how to define and populate a ProDataSet. It requires the Sports2000 database to be connected in order to run successfully.
Note that this is only a general example, and is not intended as a conclusive demonstration of all ProDataSet features.

/* 1. Define a Temporary table for each table you wish to use in the ProDataSet. */

DEFINE TEMP-TABLE ttOrder BEFORE-TABLE ttOrderBefore
FIELD OrderNum LIKE Order.OrderNum
FIELD OrderDate LIKE Order.OrderDate
FIELD CustName LIKE Customer.NAME
FIELD Discount LIKE Customer.Discount
FIELD RepName LIKE SalesRep.RepName
INDEX OrderNum IS UNIQUE OrderNum.

DEFINE TEMP-TABLE ttOLine LIKE Orderline BEFORE-TABLE ttOLineBefore.

DEFINE TEMP-TABLE ttItem
FIELD ItemNum LIKE Item.ItemNum
FIELD ItemName LIKE Item.ItemName
FIELD Price LIKE Item.Price
INDEX ItemNum IS UNIQUE ItemNum.

/* 2. Define the ProDataSet by specifying the temporary tables and their relationship. */

DEFINE DATASET dsOrder FOR ttOrder, ttOLine, ttItem
DATA-RELATION drOrderLine FOR ttOrder, ttOLine RELATION-FIELDS (OrderNum,OrderNum)
DATA-RELATION drLineItem FOR ttOLine, ttItem RELATION-FIELDS (ItemNum,ItemNum).

/* 3. Identify, define and attach the datasource of Data you wish to use to populate the ProDataSet. */

DEFINE QUERY qOrder FOR Order /*, Customer, Item */.
DEFINE DATA-SOURCE srcOrder FOR QUERY qOrder
Order KEYS (OrderNum) /*,
Customer KEYS (CustNum),
Item KEYS (ItemNum) */.

DEFINE DATA-SOURCE srcOLine FOR OrderLine.
DEFINE DATA-SOURCE srcItem FOR Item.

BUFFER ttOrder:ATTACH-DATA-SOURCE(DATA-SOURCE srcOrder:HANDLE,?,?).
BUFFER ttOLine:ATTACH-DATA-SOURCE(DATA-SOURCE srcOLine:HANDLE,?,?).
BUFFER ttItem:ATTACH-DATA-SOURCE(DATA-SOURCE srcItem:HANDLE,?,?).

/* 4. Populate the ProDataSet with Data. */

QUERY qOrder:QUERY-PREPARE("FOR EACH ORDER").
DATASET dsOrder:FILL().

/* 5. Detaching the Data-Source. */

/* Note that after the FILL operation, the data in the dataset has become independent of the data source (database).
The Data-source object no longer needs to be attached at this point, until another FILL or a save operation takes place. */

BUFFER ttOrder:DETACH-DATA-SOURCE().

/* 6. Display the data */

FOR EACH ttOrder:
DISPLAY ttOrder.OrderNum
ttOrder.OrderDate
WITH FRAME ttOrderFrame 1 COL TITLE "ORDER".

FOR EACH ttOLine of ttOrder: &.nbsp;
DISPLAY ttOLine.OrderNum
ttOLine.LineNum
ttOLine.ItemNum
ttOLine.Price
ttOLine.Qty
ttOLine.Discount
ttOLine.ExtendedPrice
WITH FRAME ttOrderLineFrame 1 COL TITLE "ORDERLINE".
END.
END..