ABL is a block-structured language. Blocks contain a set of ABL statements that are executed in sequence and are terminated by an END statement. The top level or outermost block of a procedure file is called the main block. ABL code blocks can be nested. Some ABL statements define blocks that begin with a block-header statement that end with a colon (:), and conclude with an END statement.

The following example code shows a block. Note that the FOR EACH statement starts the block.

FOR EACH Customer:
  DISPLAY CustNum Name.
END.

Blocks are typically used to manage transactions. A transaction is a set of changes to a database, or an undoable temp-table, variable, or class data member, which can be rolled back if something unexpected happens. Transactions are scoped to blocks and every block has default error handling built-in. When a transaction block is nested within another transaction block, it is called a subtransaction. When an error occurs, the first step is to undo the transaction or subtransaction. Thus, undoing a transaction reverses changes to database fields, undoable variables, class data members,and temp-table fields. You can further control error handling by defining explicit block error handling and by adding CATCH and FINALLY statements to the end of blocks.

Blocks are also used to create a scope for a database buffer. (You learn more about database buffers in a later topic.)

There are some general rules for determining what constitutes a block:

  • ABL statements such as FOR EACH, DO, and REPEAT define the start of a new block.
  • Every procedure itself constitutes a block.
  • A database trigger (block of ABL code that executes whenever a specific database event occurs) is a block of its own.
  • An internal procedure, user-defined function, constructor, method, and destructor define a block.

The complete list of block types is summarized in the following table:

Table 1. ABL block types
Block name Defined by
Simple DO block DO statement used to group multiple statements into a single execution unit
DO TRANSACTION block DO statement with the TRANSACTION option
DO ON <directive> block DO statement with a directive, such as ON ERROR
FOR block FOR statement
REPEAT block REPEAT statement
CATCH block CATCH statement
FINALLY block FINALLY statement
Procedure (External procedure) The implicit all-enclosing block of a procedure file
Internal procedure PROCEDURE statement
User-defined function FUNCTION statement
Database trigger procedure TRIGGER PROCEDURE statement in a procedure file
Database trigger block ON statement with a database event specified
User-interface trigger ON statement with a user-interface event specified
Class method (User-defined method) METHOD statement
Class constructor CONSTRUCTOR statement
Class destructor DESTRUCTOR statement
Class property PROPERTY statement and GET or SET definition
Class block (Class file) CLASS statement in a class file (.cls)

For more information, see Procedure Blocks and Data Access and Transactions and trigger and procedure blocks in Develop ABL Applications.