Page 1 of 1

Use the same input file in Sub program and main program.

Posted: Mon Oct 16, 2017 12:55 pm
by Anil
Dear All,

I have one question. I want to use one input file in sub-program, this file is used in main program as well. How can I do that? Please help.

Re: Use the same input file in Sub program and main program.

Posted: Mon Oct 16, 2017 6:27 pm
by Robert Sample
Research the EXTERNAL clause in the Enterprise COBOL Language Reference manual (page 178 of the 6.2 version). This is not necessarily a wise thing to do.

Re: Use the same input file in Sub program and main program.

Posted: Tue Oct 17, 2017 12:18 am
by Anil
Read about EXTERNAL clause. Is not it for variables and not files?

Re: Use the same input file in Sub program and main program.

Posted: Tue Oct 17, 2017 12:58 am
by Robert Sample
Did you not read page 178+ of the 6.2 version of the manual? It says
EXTERNAL clause
The EXTERNAL clause specifies that a file connector is external, and permits communication between two programs by the sharing of files.
A file connector is external if the storage associated with that file is associated with the run unit rather than with any particular program within the run unit. An external file can be referenced by any program in the run unit that describes the file. References to an external file from different programs that use separate descriptions of the file are always to the same file. In a run unit, there is only one representative of an external file.
In the FILE SECTION, the EXTERNAL clause can be specified only in file description entries.
The records appearing in the file description entry need not have the same name in corresponding external file description entries. In addition, the number of such records need not be the same in corresponding file description entries.
Use of the EXTERNAL clause does not imply that the associated file-name is a global name. See Sharing data by using the EXTERNAL clause in the Enterprise COBOL Programming Guide for specific information about the use of the EXTERNAL clause.
So the manual EXPLICITLY tells you EXTERNAL is for files as well as variables. Depending upon the specifics of what you want to do, you may need GLOBAL as well, but you need to spend some time reading the Programming Guide manual to know which (or both) are better for your needs.

Re: Use the same input file in Sub program and main program.

Posted: Sat Oct 28, 2017 5:57 pm
by Anil
Thanks Robert.

So in CICS will all the files be defined as EXTERNAL as they are used by so many programs?

Re: Use the same input file in Sub program and main program.

Posted: Sat Oct 28, 2017 6:50 pm
by nicc
That is a new question - start a new topic but I suggest that you get familiar with the fundamentals of CICS before starting to ask such questions as that study will probably provide you with the answers that you are seeking.

Re: Use the same input file in Sub program and main program.

Posted: Sun Oct 29, 2017 8:19 am
by Robert Sample
Since you do not define any files in a COBOL program running under CICS, your question is pointless. CICS defines all files; the program defines none.

Re: Use the same input file in Sub program and main program.

Posted: Fri Nov 03, 2017 11:51 am
by Anil
Thanks Robert.