我有 5 个与父子关系相关的表。像 table1 -> table2->table3->table4->table5,这里的箭头显示父子关系。如何使用 prodataset in progress 4GL 从这些相关表中获取记录?我如何为这种情况定义查询?
问问题
3710 次
1 回答
0
这是一个连接 1 个表的示例,只需使用 ,FIRST 格式向 cQuery 添加更多表。
ASSIGN
cQuery = "FOR EACH table1 NO-LOCK ":U
+ " WHERE table1.product_obj = ":U + QUOTER(cProduct)
+ " AND table1.role_obj = ":U + QUOTER(cRole)
+ " ,FIRST table2 NO-LOCK ":U
+ " WHERE table2.criterion_obj = table1.criterion_obj":U.
hQuery:SET-BUFFERS(BUFFER table1:HANDLE, BUFFER table2:HANDLE).
hQuery:QUERY-PREPARE(cQuery) NO-ERROR.
hQuery:QUERY-OPEN() NO-ERROR.
hQuery:GET-FIRST() NO-ERROR.
DO WHILE NOT hQuery:QUERY-OFF-END:
<put logic here>
hQuery:GET-NEXT() NO-ERROR.
END.
=============
对于 ProDataSets,您需要定义临时表,然后创建 ProDataSets
手册中的示例:
DEFINE TEMP-TABLE ttOrder LIKE Order
FIELD OrderTotal AS DECIMAL
FIELD CustName LIKE Customer.NAME
FIELD RepName LIKE SalesRep.RepName.
DEFINE TEMP-TABLE ttOline LIKE OrderLine.
DEFINE TEMP-TABLE ttItem
FIELD ItemNum LIKE ITEM.ItemNum
FIELD ItemName LIKE ITEM.ItemName
FIELD Price LIKE ITEM.Price
FIELD Weight LIKE ITEM.Weight
FIELD OnHand LIKE ITEM.OnHand
FIELD OnOrder LIKE ITEM.OnOrder.
DEFINE DATASET dsOrder FOR ttOrder, ttOline, ttItem
DATA-RELATION OrderLine FOR ttOrder, ttOline
RELATION-FIELDS (OrderNum, OrderNum)
DATA-RELATION LineItem FOR ttOline, ttItem
RELATION-FIELDS (ItemNum, ItemNum).
DEFINE VARIABLE hDSOrder AS HANDLE NO-UNDO.
hDSOrder = DATASET dsOrder:HANDLE.
DEFINE QUERY qOrder FOR Order, Customer, SalesRep.
DEFINE QUERY qItem FOR ITEM.
DEFINE DATA-SOURCE srcOrder FOR QUERY qOrder
Order KEYS (OrderNum), Customer KEYS (CustNum), SalesRep KEYS (SalesRep).
DEFINE DATA-SOURCE srcOline FOR OrderLine.
DEFINE DATA-SOURCE srcItem FOR QUERY qItem ITEM KEYS (ItemNum).
BUFFER ttOrder:ATTACH-DATA-SOURCE(DATA-SOURCE srcOrder:HANDLE,
"Customer.Name,CustName").
BUFFER ttOline:ATTACH-DATA-SOURCE(DATA-SOURCE srcOline:HANDLE).
BUFFER ttItem:ATTACH-DATA-SOURCE(DATA-SOURCE srcItem:HANDLE).
QUERY qOrder:QUERY-PREPARE("FOR EACH Order WHERE Order.OrderNum = 1, " +
"FIRST Customer OF Order, FIRST SalesRep OF Order"). /* setup query to fill
dataset */
hDSOrder:FILL(). /* fill the ProDataSet as a whole */
于 2013-10-29T11:05:35.257 回答