How can I use FOR each while traversing the table for one of the fields ascending to OpenEdge?

So, for example, I have a table with a "sub_id" field that is not sorted in ascending or descending order. I want to do for EVERYONE from smallest sub_id to largest, how can I do that?

+3


source to share


1 answer


You must use the BY keyword. If the field you are sorting is not indexed, it can be slow and consume system resources. This will be most apparent on a large table.

/* Smallest to largest */
FOR EACH tablename NO-LOCK BY tablename.sub_id:
  /* Do something */
END.

/* Largest to smallest sub_id */
FOR EACH tablename NO-LOCK BY tablename.sub_id DESCENDING:
  /* Do something */
END.

/* With a WHERE clause */
FOR EACH tablename NO-LOCK WHERE tablename.field = "something" BY tablename.sub_id:
  /* Do something */
END.

      



If you want to change data (update, assign, etc.), NO-LOCK as above will not work. NO-LOCK is for read-only operations (such as displaying data). EXCLUSIVE-LOCK is for update / delete etc.

+3


source







All Articles