MF 

The DECLARE Statement

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.

General Formats for Format 1

Syntax for format 1 of the DECLARE statement
MFNETJVM 

General Formats for Format 2

Syntax for format 2 of the DECLARE statement

General Rules for All Formats

  1. If value-expression is specified, the item is initialized to that value; otherwise the content is undefined.

General Rules for Format 1

  1. For native COBOL, type-specifier can be one of the following:
    • BINARY-CHAR [UNSIGNED]
    • BINARY-SHORT [UNSIGNED]
    • BINARY-LONG [UNSIGNED]
    • BINARY-DOUBLE [UNSIGNED]
    • FLOAT-SHORT
    • FLOAT-LONG
    • POINTER
    • user-typedef-name
  2. For .NET COBOL type specifiers, refer to the Type Specifier link below.
  3. In native COBOL, the behavior of local data items is determined by the DECLARE directive. Default behavior (DECLARE"2") allocates local items afresh each time a paragraph or section is entered. DECLARE"1" (only supported for native COBOL) emulates previous behavior, where locally declared data items are added to local-storage, but are not allocated afresh each time a paragraph or section is entered.

Example

       01 names pic x(10) typedef.
       ...
       declare i1 as binary-long
       display i1 
         
       *>   Optionally, the variables can be initialised inline 
        declare c2 as binary-long = 5
        display c2

        declare name-list as names occurs 3