Page 1 of 1

COBOL VARIABLE ACCESSIBLE IN OTHER PROGRAM

PostPosted: Fri Oct 25, 2013 5:50 pm
by rbarnach1
Hi,

Is it possible to declare a variable in a COBOL program that is accessible in another non-cobol program?

Another question, how can I access an EXTERNAL VARIABLE declared to a C Program from COBOL?

Thanks,

Re: COBOL VARIABLE ACCESSIBLE IN OTHER PROGRAM

PostPosted: Fri Oct 25, 2013 5:57 pm
by Robert Sample
The z/OS Language Environment bookshelf has a book titled Writing Interlanguage Communication (ILC) Applications, and this book has a chapter specifically on C and COBOL communications. If you have not yet read this book and chapter, I recommend you start there.

Re: COBOL VARIABLE ACCESSIBLE IN OTHER PROGRAM

PostPosted: Fri Oct 25, 2013 6:21 pm
by rbarnach1
Robert Sample wrote:The z/OS Language Environment bookshelf has a book titled Writing Interlanguage Communication (ILC) Applications, and this book has a chapter specifically on C and COBOL communications. If you have not yet read this book and chapter, I recommend you start there.


Thanks, already browsed this source unfortunately, I don't see any answer to my inquiry.

I'm looking for similar functionality of C EXTERNAL VARIABLE declaration and applied it to COBOL. External variable declaration of COBOL is different than C.

Re: COBOL VARIABLE ACCESSIBLE IN OTHER PROGRAM

PostPosted: Fri Oct 25, 2013 6:39 pm
by Robert Sample
Is it possible to declare a variable in a COBOL program that is accessible in another non-cobol program?

Another question, how can I access an EXTERNAL VARIABLE declared to a C Program from COBOL?
If you read the manual I referenced, you would find that the answer to your questions is contained in (and I highlighted the key point)
4.4.3 Name Scope of External Data In programming languages, the name scope is defined as the portion of an application within which a particular declaration applies or is known. The name scope of external data differs between C and COBOL. The scope of external data under C is the load module; under COBOL, it is the enclave (or run unit). Figure 7 in topic 4.4.3.2 and Figure 8 in topic 4.4.3.3 illustrate these differences. Because the name scope for C and COBOL is different, external variables do not map between C and COBOL; external variables with the same name are considered separate between C and COBOL. If your application relies on the separation of external data, do not give the data the same name in both languages within a single application. If you give the data in each load module a different name, you can change the language mix in the application later, and your application still behaves as you expect it to.

4.4.3.1 DLL Considerations
4.4.3.2 Name Scope of External Data in a C Application
4.4.3.3 Name Scope of External Data in a COBOL Run Unit
So you pretty much need to pass variables between C and COBOL if you want to access the values -- using an EXTERNAL VARIABLE will not allow the C and COBOL programs to interact with the same data.