Skip to main content

[archive] Variables local to paragraphs and perform using

  • February 15, 2008
  • 1 reply
  • 0 views

[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,

1 reply

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