The germ for this post came from this question:

How can get the Library List from a Job Description?

I can use the DSPJOBD command to see the Job Description's library list, alas I can only display or print it. This does not make it easy for me to use in a program.

DSPJOBD JOBD(MYLIB/MYJOBD) Display Job Description Job description: MYJOBD Library: MYLIB Initial library list: Sequence number Library 10 QTEMP 20 MYLIB 30 ANOTHERLIB 40 QGPL

My first thought was to look for something using Db2 for i that would allow me to do this. After checking all the possibilities on Scott Forstie's Db2 for i poster I could not find a View, Table Function, etc. that would give me what I wanted. Therefore, I would have use an API.

The QWDRJOBD API retrieves information from the Job Description, including the library list. Unfortunately the area used for the library list is variable in length, and I will be able to retrieve that information if I call the API once to get the size of the information retrieved, and a second time to get the library list information.

I am calling this API from a RPG program. Let me start with the definitions:

01 **free 02 ctl-opt option(*nodebugio:*srcstmt:*nounref) ; 03 /copy qsysinc/qrpglesrc,qusec 04 /copy qsysinc/qrpglesrc,qwdrjobd 05 dcl-pr GetJobDinfo extpgm('QWDRJOBD') ; 06 *n char(65535) options(*varsize) ; //Receiver 07 *n int(10) const ; //Receiver length 08 *n char(8) const ; //API format 09 *n char(20) const ; //Job description 10 *n likeds(QUSEC) ; //Std API error DS 11 end-pr ; 12 dcl-ds JobD1 likeds(QWDD0100) ; 13 dcl-ds JobD2 likeds(QWDD0100) based(pJobd2) ; 14 dcl-s LibList char(11) based(pLibl) dim(250) ; 15 dcl-s JobDescription char(20) ; 16 dcl-s BytesAvailable int(10) ; 17 dcl-s Entries packed(3) ;

Line 1: In 2018 my RPG is always totally free format.

Line 2: My favorite control options.

Line 3: The definition of the standard API error data structure is in this source member. By using the /COPY I don't have to define it myself.

Line 4: Rather than define the data structure the results of the API are returned in I can use the data structure defined in this source member to ask as a template.

Lines 5 – 11: This is the procedure definition, parameter list, for the API. I am using my own name for the API in the program, therefore, I need to give the API's name in the EXTPGM .

Lines 6 – 10: I do not see the point in giving the API's parameters names if I am not going to use those names. If I do not give these subfields names I have to give *N instead.

Lines 12 and 13: I have defined the same data structure twice, using the data structure in the member QWDRJOBD as the template. I have defined the second one with a pointer, more about that later.

Line 14: This is the array that will contain the list of libraries in. Notice that is has a pointer.

Lines 15 – 17: This is the definition of various variables I will be using.

And now onto the part of the program that get the library list.

18 JobDescription = 'MYJOBD MYLIB' ; 19 JobD1 = *allx'00' ; 20 BytesAvailable = %size(JobD1) ; 21 dsply ('Size 1 = ' + %char(BytesAvailable)) ; 22 GetJobDInfo(JobD1:%size(JobD1):'JOBD0100':JobDescription:QUSEC) ; 23 BytesAvailable = JobD1.QWDBAVL ; 24 dsply ('Size 2 = ' + %char(BytesAvailable)) ; //test 25 pJobd2 = %alloc(JobD1.QWDBAVL) ; 26 JobD2 = *allx'00' ; 27 GetJobDInfo(JobD2:BytesAvailable:'JOBD0100':JobDescription:QUSEC) ; 28 Entries = JobD2.QWDNLILL ; 29 pLibl = pJobd2 + JobD2.QWDOILL ; 30 *inlr = *on ;

Line 18: The API requires that the qualified Job Description name is passed to it. It must be Job Description name, in positions 1 – 10, followed by the library name, starting at position 11.

Line 19: I am initializing the data structure that will contain the results from the API data structure with hexadecimal '00'. This is the equivalent of null.

Lines 20 and 21: These two lines are only here to show you, later, how the size of the returned information is different depending upon the Job Description.

Line 22: This first call of the API is only to get the number of bytes that could be retrieved in the result. The parameters I have used are:

Data structure to contain the results. I have to give a length for the results. The first time I call this API I have no idea how long the results, including the library list will be. I can only use the length of the data structure, knowing that the library list is not included. Result format. For this API there is only one value that can be used. Qualified Job Description name. Standard API error data structure.

Line 23: Now I have the length of all the results, in the data structure subfield QWDBAVL .

Line 24: This is only here for testing, to show that the value of the bytes available is larger than the length of the data structure.

Line 25: The %ALLOC operation code allocates a space in memory that I will use for the results when we call the API again.

Line 26: The second results data structure in initialized with nulls.

Line 27: This time I call the API with the second result data structure, JobD2 , to contain my results.

Line 28: The subfield QWDNLILL contains the number libraries in the library list.

Line 29: The pointer for the library list array is set to start at the memory space starting at the start of the pointer plus the offset to the library list information, subfield QWOFILL .

When I run this for the same Job Description I used with the DSPJOBD command, MYJOBD in MYLIB I get the following:

DSPLY Size 1 = 452 DSPLY Size 2 = 502 EVAL LibList LIBLIST(1) = 'QTEMP ' LIBLIST(2) = 'MYLIB ' LIBLIST(3) = 'ANOTHERLIB ' LIBLIST(4) = 'QGPL ' LIBLIST(5) = '*NONE ' LIBLIST(6) = ' ' LIBLIST(7) = ' ' > EVAL Entries ENTRIES = 004.

The DSPLY operations show how the size of the results for all the data, including the library list, is bigger than the result data structure.

If I run the program for the Job Description QDFTJOBD in my library list I can see the get:

DSPLY Size 1 = 452 DSPLY Size 2 = 469 > EVAL LibList LIBLIST(1) = '*SYSVAL ' LIBLIST(2) = '*NONE ' LIBLIST(3) = ' ' LIBLIST(4) = ' ' LIBLIST(5) = ' ' LIBLIST(6) = ' ' LIBLIST(7) = ' ' > EVAL Entries ENTRIES = 001.

Even though it is cumbersome to have to call the API twice this shows how easy it is to get the library list from the Job Description.

You can learn more about the QWDRJOBD API from the IBM website here.

This article was written for IBM i 7.3, and should work for earlier releases too.