Try OpenEdge Now
skip to main content
Programming Interfaces
Input/Output Processes : Creating Reports : Generating reports from multiple tables : Reporting information from two tables
 
Reporting information from two tables
The next step is to look at the orders for each selected customer. This information is in the Order table. Another FOR EACH inside the first accomplishes this task. For each iteration of the outer block, the inner block finds all the related information. The WHERE clause establishes the relationship between the two tables.
The code from i-10-07.p shows the nested FOR EACH blocks.
i-10-07.p
...
FOR EACH Customer NO-LOCK
  WHERE Customer.Balance >= (Customer.CreditLimit * .85) WITH STREAM-IO:
  DISPLAY
    Customer.Name FORMAT "x(20)"
    Customer.Contact FORMAT "x(15)"
    Customer.Balance
    Customer.CreditLimit WITH NO-BOX.

  FOR EACH Order
    NO-LOCK WHERE Order.CustNum = Customer.CustNum WITH STREAM-IO:
    DISPLAY Order.OrderNum Order.OrderDate Order.ShipDate Order.PromiseDate
      SKIP(1) WITH 2 COLUMNS.
  END.
END.
...
The following output shows how the related information ends up grouped together:
Notice that for a single iteration of the Customer data, there may be several iterations of Order data. Earlier you learned that the default frame of an iterating control block is a down frame. When you nest control blocks, only the innermost block uses a down frame. The other blocks execute one iteration at a time. This default behavior lets the related information group together naturally with the iteration of the blocks.