Hi,
I have a quick question related to nested for statements.
By nested FOR statements I mean
When I started learning PROGRESS first, I was taught that nested FOR statements were generally faster, but had the disadvantage of being less controllable. E.g. in the above code example you could have problems with locking, record scoping and depending on indexes you could have situation whereby you might have to retrieve all customers before you could update any sales-order. I was told to avoid using them when doing a search (no-lock) and never use them when doing an update.
For that reason, unless I'm writing a query for a browse I tend to avoid them completely and write something like.
The company I'm doing work for at the moment tend to use nested FOR statements. Does anyone know if my understanding of the advantages/disadvantages of nested for statements is correct. Also if anyone know maybe you could confirm when is it approriate to use and not use nested if statements.
I have a quick question related to nested for statements.
By nested FOR statements I mean
Code:
FOR EACH customer NO-LOCK,
EACH sales-order WHERE sales-order.customer-id = customer.customer-id EXCLUSIVE-LOCK NO-ERROR:
ASSIGN sales-order.status = "archive".
END.
When I started learning PROGRESS first, I was taught that nested FOR statements were generally faster, but had the disadvantage of being less controllable. E.g. in the above code example you could have problems with locking, record scoping and depending on indexes you could have situation whereby you might have to retrieve all customers before you could update any sales-order. I was told to avoid using them when doing a search (no-lock) and never use them when doing an update.
For that reason, unless I'm writing a query for a browse I tend to avoid them completely and write something like.
Code:
DEFINE BUFFER b-sales-order FOR sales-order.
FOR EACH customer NO-LOCK:
DO TRANSACTION:
FOR EACH sales-order WHERE sales-order.customer-id = customer.customer-id NO-LOCK:
FIND FIRST b-sales-order where b-sales-order.order-no = sales-order.order-no
EXCLUSIVE-LOCK NO-ERROR NO-WAIT.
IF AVAILABLE b-sales-order THEN DO:
ASSIGN b-sales-order.status = "archive".
RELEASE b-sales-order.
END.
END. /* FOR EACH*/
END. /* DO TRANSACTION */
END.
The company I'm doing work for at the moment tend to use nested FOR statements. Does anyone know if my understanding of the advantages/disadvantages of nested for statements is correct. Also if anyone know maybe you could confirm when is it approriate to use and not use nested if statements.