PERFORM Statement

Controls execution of a statement block in the scope of the PERFORM statement. This statement can also process each element of an array or collection.

perform-statement

Note: Other formats of this statement are available. See Statements in the COBOL Language Reference.

Further information

For JVM COBOL, the USING phrase is only applicable to JVM version 1.7 and onwards.

The type-specifier section of the PERFORM..USING phrase must specify a type that implements the System.IDisposable interface (.NET) or the java.lang.AutoCloseable interface (JVM version 1.7), and must specify an initial value via the = expression syntax.

Example of local declaration within an iterator

A variable can be declared at the point of use in an iterator, and its scope is until the end of the perform block.

      *>   In this case, the scope of i is until the end of the perform block. 
           perform varying i as binary-long from 1 by 1 until i > 10
               display i
           end-perform

      *>   So the i in the following perform block is a new instance of i,
      *>   independent of the i in the preceding perform block.
           perform varying i as binary-short from 0 by 1 until i > 10
               display i
           end-perform

Here, k is declared inline to iterate through a dictionary. Again, it is in scope until the corresponding end-perform.

    01 dict1 dictionary[string string].
           create dict1
           write dict1 from "Anthony" key "A"
           write dict1 from "Brian" key "B"
           write dict1 from "Charles" key "C"
           perform varying key k as string value val as string through dict1
               display k ":" val
           end-perform
           perform varying value val as string through dict1
               display val
           end-perform
           perform varying key k as string through dict1
               display k
           end-perform

See also the Local Variables sample, available from $COBDIR/demo.