Global Variables in VISUAL COBOL


I need to consume a .NET COM dll in Visual Cobol but there are certain problem which i am facing while trying to consume that.

I have native COBOL DLL which is internally calling a Native DLL which is interacting with the .NET COM component.

COBOL DLL(Base) --> Native COBOL DLL(Layer) --> .NET COM DLL

The call is driven by Base DLL to Layer DLL , The layer DLL create an object of COM class and execute the method and return the values to Layer Dll and dispose the object.

I need to retain the object and its value in Base Layer can someone suggest me solution for the same.

I am thinking of declaring a Global/external variable so that i can retain the values in the base layer. I can change the base layer so i am avoid using linkage variables.

Please suggest me the usage of Global or external variable in Visual COBOL


  • Verified Answer

    You can store the object in the Base class by defining it as an external item in both Base class and in Layer


    01 anInstance    object reference external.

    This data item will then be referring to the same memory storage and will be shared between the two.

    The object will only be valid on the second call if it has not been disposed of first.

    So if your called Layer and it created the instance of the COM class and stored it in anInstance then it would automatically still be available in Base even if Layer has been canceled.

    You could also just pass the object as a parameter back and forth between the Base and the Layer and store it as a non-external item in the base class.