Highlighted
Absent Member.
Absent Member.
259 views

[archive] Variables local to paragraphs and perform using

[Migrated content. Thread originally posted on 14 February 2008]

Hi,

mi experience tells that one of the worst things in Cobol is that any variable is PUBLIC to any paragraph in a program.

In the Cobol world we all have tons of OLD programs, sometimes written by retired programmers, that are difficult to mantain. Add to this scenario the "cobolers" bad habits:
1.write "not self-sufficient" paragraphs
2.re-use variables (exspecially iterators) declared in ws by someone else, used somewhere else, modifying their content in an "arbitrary" way (any modification of a working variable is "arbitrary" in this scenario: this can put your program in an inconsistent state)

To deal with this issues, I suggest to introduce the concept of local variable declaration, at least at paragraph level. I mean, the variable exists ONLY in the paragraph boundaries:

my-paragraph.
local-storage section.
77 my-iterator pic 9(02) comp-x.
77 my-string pic x(10).
procedure division.
..procedural-code..

peraphs a lighter way is better, simply writing:

my-paragraph.
77 my-iterator pic 9(02) comp-x.
77 my-string pic x(10).

..procedural-code..

add to this the ability to invoke a paragraph with using/returning parameters:

perform my-paragraph using par-1 giving result.

my-paragraph using my-par-1.
77 my-par-1 pic x(10).
77 my-result pic 9(01).
..procedural-code..
exit paragraph returning my-result.

I know that OO cobol offers its own way to solve these problems, but I think that cobol programmers will appreciate a way -like this- to add consistency and "firmness" to their OLD programs...

ciao,
0 Likes
1 Reply
Highlighted
Absent Member.
Absent Member.

RE: [archive] Variables local to paragraphs and perform using

Seems like a great idea to me. Wondered for years why we didn't have it in the 80's.
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.