Try OpenEdge Now
skip to main content
ABL Essentials
Procedure Blocks and Data Access : Language statements that define blocks : DO blocks
 

DO blocks

A DO block is the most basic programming block in ABL. The keyword DO starts a block of statements without doing anything else with those statements except grouping them. You've already used the keyword DO as a block header in a couple of ways, including your trigger blocks, such as this trigger on the Next button in h-CustOrderWin1.w:
DO:
  GET NEXT CustQuery.
IF AVAILABLE Customer THEN
DISPLAY Customer.CustNum Customer.Name Customer.Address Customer.City
      Customer.State
WITH FRAME CustQuery IN WINDOW CustWin.
{&OPEN-BROWSERS-IN-QUERY-CustQuery}
END.
This block only assures that all the statements are executed together when the event occurs. If you take a closer look at this trigger, you can use another DO block inside it to correct a small error in the program logic.
To see the error in the program logic:
1. Run h-CustOrderWin1.w.
2. Click the Last button to see the last Customer and its Orders.
3. Click the Next button.
There is no next Customer, so the Customer record is not changed. The IF AVAILABLE Customer phrase in the Next button trigger assures that nothing happens if there is no Customer to display. However, the preprocessor {&OPEN-BROWSERS-IN-QUERY-CustQuery}, which opens the Order query, isn't affected by the IF AVAILABLE Customer check, because it's a separate statement. So the code opens the Order query even if there's no current Customer, and therefore displays nothing, as shown in the following figure.
Figure 5. Example of empty query result
If there's no Customer you shouldn't open the Order query, so you need to bring both statements into the code that is executed only when a Customer is available.
To correct the statement that opens the query:
1. Create another DO-END block in the trigger:
DO:
  GET NEXT CustQuery.
  IF AVAILABLE Customer THEN
  DO:
   DISPLAY Customer.CustNum Customer.Name Customer.Address Customer.City      Customer.State
     WITH FRAME CustQuery IN WINDOW CustWin.
     {&OPEN-BROWSERS-IN-QUERY-CustQuery}
  END. /* END DO IF AVAILABLE Customer */
END.
Now the statement that opens the query won't execute either if there's no Customer. This is another illustration of how to use the DO block as a way to group multiple statements together, so that they all execute together or not at all. As this example illustrates, you can nest DO blocks as much as you wish.
Make sure you indent all the statements in the block properly so that someone reading your code can easily see how the logic is organized. It's also a good idea to get into the habit of always putting a comment with each END statement to clarify which block it's ending. When your code gets complex enough that a single set of nested blocks takes up more than a page, you'll be grateful you did this. It can prevent all sorts of logic errors.
2. Make this same DO-END correction to the trigger code for the Prev button.
3. Save the window as h-CustOrderWin2.w.
The DO block is considered the most basic kind of block because ABL doesn't provide any additional services to the block by default. There is no automatic looping within the block, no record reading, and no other special processing done for you behind the scenes. However, you can get a DO block to provide some of these services by adding keywords to the DO statement. The following section provides some examples.
* Looping with a DO block
* Using a DO block to scope records and frames