Search code examples
ibm-midrange

For programs with identical name in the same library list, how to actively control which one to get called?


I have three libraries, A, B and C. Their order in the library is A on top of B, and B on top of C. There is a program Pa in library A and a program Pb in library B. Pa and Pb have the same name and parameter list, but their functions are slightly different. Now there is a program Pc in library C which calls Pa. But in order to achieve the desired result Pb should be called. The problem is that library A cannot be removed from the library list and cannot be moved under library B, and Pa cannot be deleted from library A. So is it possible to somehow hide Pa and make Pc call Pb instead? Program library names cannot be coded in the program so things have to be decided at runtime.


Solution

  • When you say Program library names cannot be coded in the program do you mean that it is because of shop standards or difficult due to implementation? Or something else that makes it undesirable?

    There are several approaches. I don't know what language you are writing in so I'll use pseudo-code to illustrate.

    1) Subroutines

     when condition = A
       do subrA
     when condition = B
       do subrB
     ...
    
     subrA
       call libA/pgmA parm(...)
    
     subrB
       call libB/pgmB parm(...)
    

    2) Dynamic calls

     define command char 128
    
     when condition = A
       command = 'call liba/pgma parm('
     when condition = B
       command = 'call libb/pgmb parm('
     end
    
     command = command + parm1 + ' ' + parm2 + ')'
     call qcmdexc (command 128)
    

    This works best if the called program does not return a value to the caller.