DECLARE Statement (JVM COBOL)

Declares one or more local variables within the procedure division body. 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.

declare-statement

Syntax of the DECLARE statement with AS type-specifier
General syntax of the DECLARE statement

Example

       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")

See also the Local Variables sample, which is available from Start > All Programs > Micro Focus Visual COBOL > Samples , under Language Reference for JVM COBOL (Windows) or $COBDIR/demo (UNIX).

Further information

When no explicit type is declared for a variable, but the value is a non-integer numeric (for example declare var1 = 1.23), it is assumed to be of type float-long.

When 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.