3

We control on what objects our programs on the as400 work, by running them with different liblists. But some operations cannot be directly controlled by this. Therefore, my program needs to read the liblist and decide on some of the libraries in it, how to act.

I could not find any api to read the liblist entries from within a program. What I would expect, is some kind of api that lets me iterate through the liblist entries by priority or gives me an array with them in the order given by the liblist. I'd prefer RPG or CL if possible, but other ILE languages are available, too.

(If you wonder, why I'm trying to do this, I asked another question, that explaines the enclosing problem I'm faced with: How can I create a DTAQ in one of two different libs, controlled by the jobs liblist? But the liblist parsing is an approach to solve that one and is an individual problem).

Community
  • 1
  • 1
kratenko
  • 7,354
  • 4
  • 36
  • 61

4 Answers4

5

You can use the QUSRJOBI API to retrieve the library list for a job. You can also use the CL command ADDLIBLE and monitor for error message CPF2103 (library already exists in library list).

Morpheus
  • 86
  • 1
  • The QUSRJOBI API offers formats JOBI0700 and JOBI0750 which will give you the library list information for the current job or another specified job. – WarrenT Jul 16 '12 at 18:05
  • the `QUSTJOBI` works great for RPG. The `ADDLIBLE` should be a working hack, too, but I don't want to mess with my liblist. For a CL-solution `RTVJOBA` works great (taken from answer by @JamesA). – kratenko Jul 16 '12 at 18:11
4

The List Objects (QUSLOBJ) API can be used to retrieve the library list.

Object and library name
When *ALLUSR is specified with a library name of *LIBL and an object type parameter of *LIB, a list of all user libraries in the thread's library name space is returned. When *LIBL is specified, the auxiliary storage pool (ASP) device name must be an asterisk (*) if the auxiliary storage pool (ASP) control parameter is specified. Refer to *ALLUSR in the description of the second 10 characters of this parameter for a definition of user libraries.

The Change Library List (QLICHGLL) API can be used to change the library list.

The RTVJOBA command can retrieve the SYSLIBL, CURLIB, and USRLIBL.


The book APIs at work, Chapter 3, List APIs has a lot of information that may help you.

James Allman
  • 40,573
  • 11
  • 57
  • 70
  • From ILE RPG you might want to call a CLLE procedure (with callp) that will perform the RTVJOBA command. Or perhaps faster, call the system API QUSRJOBI as suggested by @Morpheus. – WarrenT Jul 16 '12 at 18:07
  • Wow, `QUSLOBJ` feels like a weird API to me; does not seem to have any outputparms despite the error code. `RTVJOBA` works great for CL, thanks once again for a good answer, @JamesA. I'll actually use Morpheus' answer for an RPG service program and yours for two CL-procedures. Can't accept both, though... – kratenko Jul 16 '12 at 18:18
  • @JamesA could you elaborate on how the List Objects API can return a library list? The only mention of library lists that I can see in the reference page is in the use of *LIBL as an object name quailfier. – WarrenT Jul 16 '12 at 18:19
  • @WarrenT I updated my answer with the information from the API documentation. – James Allman Jul 16 '12 at 19:01
  • Have you tried it with *ALLUSR, *LIBL and *LIB? I get a list in the space of all user libraries accessible to the job, i.e., a very long list of libraries. – user2338816 Jan 18 '16 at 00:37
2

A simpler alternative approach might be worthwhile, depending on your situation. If you know the target libraries in advance, perhaps you could create a data area in each of those libraries, containing the library name. Your program will read whichever data area it finds first on the library list, and will give you the name of the library for you to create your data queue.

It's not sophisticated, but it is effective and very simple, and also therefore easier to code/debug/maintain.

WarrenT
  • 4,502
  • 19
  • 27
  • Right, that should work, too. Might be really efficient (for my related problem), since I do not need to get and parse that >2kB string. But right now I prefer a solution for which I needn't create extra objects. I try to work with what there allready is in our system -- keeps the admins happy (still, +1). – kratenko Jul 16 '12 at 18:26
  • Or perhaps there is some other object that would already appear in each of those libraries. In which case you could do a RTVOBJA, to find out which is found first on the *LIBL. This might be better & less code since you will not have to parse the long string checking for specific (harcoded?) library names. – WarrenT Jul 16 '12 at 18:46
0

Kratenko, if you want simpler and lesser code alternative than API. Create simple CL pgm that you can call within your rpg. Your cl can have RTVJOBA (there's parm to get libl). You might get many libs from that, and you need to parse and identify the specific lib you want? About identifying you must know one of the qualifiers. Do you want the lib where your pgm runs or the lib where "some" file resides? If yes on any, then you can use RTVOBJD to get specific lib. Then use that lib in your CRTDTAQ cmds.

  • Rather than a "CL pgm", an ILE CL module might be better, perhaps in a service program. Once created, these can be used very much like IBM-supplied APIs except that you get to define parameters and error handling in whatever way fits best for you. – user2338816 Jan 23 '16 at 01:08