Consultor Eletrônico



Kbase P112979: 4GL: How to populate TEMP TABLEs of ProDataSet object TEMP-TABLE from text files.
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   27/01/2006
Status: Unverified

GOAL:

4GL: How to populate TEMP TABLEs of ProDataSet object TEMP-TABLE from text files.

GOAL:

How to use the BEFORE-FILL event of to populate parent and child TEMP-TABLE of a DATASET object?

FIX:

The following code defines a static DATASET object containing two static TEMP-TABLEs. ttCustomer, a parent TEMP-TABLEand ttOrder a child TEMP-TABLE. The code shows how to populate these TEMP-TABLEs using the SET-CALLBACK-PROCEDURE( ) method BEFORE-FILL event from text files:
/* Define Variables */
DEFINE VARIABLE hDataSet AS HANDLE NO-UNDO.
/* Define First Temp Table */
DEFINE TEMP-TABLE ttCustomer
FIELD fCustNum AS INTEGER
FIELD fCustName AS CHARACTER
INDEX idxCustNum IS UNIQUE PRIMARY fCustNum.
/* Define Second Temp Table */
DEFINE TEMP-TABLE ttOrder
FIELD fOrderNum AS INTEGER
FIELD fCustNum AS INTEGER
INDEX idxOrderNum IS UNIQUE PRIMARY fOrderNum.
/* Define ProDataSet w these the two tables and establish relationship*/
DEFINE DATASET dsCustomerOrder FOR ttCustomer, ttOrder
DATA-RELATION drCustomerOrder FOR ttCustomer, ttOrder
RELATION-FIELDS (fCustNum, fCustNum).
/* Get Handle to DataSet */
hDataSet = DATASET dsCustomerOrder:HANDLE.
/* Set Callback Procedure at the ttCustomer temp table level */
BUFFER ttCustomer:SET-CALLBACK-PROCEDURE
("BEFORE-FILL", "preCustomerFill", THIS-PROCEDURE).
DATASET dsCustomerOrder:FILL().
PROCEDURE preCustomerFill:
DEFINE INPUT PARAMETER DATASET FOR dsCustomerOrder.
INPUT FROM ttCustomer.d.
REPEAT TRANSACTION:
CREATE ttCustomer.
IMPORT ttCustomer.
IF ttCustomer.fCustNum = 0 THEN DELETE ttCustomer.
END.
INPUT CLOSE.
/* Manually fill child temp table(s) here */
INPUT FROM ttOrder.d.
REPEAT TRANSACTION:
CREATE ttOrder.
IMPORT ttOrder.
IF ttOrder.fOrderNum = 0 THEN DELETE ttOrder.
END.
INPUT CLOSE.
END PROCEDURE.
/* Test that data and relationships are intact */
FOR EACH ttCustomer NO-LOCK:
DISPLAY
ttCustomer.fCustNum FORMAT "ZZZZZ"
ttCustomer.fCustName FORMAT "X(30)"
WITH FRAME ttPurchaseOrderFrame 1 COL TITLE "Customers".
FOR EACH ttOrder OF ttCustomer:
DISPLAY
ttOrder.fCustNum FORMAT "ZZZZZ"
ttOrder.fOrderNum FORMAT "ZZZZZ"
WITH FRAME ttPOLineFrame 1 COL TITLE "Orders".
END.
END.