Obviously, when you have a program that contains IMS calls, you need to pass a PSB to that program that contains all of the necessary PCBs to give the program the required access to the different databases that it references. What is not so obvious is what you need to do if a program calls an external subroutine that needs to do IMS calls.
Actually, it's pretty simple. If a program calls an external subroutine that does IMS calls then the program is an IMS program whether the program itself does IMS calls or not. In either case, the program needs to be referenced in the JCL in the same way as any other IMS program and the program needs a PSB.
The PSB passed to the program needs to contain PCBs for any databases that it accesses directly (if it has any IMS calls itself) as well as PCBs that are needed by any external subroutines for their database accesses.
The main program then needs to pass the necessary PCBs to the appropriate external sub-programs so that they can be used to access the necessary databases.
While the PSB needs to include PCBs for all necessary database accesses that are performed by the program and any external subroutines, it is not necessary to always provide separate PCBs for each module that references the same database. Each PCB effectively represents a pointer to a location within the database. Unless different modules need to retain their positioning between calls, they can use the same PCB as other modules accessing the same database. You just need to make sure that the PCB allows all of the types of access required by all of the modules that use it.
If you have several programs that don't do IMS calls themselves but which all call a common external sub-routine that does then you can set up a single PSB that provides the necessary accesses required by that module and use the PSB with all of the programs that call the module.
This article written by Stephen Chapman, Felgall Pty Ltd.