Kbase P115469: How to nest a FOR EACH loop inside another FOR EACH loop for the same database same table?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  21/04/2006 |
|
Status: Unverified
GOAL:
How to nest a FOR EACH loop inside another FOR EACH loop for the same database same table?
FIX:
To nest a FOR EACH block inside another FOR EACH block for the same database table, define another buffer name for the table. For example, the following code generates a country count report that like this:
Australia 1
Austria 3
Finland 28
France 7
Italia 2
Nederland 3
Sverige 2
United Kingdom 12
USA 1062
The code generates the above report by defining another buffer for the customer table and by nesting a FOR EACH loop inside another FOR EACH loop for the Customer table:
DEFINE VARIABLE iCount AS INTEGER NO-UNDO.
OUTPUT TO CountyCoutReport.
FOR EACH customer NO-LOCK BREAK BY country:
icount = 0.
FOR EACH bCustomer WHERE Customer.Country = bCustomer.Country NO-LOCK:
icount = icount + 1.
END.
IF FIRST-OF(country) THEN
PUT UNFORMATTED Customer.Country FORMAT "X(30)".
IF LAST-OF(Country) THEN
PUT UNFORMATTED iCount FORMAT "zzzzz" SKIP.
END.
OUTPUT CLOSE.