God_of_Thunder
God_of_Thunder

Reputation: 763

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.

Upvotes: 1

Views: 144

Answers (3)

user2338816
user2338816

Reputation: 2163

A library list consists of four components: system portion, product libraries, current library and user portion. Under normal circumstances, the system ortion should not be modified. (It should be restricted from modification.) But all other portions are open.

A most likely spot would be in the "product libraries" portion. This can hold two libraries though it's most common to see one or none. If you create a *CMD or *MENU object, you can assign a product library for the object. (Current library can also be set.) So, for a command, whenever that command is run, the associated product library is added to the library list until the command finishes. At that time, the library is removed. If these are CL programs, it's possible that libraries are being added to and removed from your library list regularly whether you know it or not.

The general logic for product libraries is to add the library in the first open spot. If both spots are occupied, then retrieve the top library, move the bottom one up and add your library at the bottom. When your program finishes reverse the process so that the product libraries are just as they were when you started.

Product libraries are above current library and the user portion in the library list. Use the Change Library List (QLICHGLL) API to set product libraries.

Upvotes: 1

Buck Calabro
Buck Calabro

Reputation: 7648

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.

Upvotes: 3

dmc
dmc

Reputation: 2684

You're asking if you can make the system override the library list without telling the system which library to use. I don't know how that would be possible.

I think you're going to have to qualify your program call with library B. If you can't hardcode the library name in your program, maybe you can softcode it somehow.

/* CL example */
dcl &libname *char 10
rtvdtaara dtaara(WHICH_LIB) rtnvar(&libname)
call pgm(&libname/PGMNAME) parm(...)

So now in addition to maintaining your library list you have to maintain this data area (or whatever you use to hold onto the library name).

Upvotes: 2

Related Questions