Johan Vergeer
Johan Vergeer

Reputation: 5578

Use RECID as primary key in OpenEdge TEMP-TABLE

I would like to create a dataset containing a couple of temp-tables that are filled by an xml file.

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.

Usually I would just create an iOrderNo field in ttOrderLine and match that in the datasets RELATION-FIELDS attribute. Since the data is loaded from an XML file, this will be tough.

The end goal is that instead of this:

FIND FIRST ttOrder.
FOR EACH ttOrderLine WHERE ttOrderLine.iParent = RECID(ttOrder):
    // Do something
END.

I would like to do this:

FIND FIRST ttOrder.
FOR EACH ttOrderLine of ttOrder:
    // Do something
END.

The error I get now when using the last method is Index field of table1 must be fields in table2.

Could someone tell me how I can get this done?

Upvotes: 0

Views: 996

Answers (2)

Mike Fechner
Mike Fechner

Reputation: 7192

Temp-Table records RECID's will change whenever the temp-table is passed around by-value (not by-reference) and passed between client and AppServer.

Generally using RECID's as keys in other tables is a very dangerous scenario.

So your scenario would break anyway, if the dataset with the Order RECID's in the Orderline table is populated on an AppServer and processed on a client.

Upvotes: 4

Jensd
Jensd

Reputation: 8011

For the OFsyntax to work you need to store the parent ID in a unique index in the child table.

The dataset isn't needed for this syntax but if you indeed also need a dataset using recid you should look into PARENT-ID-RELATION instead of RELATIONS-FIELDS.

Start by looking at this:

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.

Upvotes: -2

Related Questions