Hi All,
I am new to datasets and I am trying to copy an entire database table to a dataset temp-tables along with 1 extra field which is a holds the database table record rowid .
I am trying to do this in three stages
1. All the data is copied to the corresponding temp-table fields using a fill.
2. I then reuse the data source to copy the database table rowid to the temp-table field RecordRowid
3. I then do a second fill to try and copy the updated data to the temp table.
In the code below 1 works fine but 2. and 3 don't work. I have spent ages trying to figure this out but have failed to get this to work. I am probably going to have to use a for each here to populate the RecordRowid manually.
Before I do I was just wondering if it is possible to do this and I'm just doing something very simple wrong.
I am new to datasets and I am trying to copy an entire database table to a dataset temp-tables along with 1 extra field which is a holds the database table record rowid .
I am trying to do this in three stages
1. All the data is copied to the corresponding temp-table fields using a fill.
2. I then reuse the data source to copy the database table rowid to the temp-table field RecordRowid
3. I then do a second fill to try and copy the updated data to the temp table.
In the code below 1 works fine but 2. and 3 don't work. I have spent ages trying to figure this out but have failed to get this to work. I am probably going to have to use a for each here to populate the RecordRowid manually.
Before I do I was just wondering if it is possible to do this and I'm just doing something very simple wrong.
Code:
/* dsOrderTT.i*/
define temp table ttOrders Like sports2000.order
field RecordRowid as rowid.
....
/* fillDSOrder.p -- Test procedure for an Order Dataset */
{dsOrderTT.i}
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) REPOSITION.
DEFINE INPUT PARAMETER piOrderNum AS INTEGER NO-UNDO.
DEFINE OUTPUT PARAMETER DATASET FOR dsOrder.
DEFINE VARIABLE vchPairs AS CHARACTER NO-UNDO.
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 KEYS (OrderNum).
DEFINE DATA-SOURCE srcItem FOR Item KEYS (ItemNum).
QUERY qOrder:QUERY-PREPARE("FOR EACH Order WHERE Order.OrderNum < 10 " +
", FIRST Customer OF Order, FIRST SalesRep OF Order").
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).
DATASET dsOrder:FILL().
DATASET dsOrder:ACCEPT-CHANGES ().
MESSAGE "Someone else changed it." DATA-SOURCE srcOrder:DATA-SOURCE-ROWID VIEW-AS alert-box.
BUFFER ttOrder:ATTACH-DATA-SOURCE(DATA-SOURCE srcOrder:HANDLE,"DATA-SOURCE srcOrder:DATA-SOURCE-ROWID,ttOrder.RecordRowident)").
BUFFER ttOLine:ATTACH-DATA-SOURCE(DATA-SOURCE srcOline:HANDLE,"DATA-SOURCE srcOline:DATA-SOURCE-ROWID,ttOLine.RecordRowident").
BUFFER ttItem:ATTACH-DATA-SOURCE(DATA-SOURCE srcItem:HANDLE,"DATA-SOURCE srcItem:DATA-SOURCE-ROWID,ttItem.RecordRowident").
DATASET dsOrder:GET-BUFFER-HANDLE("ttOrder"):FILL-MODE = "MERGE".
DATASET dsOrder:GET-BUFFER-HANDLE("ttOline"):FILL-MODE = "MERGE".
DATASET dsOrder:GET-BUFFER-HANDLE("ttItem"):FILL-MODE = "MERGE".
DATASET dsOrder:FILL().
DATASET dsOrder:ACCEPT-CHANGES ().
FIND FIRST ttOline NO-ERROR.
IF NOT BUFFER ttOLine:ROW-STATE = ROW-MODIFIED THEN
MESSAGE "Someone else changed it." string(ttOLine.RecordRowident) VIEW-AS alert-box.
BUFFER ttOrder:DETACH-DATA-SOURCE().
BUFFER ttOline:DETACH-DATA-SOURCE().
BUFFER ttItem:DETACH-DATA-SOURCE().