Consultor Eletrônico



Kbase P53646: Using a FOR EACH statement to change records in a table and records get processed multiple times
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   6/12/2009
Status: Verified

SYMPTOM(s):

Using a FOR EACH statement to change records in a table

One of the fields being modified is part of the index being used to navigate through the records

Records are being processed multiple times

FACT(s) (Environment):

All Supported Operating Systems
Progress 8.x
Progress 9.x
OpenEdge 10.x

CAUSE:

This is expected behavior.

The FOR EACH statement uses a live index to walk through the records. By changing the value of any of the fields in the index that the FOR EACH is using the order of records in the index are changed. If the change you make to one of the fields in the index causes that index entry to be moved "further" down in the index then the record will be processed again.

FIX:

Either of the following options can be used to resolve the issue:

Use the USE-INDEX phrase of the FOR EACH statement and specify an index whose fields are not in the group of fields whose values you are going to be changing
Use the PRESELECT phrase of the REPEAT statement which will allow you to let the compiler determine the best set of indexes (including one with the field you are changing) as this statement builds a temporary index on the client containing the RECIDs of all records which meet the selection criteria then simply walks through this prebuilt index