Datasets 101

Posted by jmls on 13-Aug-2009 05:55

for some strange reason, I thought that this would be easy. Oh well.

I have an existing system with three entities: customer, branches, transactions.

Each customer can have multiple branches, and each customer (not the branch) has multiple transactions.

My current system has three temp tables

Customer (custid)

branch (custid,branchid)

transaction (custid,transactionid)

I already have logic to fill these temp-tables, and what I wanted to do was to export the data as an xml file. Yay! Prodataset !

Boo!

DEF TEMP-TABLE Transaction NO-UNDO       FIELD CustID AS CHAR

      FIELD TransactionID AS CHAR

      ...[more fields]...             INDEX CustID IS PRIMARY         CustID.         DEF TEMP-TABLE Branch NO-UNDO       FIELD CustID   AS CHAR       FIELD BranchID  AS CHAR

      ...[more fields]...             INDEX CustID IS PRIMARY         CustID. DEF TEMP-TABLE Customer NO-UNDO       FIELD CustID   AS CHAR

      ...[more fields]...

      INDEX CustID IS PRIMARY         CustID.

DATASET demo  FOR Customer, Branch, Transaction       DATA-RELATION CustomerBranch FOR Customer, Branch                     RELATION-FIELDS (CustID,CustID)

      DATA-RELATION CustomerTransaction FOR Customer, Transaction                     RELATION-FIELDS (CustID,CustID).

I then create the temp-table data, and WRITE-XML on the dataset. What I was hoping to get was

<demo>

     <customer>

          <branch>

          <branch>

          <transaction>

          <transaction>

     </customer>

     <customer>

          <branch>

          <branch>

          <transaction>

          <transaction>

     </customer>

</demo>

etc

what I got was

<demo>

     <customer>

     <customer>

     <branch>

     <branch>

     <branch>

     <branch>

     <transaction>

     <transaction>

     <transaction>

     <transaction>

</demo>

What am I doing wrong ? I don't want to FILL, as I already have the data created in the temp tables ?

TIA

All Replies

Posted by ojfoggin on 13-Aug-2009 06:07

This has happened to me also.

My PDS was only with 2 temp-tables and it put them all out inline.

i.e.

    

    

    

    

    

    

    

    

Posted by rbf on 13-Aug-2009 06:10

Check out the NESTED keyword.

Posted by jmls on 13-Aug-2009 06:13

Urgh. Was just looking at that. I feel really stupid. Thanks anyway

Posted by jmls on 13-Aug-2009 12:41

crap, I just awarded Oliver a "correct answer"

Sorry Peter, best you can do now is have a "helpful answer" ..

This thread is closed