Consultor Eletrônico



Kbase P4367: When doing a FOR EACH on a table and changing data, the FOR EACH never terminates
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/15/2008
Status: Verified

SYMPTOM(s):

Using a FOR EACH statement to loop through records in a table

Changing value of fields during each iteration

Loop never terminates

CAUSE:

The reason why the FOR EACH is looping is because one of the fields that are being changed during each iteration is one of the fields that comprises the index or indexes that the FOR EACH is using to resolve the query.

But a better solution would be to use PRESELECT. If you use PRESELECT a temporary index with pointers to each of the records will be created. This allows the user to change the value of the indexed field without causing the record to be found again. If you use USE-INDEX, it might impact performance because it may not be the best index to query the records. Also if the index specified in USE-INDEX changes or is deleted, then the code may also need to be modified.

FIX:

Specify a specific index using the USE-INDEX phrase. The index you specify must be one that is not being used to resolve the query for the FOR EACH statement.