MF 

Local Data Item Declarations

Local data items are data items (also known as variables) that are declared in the procedure division body.

Syntax:

Syntax Rules:

  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
    • user-typedef-name
  2. For JVM COBOL type specifiers, refer to the Type Specifier link below.
  3. When declaring a local data item derived from a user type definition, that type definition must be an elementary data item.

General Rules:

  1. The scope of any inline local variable is from the point of declaration until the end of the innermost containing block, where paragraphs and sections are considered to be blocks.

Example

        01 names pic x(10) typedef.
        procedure division.
        declare i1 as binary-long
        declare name-list as names occurs 3
       *> Optionally, the variables can be initialised inline 
        declare c2 as binary-long = 5
        display c2
        perform varying k as binary-long from 4 by 1 until K > 6
          display k 
        end-perform