Try OpenEdge Now
skip to main content
ABL Essentials
Procedure Blocks and Data Access : Language statements that define blocks : FOR blocks : Using block headers to identify blocks
 
Using block headers to identify blocks
If it isn't clear what block the LEAVE statement applies to, or if you want it to apply to some other enclosing block, you can give a block a name followed by a colon and then specifically leave that block. This variant of the procedure has the same effect as the first one:
FOR EACH Customer NO-LOCK WHERE Customer.State = "NH" WITH FRAME f:
  DISPLAY Customer.CustNum Customer.Name.

  OrderBlock:
  FOR EACH Order OF Customer NO-LOCK BY Order.OrderDate:
    DISPLAY Order.OrderNum Order.OrderDate WITH FRAME f.
    LEAVE OrderBlock.
  END. /* FOR EACH Order */
END. /* FOR EACH Customer */
Just to see the effect of specifying a different block, you can try this variant:
CustBlock:
FOR EACH Customer NO-LOCK WHERE Customer.State = "NH" WITH FRAME f:
  DISPLAY Customer.CustNum Customer.Name.

  OrderBlock:
  FOR EACH Order OF Customer NO-LOCK BY Order.OrderDate:
    DISPLAY Order.OrderNum Order.OrderDate WITH FRAME f.
    LEAVE CustBlock.
  END. /* FOR EACH Order */
END. /* FOR EACH Customer */
If you run this code, the AVM leaves the outer FOR EACH Customer block after retrieving the first Order for the first Customer because of the change to the LEAVE statement, as shown in the following figure.
Figure 14. Specifying a different block