DO blocks
- Last Updated: October 14, 2024
- 3 minute read
- OpenEdge
- Version 13.0
- Documentation
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 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:
|
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:
- Run h-CustOrderWin1.w.
- Click the Last button to see the last Customer and its Orders.
- 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, is not affected by the IF
AVAILABLE Customer check, because it is 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.

If there is no Customer you should not open the Order query, so you need to bring both statements into the code that is executed only when a Customer is available.
- Create another
DO-ENDblock in the trigger:DO: GET NEXT CustQuery. IF AVAILABLE Customer THEN DO: DISPLAY Customer.Name Customer.CustNum 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 will not execute either if there is no Customer. This is another illustration of how to use the
DOblock as a way to group multiple statements together, so that they all execute together or not at all. As this example illustrates, you can nestDOblocks 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 is also a good idea to get into the habit of always putting a comment with each
ENDstatement to clarify which block it is ending. When your code gets complex enough that a single set of nested blocks takes up more than a page, you will be grateful you did this. It can prevent all sorts of logic errors. - Make this same
DO-ENDcorrection to the trigger code for the Prev button. - Save the window as h-CustOrderWin2.w.
DO block is considered the most basic kind of block
because ABL does not 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.