When I execute the below code with another .p, I have this message : FILL requires an attached data-source for buffer <name>, or an active before-fill callback procedure. (11874)
Suggest modification in below Code --------
{/Temp-DB/dsOrderTT.i}
{Temp-DB/dsOrder.i}
DEFINE INPUT PARAMETER piOrderNum AS INTEGER NO-UNDO.
DEFINE INPUT PARAMETER phDataSet AS HANDLE NO-UNDO.
DEFINE QUERY qOrder FOR Order, Customer, SalesRep.
DEFINE VARIABLE iBuff AS INTEGER NO-UNDO.
DEFINE VARIABLE hBuff AS HANDLE NO-UNDO.
DEFINE DATA-SOURCE srcOrder FOR QUERY qOrder
Order KEYS (OrderNum), Customer KEYS (CustNum),
SalesRep KEYS (SalesRep).
DEFINE DATA-SOURCE srcOline FOR OrderLine.
DEFINE DATA-SOURCE srcItem FOR ITEM KEYS (ItemNum).
phDataSet:SET-CALLBACK-PROCEDURE
("BEFORE-FILL", "preDataSetFill", THIS-PROCEDURE).
phDataSet:SET-CALLBACK-PROCEDURE
("AFTER-FILL", "postDataSetFill", THIS-PROCEDURE).
phDataSet:GET-BUFFER-HANDLE("ttOrder"):SET-CALLBACK-PROCEDURE
("BEFORE-FILL", "preOrderFill", THIS-PROCEDURE).
phDataSet:GET-BUFFER-HANDLE("ttOline"):SET-CALLBACK-PROCEDURE
("AFTER-FILL", "postOlineFill", THIS-PROCEDURE).
phDataSet:GET-BUFFER-HANDLE("ttItem"):SET-CALLBACK-PROCEDURE
("AFTER-ROW-FILL", "postItemRowFill", THIS-PROCEDURE).
PROCEDURE preDataSetFill:
DEFINE INPUT PARAMETER DATASET FOR dsOrder.
QUERY qOrder:QUERY-PREPARE("FOR EACH Order WHERE Order.OrderNum = " +
STRING(piOrderNum) +
", FIRST Customer OF Order, FIRST SalesRep OF Order").
END PROCEDURE. /* preDataSetFill */
PROCEDURE postDataSetFill:
DEFINE INPUT PARAMETER DATASET FOR dsOrder.
DO iBuff = 1 TO DATASET dsOrder:NUM-BUFFERS:
DATASET dsOrder:GET-BUFFER-HANDLE(iBuff):DETACH-DATA-SOURCE().
END.
END PROCEDURE. /* postDataSetFill */
PROCEDURE postOlineFill:
DEFINE INPUT PARAMETER DATASET FOR dsOrder.
DEFINE VARIABLE dTotal AS DECIMAL NO-UNDO.
FOR EACH ttOline WHERE ttOline.OrderNum =
ttOrder.OrderNum:
dTotal = dTotal + ttOline.ExtendedPrice.
END.
ttOrder.TotalOrder = dTotal.
END PROCEDURE. /* postOnlineFill */
PROCEDURE postItemRowFill:
DEFINE INPUT PARAMETER DATASET FOR dsOrder.
DEFINE VARIABLE iType AS INTEGER NO-UNDO.
DEFINE VARIABLE cItemTypes AS CHARACTER NO-UNDO
INIT "BASEBALL,CROQUET,FISHING,FOOTBALL,GOLF,SKI,SWIM,TENNIS".
DEFINE VARIABLE iTypeNum AS INTEGER NO-UNDO.
DEFINE VARIABLE cType AS CHARACTER NO-UNDO.
DO iType = 1 TO NUM-ENTRIES(cItemTypes):
cType = ENTRY(iType, cItemTypes).
IF INDEX(ttItem.ItemName, cType) NE 0 THEN
ttItem.ItemName = REPLACE(ttItem.ItemName, cType, cType).
END.
END PROCEDURE.
PROCEDURE preOrderFill:
DEFINE INPUT PARAMETER DATASET FOR dsOrder.
BUFFER ttOrder:ATTACH-DATA-SOURCE(DATA-SOURCE srcOrder:HANDLE,
"Customer.Name,CustName").
END PROCEDURE
Please post the temp-table and dataset definitions so we can reproduce it and check.
I got it to work. First, the problem you're having is probably because by the time you fill the dataset, the callback-procedures are out of scope. I put the fill INSIDE the code above, and it seems to work. I also removed the tables in the ttOrder datasource field pairs, since there's no custname in order, only custnum. This would be my first (calling) procedure:
DEFINE TEMP-TABLE ttOLine LIKE orderLine.
DEFINE TEMP-TABLE ttOrder LIKE order
FIELD totalOrder AS DECIMAL.
DEFINE TEMP-TABLE ttItem LIKE ITEM.
DEFINE DATASET dsOrder FOR ttOrder, ttOLine, ttItem.
DEFINE VARIABLE hDS AS HANDLE NO-UNDO.
ASSIGN hDS = DATASET dsOrder:HANDLE.
run p:\tests\dataset.p (INPUT 1 , INPUT-OUTPUT DATASET dsOrder BY-REFERENCE).
FOR EACH ttOrder:
DISP ttOrder.ordernum.
END.
And this would be the code you have above, a little different:
DEFINE TEMP-TABLE ttOLine LIKE orderLine.
DEFINE TEMP-TABLE ttOrder LIKE order
FIELD totalOrder AS DECIMAL.
DEFINE TEMP-TABLE ttItem LIKE ITEM.
DEFINE DATASET dsOrder FOR ttOrder, ttOLine, ttItem.
DEFINE INPUT PARAMETER piOrderNum AS INTEGER NO-UNDO.
/*.DEFINE INPUT PARAMETER phDataSet AS HANDLE NO-UNDO.*/
DEFINE INPUT-OUTPUT PARAMETER DATASET FOR dsOrder.
DEFINE VARIABLE phdataset AS HANDLE NO-UNDO.
phDataset = DATASET dsOrder:HANDLE.
DEFINE QUERY qOrder FOR Order, Customer, SalesRep.
DEFINE VARIABLE iBuff AS INTEGER NO-UNDO.
DEFINE VARIABLE hBuff AS HANDLE NO-UNDO.
DEFINE DATA-SOURCE srcOrder FOR QUERY qOrder
Order KEYS (OrderNum), Customer KEYS (CustNum),
SalesRep KEYS (SalesRep).
DEFINE DATA-SOURCE srcOline FOR OrderLine.
DEFINE DATA-SOURCE srcItem FOR ITEM KEYS (ItemNum).
phDataSet:SET-CALLBACK-PROCEDURE
("BEFORE-FILL", "preDataSetFill", THIS-PROCEDURE).
phDataSet:SET-CALLBACK-PROCEDURE
("AFTER-FILL", "postDataSetFill", THIS-PROCEDURE).
phDataSet:GET-BUFFER-HANDLE("ttOrder"):SET-CALLBACK-PROCEDURE
("BEFORE-FILL", "preOrderFill", THIS-PROCEDURE).
phDataSet:GET-BUFFER-HANDLE("ttOline"):SET-CALLBACK-PROCEDURE
("AFTER-FILL", "postOlineFill", THIS-PROCEDURE).
phDataSet:GET-BUFFER-HANDLE("ttItem"):SET-CALLBACK-PROCEDURE
("AFTER-ROW-FILL", "postItemRowFill", THIS-PROCEDURE).
DATASET dsOrder:FILL().
PROCEDURE preDataSetFill:
DEFINE INPUT PARAMETER DATASET FOR dsOrder.
QUERY qOrder:QUERY-PREPARE("FOR EACH Order WHERE Order.OrderNum = " +
STRING(piOrderNum) +
", FIRST Customer OF Order, FIRST SalesRep OF Order").
END PROCEDURE. /* preDataSetFill */
PROCEDURE postDataSetFill:
DEFINE INPUT PARAMETER DATASET FOR dsOrder.
DO iBuff = 1 TO DATASET dsOrder:NUM-BUFFERS:
DATASET dsOrder:GET-BUFFER-HANDLE(iBuff):DETACH-DATA-SOURCE().
END.
END PROCEDURE. /* postDataSetFill */
PROCEDURE postOlineFill:
DEFINE INPUT PARAMETER DATASET FOR dsOrder.
DEFINE VARIABLE dTotal AS DECIMAL NO-UNDO.
FOR EACH ttOline WHERE ttOline.OrderNum =
ttOrder.OrderNum:
dTotal = dTotal + ttOline.ExtendedPrice.
END.
ttOrder.TotalOrder = dTotal.
END PROCEDURE. /* postOnlineFill */
PROCEDURE postItemRowFill:
DEFINE INPUT PARAMETER DATASET FOR dsOrder.
DEFINE VARIABLE iType AS INTEGER NO-UNDO.
DEFINE VARIABLE cItemTypes AS CHARACTER NO-UNDO
INIT "BASEBALL,CROQUET,FISHING,FOOTBALL,GOLF,SKI,SWIM,TENNIS".
DEFINE VARIABLE iTypeNum AS INTEGER NO-UNDO.
DEFINE VARIABLE cType AS CHARACTER NO-UNDO.
DO iType = 1 TO NUM-ENTRIES(cItemTypes):
cType = ENTRY(iType, cItemTypes).
IF INDEX(ttItem.ItemName, cType) NE 0 THEN
ttItem.ItemName = REPLACE(ttItem.ItemName, cType, cType).
END.
END PROCEDURE.
PROCEDURE preOrderFill:
DEFINE INPUT PARAMETER DATASET FOR dsOrder.
BUFFER ttOrder:ATTACH-DATA-SOURCE(DATA-SOURCE srcOrder:HANDLE,
"custnum,custnum").
END PROCEDURE.
/*--------------------------*/
And even though you still get an error for failing to attach a datasource to the orderline temp-table, you get a record for ttOrder.
Hope it helps,
Murilo