DO blocks
- Last Updated: October 16, 2023
- 2 minute read
- OpenEdge
- Version 12.2
- 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. For example:
|
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, 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.

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.
- Create another
DO-ENDblock 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
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's also a good idea to get into the habit of always putting a comment with each
ENDstatement 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. - 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 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.