Highlighted
Contributor.
Contributor.
673 views

.Net Cobol

Jump to solution

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.

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: .Net Cobol

Jump to solution

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

  statements

end-perform

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.

View solution in original post

0 Likes
1 Reply
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: .Net Cobol

Jump to solution

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

  statements

end-perform

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.

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.