Dump working storage for use in a Unit Test
I would like to unit test a program that is several layers deep in a large monolithic application. The program undergoing change and requiring testing has a lengthy list of fields that needs to be supplied via its Linkage Section. Is there a way I capture the contents of storage during execution, perhaps in debug mode, so I can more easily use these values in my unit test?
We've come up with a couple of ideas for how you might save and restore data areas from within a COBOL program, which might allow you to do what you wanted. Both approaches make use of special byte-stream-io APIs that are available in Micro Focus COBOL to read and write the data. Each would require some coding on your part; I'm going to attach a couple of examples to give you a clear idea of how this might be done.
Sample 1 in the attached zip file is streamio-memfromarray.cbl, and was conceived and developed by my colleague Chris Glazier. It shows an idea for defining an array containing references to each memory (01 level) item that needs to be saved. These could be 01 levels within Working Storage of a program, or items that were passed into the program via Linkage Section. The example loops through the array, saving memory for these items to a file, and then later reads them back from the file. You could call this program as a child of an existing program where you needed to save items.
Sample 2 is streamio-memrange.cbl. Chris also wrote this one, based on an idea suggested by Development. It takes a slightly different approach, and assumes that you only need to save items that are in working storage (rather than those passed in linkage) and also that the items needing to be saved are all together in one contiguous section of memory. The program uses COBOL constant (78 Level) items that are inserted before and after the items to be saved, and these are used to calculate the size of the memory to save.
Please let me know if you have any questions about the attached examples.