我想要创建一个数据集,它只包含临时表,关系将在以后定义。
当我在数据集中定义关系时,一切都很好。
DEF TEMP-TABLE ttParent NO-UNDO
FIELD pKey AS INT
FIELD parentName AS CHAR.
DEF TEMP-TABLE ttChild NO-UNDO
FIELD iParent AS INT XML-NODE-TYPE "HIDDEN"
FIELD childName AS CHAR.
DEF DATASET dsMyDataset
FOR ttParent, ttChild
DATA-RELATION Parent_Child FOR ttParent, ttChild
RELATION-FIELDS(pKey, iParent)
NESTED FOREIGN-KEY-HIDDEN.
CREATE ttParent.
ASSIGN
ttParent.pKey = 1
ttParent.parentName = "Parent".
CREATE ttChild.
ASSIGN
ttChild.iParent = ttParent.pKey
ttChild.childName = "Child".
CREATE ttChild.
ASSIGN
ttChild.iParent = ttParent.pKey
ttChild.childName = "Child2".
DATASET dsMyDataset:WRITE-XML("FILE", "C:/temp/testDs.xml").这将像预期的那样创建以下XML:
<?xml version="1.0"?>
<dsMyDataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ttParent>
<pKey>1</pKey>
<parentName>Parent</parentName>
<ttChild>
<childName>Child</childName>
</ttChild>
<ttChild>
<childName>Child2</childName>
</ttChild>
</ttParent>
</dsMyDataset>现在,当我将其重写到dataset中时,其中只定义了试探表,然后添加了这些关系:
// Definition of temp-tables same as above
DEF DATASET dsMyDynamicDataset
FOR ttParent, ttChild.
DATASET dsMyDynamicDataset:ADD-RELATION (
BUFFER ttParent:HANDLE, BUFFER ttChild:HANDLE,
"pKey,iParent",
FALSE, TRUE, FALSE, FALSE, TRUE).
// Filling of temp-tables same as above
DATASET dsMyDynamicDataset:WRITE-XML("FILE", "C:/temp/testDs.xml").我希望得到与上面相同的结果,但这是我得到的结果:
<?xml version="1.0"?>
<dsMyDynamicDataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ttParent>
<pKey>1</pKey>
<parentName>Parent</parentName>
</ttParent>
<ttChild>
<childName>Child</childName>
</ttChild>
<ttChild>
<childName>Child2</childName>
</ttChild>
</dsMyDynamicDataset>发布于 2017-11-07 15:38:41
您将关系设置为非活动。ADD-RELATION语句中的第三个逻辑参数是“非活动的”。如果为false,则创建但未激活关系。将该参数更改为true,您将得到预期的输出。
以下是关于ADD-RELATION的进度文档
https://stackoverflow.com/questions/47160433
复制相似问题