.Net Cobol

Is the local-storage section  a "best practice" place to define all of your method variables?  For example:

method-id Encrypt.
       local-storage section.
       01  clearBytes binary-char unsigned occurs any.
       01  pdb type Rfc2898DeriveBytes.
       01  nb binary-char unsigned occurs 13.
       01  ms type MemoryStream value new MemoryStream.
       01  cs type CryptoStream.
       01  num binary-short.
       01  str type StringBuilder value new StringBuilder.

  • Verified Answer

    Yes, local-storage is where you define your variables that are local to the scope of the method. It is not required to use the local-storage section header in a method as that is the default.

    You can also define variables within the procedure division using the declare statement.

    declare myvar as string = "test"

    or within the scope of a perform like:

    perform using myvar as string



    where the variable will go out of scope after the perform exits.

    If you would like to define global variables that can be accessed by all methods then you would define them in the working-storage section of the class.

    If you would like them to be shared by all instances of a class then you can place them in working-storage and add the static keyword.