Page 1 of 1

Containing programs

PostPosted: Fri Feb 17, 2012 10:28 pm
by Alison Oliveira
Containing programs is the same as programs that contains sub-programs or procedures???

Re: Containing programs

PostPosted: Fri Feb 17, 2012 10:35 pm
by Robert Sample
What is the context of your usage? I've never heard of using "containing program" for a main or calling program -- but then, I've only been working with COBOL and mainframes for over 35 years so far.

Re: Containing programs

PostPosted: Fri Feb 17, 2012 10:41 pm
by Alison Oliveira
I read in a manual... :
"Use the COMMOM attribute on the PROGRAM-ID clause to specify that your program can be called by the containing program or by any program or by any program in the containing program..."

I am talking about this "containing program"...
Thanks for help!

Re: Containing programs

PostPosted: Fri Feb 17, 2012 11:03 pm
by Akatsukami
IIRC, this is ANSI-85 COBOL. A containing program would have a contained (the more common term is "nested") program before its END PROGRAM statement.

(ETA: I think that this feature is strictly for CICS, but not being a CICS programmer I'm not certain.)

Re: Containing programs

PostPosted: Fri Feb 17, 2012 11:07 pm
by Robert Sample
Containing programs have nested programs. A nested program is a subprogram, but not all subprograms are nested. A subprogram source can be completely independent of the calling program. In fact, the calling program can call the subprogram dynamically, so the subprogram may not even be in the same load library as the calling program.

Re: Containing programs

PostPosted: Sun Feb 19, 2012 9:27 pm
by Monitor
This is correct : Cobol -85.
This is not correct: for CICS only, as it is COBOL STANDARD, it is valid for all programs.
Nested programs is a way of structuring a program in different programs instead of having paragraphs. A mixture is probably most common.
Nested programs makes it possible to have separate Working-Storage Sections for each program, thus (1) hiding/protections data and (2) no need for unique names, each contained program is a comletely separate program. You may call the nested programs with parameters, as always, which you cant when using paragraphs, BUT you can also expose variables from the outer program, My-Program, so they are available in the other, contained, programs, by marking the 01 or 77 level as GLOBAL.

A small example, but more details to read in the manual of course!

Id Division.
Program-Id. My-Program.
Working-Storage Section
77 My-Global-Data Pic xxxx  GLOBAL.
01 Param1.
   . . .
Procedure Division
    . . .
    Call 'My-Nested-Program1' Using Param1
    Call 'My-Common-Program'
* This call is valid only if the called program has the COMMON attribute
* as it is not a direct contained program. It is contained in the
* My-Nested-Program1
    . . .
    GoBack
.
Id Division.
Program-Id. My-Nested-Program1.
Working-Storage Section
Linkage Section.
01 Param1.
   . . .
Procedure Division Using Param1.
    . . .
* No declaration needed here
    If My-Global-Data......
    Call 'My-Common-Program' 
* This call would have been valid without the COMMON attribute, since it is a direct contained program.
    . . .
    GoBack
.
Id Division.
Program-Id. My-Common-Program Is COMMON.
Working-Storage Section
. . .

   . . .
Procedure Division
    . . .
    . . .
   
    . . .
    GoBack
End Program My-Common-Program.
End Program My Nested-Program1.
End Program My-Program.