Problem:
A particular application allocates memory dynamically. The only access to the data is via a pointer in working-storage. There is no direct way to inspect the data values at the dynamic location.
Resolution:
Following is a small Cobol program which illustrates the solution.
data division.
working-storage section.
* Data to be inspected -- statically allocated to simplify the demo, but
* referenced only by a pointer.
01 data-of-interest pic x(50) value 'This is interesting data.'.
01 pointer-to-interest pointer.
linkage section.
* Linkage item with same structure as data to be inspected.
01 picture-of-data pic x(50).
procedure division.
* Simulate pointer access to dynamically allocated memory.
set pointer-to-interest to address of data-of-interest.
* Step animator to this statement:
display 'Step demo to here'.
* In Animator, "D"o:
* set address of picture-of-data to pointer-to-interest.
* Put cursor under picture-of-data and "Q"uery "C"ursor.
* Observe value of data addressed via pointer.
stop run.
The most important point is that picture-of-data has the same structure as data-of-interest. The overall effect is to overlay an arbitrary block of memory with the correct "map" in the linkage section. Linkage section items are not real items. They are simply descriptions of data stored elsewhere. The exact location of "elsewhere" is defined by a pointer which has a non-null value.
Note also that the procedure division does not have a USING clause which references the linkage section item. The linkage section item is simply an overlay template for a block of memory. That memory block is located by a mechanism other than the one used to pass call parameters.



