In my life as a programmer I have only coded a little assembler, but one of the modules I have enjoyed most I will share with you this week. Way back in week 4/2005 I wrote about how to create a global area which all tasks running in the same CICS region can share. To use the same trick in TSO or in BATCH (or a homemade started task) you have to use an assembler program to call the LOAD-macro. This is what the following assembler program does.
If you are a very observant reader of my weekly tip and has a sharp memory you will immediately point out that the method described in week 51/2008 can be used instead. You are right, but the problem is that this method only allows you to store 16 bytes. And then you will be forced to allocate a larger area anyway. This is most simply done using the LOAD-macro:
Assembler has never been easy to neither write or read so I will try to explain more deeply what the different parameters are used for in order to make you able to use the program efficiently. The parameter LMODNAME is almost self-explanatory and must of course hold the name of the load module you want to load into storage. Create this load-module like it is described in the tip from week 4/2005. It is the size of this load module which decides the amount of storage you are allocating. The parameter LMODADDR holds the address of the load module in storage after the call to MYLOAD. Before you call the program you must set the parameter DCBADDR to 0 which will make the program search for the load module in the normal MVS search order. The parameter FUNCTION must be set to 0 in order to perform a LOAD. Using DCBADDR and FUNCTION you can perform other stuff. Please send me a mail if you want to know more about those two parameters.
After calling MYLOAD you must examine the return code which is either set to 0 (everything went OK) or 806 (the load module was not found or you have used DCBADDR or FUNCTION incorrect). The first time you call MYLOAD the load module is placed in storage. At all following calls using the same LMODNAME the LOAD-macro will detect that the load module is already in storage and just return the address in LMODADDR. One exception is if the load module has the attribute NOREUS. In this case you will get a new storage area allocated and have another address returned, which will make this tip useless.
I use this tip in ISPF instead of ISPF SHARED POOL variables, because these variables are only global within the same APPLID. When you use ISPF in combination with this tip you must be aware that when the split session that performed the initial load dies then the storage area associated with the load module dies as well. This is normally not a problem, but very nice to know.
At last I will present to you a piece of PLI code illustrating the use of MYLOAD:
It is important to have an eyecatcher at the beginning of the global area to make it possible for you to distinguish the first call to MYLOAD from all the following calls. In this example the text GLOBALAREA in the first ten bytes is used as eyecatcher. Please remember that the size of the variable globalArea must not exceed the size of MYLMOD. Otherwise you may receive a 0C4 abend.