Context
Procedure Division DECLARE Statement (.NET COBOL) PERFORM Statement (.NET COBOL) TRY Statement (.NET COBOL)
declare i1 as binary-long display i1 *> Optionally, the variables can be initialised inline declare c2 as condition-value = true display c2 declare string-list2 as string occurs 3 = table of string("Bill", "Ben", "LittleWeed") ************************************************************************** * Iteration Variables ************************************************************************** *> A variable can be declared at the point of use in an iterator. *> In this case the scope of i will be until the end-perform. perform varying i as binary-long from 1 by 1 until i > 10 display i end-perform ************************************************************************** * Exception Variables ************************************************************************** *> The example below shows that you can declare e at the point of use. *> It is in scope until the end-try. try display "exception test" catch e as type Exception display e::Message end-try
See also the Local Variables sample, which is available from Start > All Programs > Micro Focus Visual COBOL > Samples, under COBOL for .NET .
The scope of any inline local variable is from the point of declaration until the end of the innermost containing block, where paragraphs, sections and the whole method are considered to be blocks.
When declaring a local item where a type name is referenced that can be resolved to more than one type, if one of those types is declared within the current compilation unit, and the other is defined externally, it is assumed that the reference is to the internal type. If both types are declared within the current compilation unit, or both are defined externally, then an error is generated.