Search code examples
cobolmainframecics

In CICS where is the data in the Linkage Section of COBOL stored?


In CICS on z/OS I have some questions:

  • What data are stored on main storage? Auxiliary storage?
  • Where does data in DFHCOMMAREA under linkage section exists? Is it on main storage?
  • If I pass DFHCOMMAREA from one program to another, will that create extra copies of the data? (pass by-value or by-reference)

Solution

  • There's quite some confusion here concerning the different storage types. From a COBOL perspective you won't ever be worrying about main storage or auxiliary storage. Your COBOL-data lives in an address space made up of virtual storage which in turn is backed by main or auxiliary storage as the system sees fit.

    While your program will automatically allocate memory for items defined in WORKING STORAGE or LOCAL STORAGE sections, it will not do so for anything defined in the LINKAGE SECTION. For a LINKAGE SECTION item to be usable, two things are required:

    1. Some memory must be allocated
    2. The LINKAGE SECTION item must be associated with the address of that memory region.

    These two things can happen in different ways:

    • For items appearing in the USING of your PROCEDURE DIVISION the memory is provided by the calling program (or some other program up the callstack) and the compiler associates the item with the respective adresses passed in the parameter list provided by the caller. In the case of DFHCOMMAREA of a top-level CICS-program the calling program that allocates the memory is CICS itself.
    • You can "remap" memory from your e.g. WORKING STORAGE to a LINKAGE SECTION item by using SET ADDRESS OF
    • With more recent compilers you can also use ALLOCATE to dynamically request memory from your program and when used with a LINKAGE SECTION item it will also automatically associate the item with the memory

    As for your last question: passing parameters BY REFERENCE from one program to another will not create extra copies of that data. Passing BY VALUE or BY CONTENT will duplicate the data.