Progress
Programming
Handbook


Blocks and Context

The context of a block generally lies within the code defined by the beginning and end of the block. For an external procedure, the block beginning and end is the first and last statement in the file. For any other block, it is the block’s header and END statement. The context of an external procedure includes all data, widgets, triggers, and internal procedures that it defines. This is the only type of block that can define trigger and internal procedure blocks within its context. Thus, the external procedure context is often called the main block of the procedure. For example, the variable, balsum, is defined in the main block of p-blocks.p and can be modified by all statements and blocks defined within p-blocks.p, such as the trigger block. However, the internal procedure, SumBalances, defines an output parameter, balance-sum, that can only be modified within the context of its own block.

In general, any data or widgets that you define within the context of a procedure or trigger block, are available only to the statements of that procedure or trigger block. However, any data or widgets that you define within other types of blocks are actually part of the nearest enclosing procedure or trigger context, not the context of the block where they are defined.

For example, this procedure calculates the sum of customer balances using a variable, balance-sum, defined within a FOR block:

p-block1.p
FOR EACH Customer FIELDS (Balance): 
    DEFINE VARIABLE balance-sum AS DECIMAL INITIAL 0. 
    balance-sum = balance-sum + Balance. 
END. 
MESSAGE "Corporate Receivables Owed:"  
        STRING(balance-sum, "$>,>>>,>>>,>>9.99") VIEW-AS ALERT-BOX. 

However, balance-sum is actually assigned to the outer procedure context, so the MESSAGE statement, outside the FOR block, can also reference it.

Variable definitions are always assigned to the nearest enclosing procedure or trigger context, because Progress maintains the run-time values for variables in a single stack frame for the entire procedure or trigger. (Progress implements trigger blocks in much the same way as procedure blocks.) Thus, when a procedure A calls another procedure B, all of procedure A’s variable values are saved for the return from procedure B. However, when Progress executes a DO, FOR, or other type of block, no prior variable values are saved before the block executes. Likewise, there is no separate data context to maintain variables defined within these blocks. Therefore, Progress maintains the variables defined within these blocks as though they were defined directly in the procedure context.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095