我想创建一个包含几个由xml文件填充的临时表的数据集。
DEF TEMP-TABLE ttOrder NO-UNDO
FIELD iOrderNo AS INT
FIELD iOrderDate AS DATE
INDEX ix RECID. // This also won't work, but this is needed to use the `OF` statement when retrieving records.
DEF TEMP-TABLE ttOrderLine NO-UNDO
FIELD iParent AS RECID
FIELD iArticleNo AS INT
FIELD dPrice AS DECIMAL.
DEF DATASET dsOrder FOR ttOrder, ttOrderLine
DATA-RELATION Order_OrderLine FOR ttOrder, ttOrderLine
RELATION-FIELDS ttOrder.RECID, ttOrderLine.iParent. // This is what won't work, but what I would like to do.
通常我只会在iOrderNo
中创建一个ttOrderLine
字段,并在数据集RELATION-FIELDS
属性中匹配该字段。由于数据是从XML文件加载的,因此这很难。
最终目标是代替:
FIND FIRST ttOrder.
FOR EACH ttOrderLine WHERE ttOrderLine.iParent = RECID(ttOrder):
// Do something
END.
我想这样做:
FIND FIRST ttOrder.
FOR EACH ttOrderLine of ttOrder:
// Do something
END.
使用最后一种方法时我现在得到的错误是Index field of table1 must be fields in table2
。
有人可以告诉我如何完成这项工作吗?
答案 0 :(得分:4)
Temp-Table记录只要temp-table按值传递(而不是按引用)并在客户端和AppServer之间传递,RECID就会改变。
通常在其他表中使用RECID作为键是一种非常危险的情况。
因此,如果Orderline表中订单RECID的数据集填充在AppServer上并在客户端上处理,那么您的方案无论如何都会中断。
答案 1 :(得分:-2)
要使OF
语法起作用,您需要将父ID存储在子表的唯一索引中。
此语法不需要数据集,但如果您确实还需要使用recid的数据集,则应该查看PARENT-ID-RELATION
而不是RELATIONS-FIELDS
。
首先看一下:
DEFINE TEMP-TABLE ttOrder NO-UNDO
FIELD iOrderNo AS INTEGER
FIELD iOrderDate AS DATE
FIELD iParent AS RECID.
DEFINE TEMP-TABLE ttOrderLine NO-UNDO
FIELD iParent AS RECID
FIELD iArticleNo AS INTEGER
FIELD dPrice AS DECIMAL
INDEX ix IS UNIQUE iParent.
DEFINE DATASET dsOrder FOR ttOrder, ttOrderLine
PARENT-ID-RELATION Order_OrderLine FOR ttOrder, ttOrderLine PARENT-ID-FIELD iParent.
FOR EACH ttOrder, EACH ttOrderLine OF ttOrder:
DISPLAY ttOrder.
DISPLAY ttOrderLine.
END.