MainframeSupports
tip week 24/2002:

COBOL has a reputation of being a dull language in which it is impossible to do "nasty" things like accessing main storage beyond working storage. This is actually not true and this tip will show you how.

Before you start you must find out which kind of information you are looking for. It could be the name of the job running your program. Then you must find out where this information can be accessed. And then you can start coding. You can also make a program that shows you the contens at a given address. Then it is important to known, that a lot of main storage are protected and that your program abends if you try to access protected storage.

Now let's do some coding. You will need some work variables:

01  WORK-POINTER POINTER.
01  AREA-ADDRESS PIC 9(9) COMP.
01  FILLER REDEFINES AREA-ADDRESS.
  02  AREA-POINTER POINTER.

Work-pointer is just an ordinary pointer variable in COBOL. Area-address and area-pointer are two variables located at exactly the same address. In this way you can assign a value to area-address which exactly matches the address in main storage you want to access and area-pointer will automatically point to this address.

In linkage section you must define the areas or control blocks, you want to access. This is just an example:

01  PSA.
  02  FILLER PIC X(16).
  02  CVT-POINTER POINTER.
01  CVT.
  02  FILLER PIC X(556).
  02  ASVT-POINTER POINTER.

For those of you who is new to MVS control blocks PSA is a control block always located at address 0. The CVT is a control block containing pointers to a lot of other MVS control blocks. Asvt-pointer is just one of those control blocks.

Now it is our objective to make the variable work-pointer point to the same address as asvt-pointer does. This is achieved in the following way:

MOVE 0 TO AREA-ADDRESS.
SET ADDRESS OF PSA TO AREA-POINTER.
DISPLAY 'PSA=' PSA.

SET ADDRESS OF CVT TO CVT-POINTER.
DISPLAY 'CVT=' CVT.

SET WORK-POINTER TO ASVT-POINTER.

At first the starting address to access is set to 0. Then COBOL is told to locate PSA at the address which is pointed to by area-pointer. Then the contens of the PSA is displayed. This is done just to show that we can do this, because PSA mostly contains non-printable characters. Next COBOL is told to locate CVT at the address which is pointed to by the variable cvt-pointer and now the CVT is displayed. And finally the goal is reached as work-pointer is set to point to the same address as asvt-pointer. It is worth noticing that pointer variables are assigned by using SET and not MOVE.

From this point only your imagination (and protected main storage) sets the limits to what main storage you want to access using COBOL. Information about MVS control blocks and their contens can be found in BookManager among the MVS-books. They have a name containing the words Data Areas and there are about two to four books. They are very specific and if you don't know where to start looking for a certain piece of storage then it is much faster to ask a systems programmer with a long and fresh experience in MVS.

Previous tip in english        Sidste danske tip        Tip list