Using QUSRJOBI to retrieve Library list vs SQL.

We will be adding additional examples of how SQL is taking over, where once only API’s could do the work.

Simplifying code and helping to build a stronger developer, with the tools required to be successful.

 

QUSRJOBI information –Format JOBI0700 is used to retrieve Library list information.

QUSRJOBI – Example(s) from the Forum: Code400 – Forum Post

Scott Klement example: Scott Klement APi writeup

From IBM: QUSRJOBI information

Code Sample:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
==>

d SkipLibs        s              3  0
CURRENT         s             10

//
//  External Calls
//

d $GetLibList     PR                  ExtPgm('QUSRJOBI')
d RcvVar                     32767    Options(*VarSize)
d LengthRcv                     10I 0 Const
d FormatName                     8A   Const
d QualJobName                   26    Const
d InternalJobId                 16    Const
d Error_ds                      15

//
//  DATA Structures
//

d ds_job10700     Ds         32767
d  BYTRTN                       10i 0
d  BYTVAL                       10i 0
d  QJOBNM                 9     34
d  JOBNAM                 9     18
d  USRNAM                19     28
d  JOBNBR                29     34
d  INTID                 35     50
d  JOBSTS                51     60
d  JOBTYP                61     61
d  SUBTYP                62     62
d  RESRV                 63     64
d  SYSLIB                       10i 0
d  PRDLIB                       10i 0
d  CURLIB                       10i 0
d  USRLIB                       10i 0
d  LIB1                  81    336

d ds_Error        Ds            15
d  BytesProvided                10I 0 inz(%SIZE(ds_Error))
d  BytesAvail                   10I 0
d  ErrorId                       7

/Free

//------------------------------------------------
//       C a l c u l a t i o n  S p e c s
//------------------------------------------------

$getLibList(ds_job10700:%SIZE(ds_job10700):'JOBI0700'
:'*' : *Blanks : ds_Error);

SkipLibs  = (SysLib  + PrdLib)*11;
CURRENT   = %TRIM(%subst(LIB1:SkipLibs + 1:10));

IF curlib = *zeros;
CURRENT = '*NONE';
endif;

Dsply CURRENT;
*inlr = *ON;
/end-free
//--------------------------------------------------------
QUSRJOBI – Retrieve Library List

The Retrieve Job Information (QUSRJOBI) API retrieves specific information about a job.

 

Now for the SQL

1
select * from qsys2.library_List_info

This will return in a list format as (for example):

ORDINAL_POSITION      SCHEMA_NAME
1                                             QSYSSLIC
2                                             QSYS
3                                            QSYS2
4                                            QUSRSYS
5                                            QHLPSYS
6                                            QGPL
7                                            etc…

To place into an RPG Program would be as simple as:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
H dftactgrp( *no ) OPTION(*NODEBUGIO) BndDir( 'QC2LE' )
F********************************************************************
F* Program Name -- LIBRARYLIST
F* Written BY Programmers.io  DATE Written -- 03.17.2020
F********************************************************************
F* List ALL modifications TO this program below IN the
F* format OF initials, DATE & description OF your CHANGE.
F*
F* Initials DATE Description
F* x.x.x. xx/xx/xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
F********************************************************************
F* *-* PROGRAM DESCRIPTION *-*
F*
F* This program will:
F*
F********************************************************************
*
* Defined VARIABLES
*
d i s 10i 0 inz
d MaxItemLines s 10i 0 inz(200)
d MyOutput s 20 inz
d reply s 1 inz
d RowCount s 10i 0 inz
*-----------------------------------------------------------------
* program STATUS dataarea
*-----------------------------------------------------------------
d PgmSts sds
d P1User 254 263
d @PGM *PROC
d @JOB 244 253
*
d C1 ds Dim(200) Qualified
d sequenceNumber...
d 10i 0
d schemaName 10a

EXEC SQL SET OPTION commit=*NONE,datfmt=*iso,
closqlcsr=*ENDMOD;

*inlr = *ON;

EXEC SQL
DECLARE c1 scroll cursor FOR
SELECT * FROM qsys2.library_List_info
FOR READ ONLY;

EXEC SQL OPEN c1;
EXEC SQL fetch FIRST FROM C1 FOR :MaxItemLines ROWS INTO :C1;
EXEC SQL GET diagnostics :RowCount = ROW_COUNT;
DoW RowCount <> 0;
FOR i = 1 TO RowCount;
myOutput = %TRIM(%CHAR(c1(i).sequenceNumber)) + '_' +
%TRIM(c1(i).schemaName);
dsply myOutput;
EndFor;
EXEC SQL fetch NEXT FROM C1 FOR :MaxItemLines ROWS INTO :C1;
EXEC SQL GET diagnostics :RowCount = ROW_COUNT;
EndDo;
EXEC SQL close C1;

//********************************************************************
/End-Free

Download:

Library List using SQL

Retrieve library list within RPGLE using SQL

 

We would prefer that you turn this into an external procedure and create a parameter list as actions dictate.

 

 

 

SQL Vs. QUSRJOBI (Retrieving Library List)
Tagged on:     

Leave a Reply

Your email address will not be published. Required fields are marked *