Consultor Eletrônico



Kbase P55488: How to trap duplicate records when using RAW-TRANSFER to pop
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   1/20/2004
Status: Unverified

GOAL:

How to trap duplicate records when using RAW-TRANSFER to populate a TEMP TABLE with a unique index?

FIX:

The following code offers a solution of skipping duplicate records when adding records using the Progress 4GL RAW-TRANSFER statement.

This solution works equally well with temp tables or database tables regardless whether these tables have a unique indexes or not:

DEFINE VARIABLE iCustomer AS INTEGER NO-UNDO.
DEFINE VARIABLE ittCustomer AS INTEGER NO-UNDO.
DEFINE VARIABLE duplicate AS LOGICAL NO-UNDO.

DEFINE TEMP-TABLE ttCustomer NO-UNDO LIKE customer.

/* populate the temp table with the even-numbered records of the customer table */
FOR EACH customer NO-LOCK:
iCustomer = iCustomer + 1.
IF Cust-Num MODULO(2) <> 0 THEN NEXT.
ittCustomer = ittCustomer + 1.
CREATE ttCustomer.
RAW-TRANSFER Customer TO ttCustomer.
END.

/*message the number of records we have in the temp table and the real table */
MESSAGE
"Number of Customer records scanned:" "~t" iCustomer "~n"
"Number of temp table records added:" "~t" ittCustomer
VIEW-AS ALERT-BOX INFO BUTTONS OK.

/* This code will populate the temp table with the missing odd-numbered records */
/* Notice that all the source customer table records are read and that the even */
/* numbered records are skipped */
ASSIGN
iCustomer = 0
ittCustomer = 0.

FOR EACH customer NO-LOCK:
iCustomer = iCustomer + 1.
FOR EACH ttCustomer NO-LOCK:
BUFFER-COMPARE Customer TO ttCustomer SAVE RESULT IN duplicate.
IF duplicate THEN LEAVE.
END.
IF duplicate THEN NEXT.
ittCustomer = ittCustomer + 1.
CREATE ttCustomer.
RAW-TRANSFER Customer TO ttCustomer.
END.

/*message the number of records we added to the temp table and the real table */
MESSAGE
"Number of Customer records scanned:" "~t" iCustomer "~n"
"Number of temp table records added:" "~t" ittCustomer
VIEW-AS ALERT-BOX INFO BUTTONS OK.