Even though many people say the iSeries 400 is a closed and proprietary
system, it does offer a huge number of "openness" application program interfaces
(APIs).
I remember years ago when IBM Rochester held the first meetings to discuss
the idea of adding APIs to the system. The first set of APIs included User
Space, User Index, and Data Queue APIs. At the time, all the API names were
designed to begin with the letters QUS. The "US" identifier stood for
"USER"--IBM's term for "programmer" back then.
Today, there are so many APIs that the manual itself is over 3,000 pages
long! I don't know the exact number of APIs available in OS/400, but it's
hundreds and hundreds if not well over a thousand by now. So the naming
convention of QUSxxxxx has long since been retired.
Rather than attempt to keep track of all the APIs and their purpose in life,
I've tried to maintain an easy way to search and review the APIs I may need. I
keep a copy of the OS/400 System API Reference manual in PDF form on my
PC. When a new release of OS/400 becomes available, I usually download an
updated copy of the API manual. It is available at
http://publib.boulder.ibm.com/html/as400/v5r1/ic2924/books/c4158000.pdf.
What Good Are APIs?
APIs provide a program interface to system routines.
Just like the CL command interface provides access to virtually every system
function, APIs provide a way for high-level language (HLL) programs to run these
same types of system functions.
For example, suppose you need to retrieve a system value while you're inside
an RPG IV program. You could simply write a CL program that calls the RTVSYSVAL
command and then return the corresponding value to the RPG program through a
parameter; nothing wrong with that.
Using APIs, however, you could simply call the same interface that the
RTVSYSVAL command uses from within RPG. The API is QWCRSVAL. A cool thing about
the APIs is that added function is often provided. For example, the QWCRSVAL API
allows you to retrieve several system values simultaneously. You could, for
example, retrieve all the password-related system values with one call to
QWCRSVAL.
Two very interesting APIs are the Retrieve Job Information API (which I use
to retrieve the library list) and the Change Library List) API. These allow you
to, as expected, retrieve or change the library list from within an HLL. But the
great thing about these APIs, particularly the Change Library List API, is that
they allow you to actually set the so-called product libraries as well as the
current library and the library list.
Change Library List (QLICHGLL)
QLICHGLL allows you to modify the library list for
your job. As I mentioned, you can change the regular "user portion" of the
library list as well as the two product libraries and the current library.
Parameter
Input/Output
Definition
Current library
Input
Char(11)
Product library 1
Input
Char(11)
Product library 2
Input
Char(11)
User library list
Input
Array of Char(11)
User library list count
Input
Int(4) in RPG 9B0 or 10i0
Standard API error data structure
Output
Char(16)
The first parameter is the current library name. It must be specified (it
cannot be blank), and it must be left-justified with a trailing blank. In
addition to any valid library name, the current library parameter accepts the
following special values:
*SAME--The current library is not changed.
*CRTDFT--There is no current library. The CRTxxxPGM command will use QGPL as
the default library name.
The product library parameters have the same restrictions as the current
library parameter. In addition, the product library parameters accept the
following special values:
*NONE--The product library (if any) is removed. Either product library 1 or 2
may have this value.
*SAME--The product library is not changed. Either product library 1 or 2 may
have this value.
The user library list parameter is an array of
11-position character values. Each array element may contain a library name,
left-justified with a trailing blank in position 11.
The user library list count parameter tells the API how many library names
have been specified in the User Library List. Effectively, this is the number of
used array elements. This value is a 4-byte binary or 4-byte integer field.
The final parameter is the standard API error data structure. Often, we just
ignore that parameter by passing it a value of X'00'.
The following CPF error messages may be generated by the QLICHGLL
API: CPF2106 Library list not changed. CPF2110 Library &1 not
found. CPF2113 Cannot allocate library &1. CPF2133 First product
library on library list destroyed. CPF2134 Second product library on library
list destroyed. CPF2137 Current library on library list
destroyed. CPF2176 Library &1 damaged. CPF2182 Not authorized to
library &1. CPF2184 Library list not replaced. CPF219A Library QTEMP
cannot be specified. CPF219F Number of libraries for library list not
valid. CPF24B4 Severe error while addressing parameter list. CPF3C90
Literal value cannot be changed. CPF3CF1 Error code parameter not
valid. CPF9872 Program or service program &1 in library &2 ended.
Reason code &3.
Retrieve Job Information (QUSRJOBI)
The QUSRJOBI API is an old API, but it has been
continually updated throughout the years. QUSRJOBI can retrieve most information
about the current running job, including the library list.
Parameter
Input/Output
Definition
Library list
Output
Char(*)
Length of first parameter variable
Input
Int(4)
Format name
Input
Char(8) 'JOBI0700'
Qualified job name
Input
Char(26)
Internal job identifier
Input
Char(16)
Standard API error data structure
Output
Char(16)
The first parameter, library list, is a return value--a data structure that
contains all the libraries on the library list, including system portion, user
portion, product libraries, and the current library name. Note that the QLICHGLL
API does not support changing the system portion of the library list. But that
is typically never done in production code, so this shouldn't be an issue.
The second parameter is the length of the data structure being used to
receive the library list (i.e., the length of the first parameter).
The third parameter is the name of the format used by the API. This format
controls what type of information the API returns. The QUSRJOBI API can return a
lot of different information, so the convention for this and many other APIs is
to accept a format ID that indicates which pieces of information the API should
return. To retrieve the library list, format ID 'JOBI0700' is passed.
The fourth parameter is the qualified job name for the job whose information
is being retrieved. Yes, you can retrieve the library list for another job if
you want. But a more practical use is to retrieve the library list for the
current job. So rather than pass in a 26-byte data structure simply create a
field that is 26 positions in length and set the first character of the field to
an asterisk (*). Leave the rest of the field blank.
The fifth parameter is the internal job name. Leave this parameter blank.
The sixth and final parameter is the standard API error data structure.
Wrapping It All Up
Logically, we would need to call QUSRJOBI to retrieve
the current library list, modify the list, and then call QLICHGLL to set the
list to what we want.
But wouldn't it be more useful to have this function wrapped in a usable RPG
IV procedure? Listed in Figure 1 is the RPG IV source for two procedure
prototypes, and they are:
GETLIBL--Retrieve the library list for the job.
SETLIBL--Change the library list to the new list specified.
To
use the procedures, you need to include the prototypes for them in your code
using either the /COPY or /INCLUDE compiler directives.
** GETLIBL - Retrieve the specified library list ** Usage: libl = GetLibl( list-type : rtn-Count ) ** Note: all parameters are optional.
** Return Value: ** LIBL - An array that receives the library list. ** Parameters: ** RTN-COUNT - An optional variable that recieves ** a count of the number of library returned. ** LIST-TYPE - An optional parameter that controls which ** library list is to be returned. The named ** constants in the LIBL include member may ** be used for this value.
D GetLibl PR 11A DIM(250) D lType 5I 0 Const Options(*NOPASS) D nLiblCount 5I 0 Options(*NOPASS)
** SETLIBL – Set (change) the library list ** Usage: libl = SetLibl( libl : list-type )
** Return Value: ** Reserved - Nothing returned at this time. ** Parameters: ** LIBL - An array of 11-character elements. ** Each library name to be placed on the library ** must be stored in a corresponding element. ** LIST-TYPE - An optional parameter that controls which ** library list is to be changed. The named ** constants in the LIBL include member may ** be used for this value. The default is ** the user portion of the library list. D SetLibl PR 1N D Libl 11A Const DIM(250) D lType 5I 0 Const Options(*NOPASS)
** Return Value: ** count - A count of the number of libraries on the library list. ** Parameters: ** LIBL - A character string of one or more library ** names separated by one or more blanks. ** POSLIB - An optional parameter that may contain the ** name of a library used to control the placement ** of the library names being added to the list. ** Special values *FIRST, and *LAST may also be ** specified to insert the library names at the start ** or end of the library list. ** POS - An optional parameter that indicates the order ** in which the new library name(s) are inserted ** into the library list. *ON = BEFORE the POSLIB ** *OFF = AFTER the POSLIB D AddLiblE PR 10I 0 D InLibl 2750A Const VARYING D PosLib 10A Const VARYING D Options(*NOPASS) D Pos 1N Const D Options(*NOPASS)
** Library list types (parameter 1) named constants D llUSRLIBL C Const(0) D llCURLIB C Const(1) D llSYSLIBL C Const(2) D llPRODLIBL C Const(3)
Figure 1: Prototypes for Library List Procedures
Listed in Figure 2 is the RPG IV source for two procedures that wrap the
functionality of these two APIs to provide a simplified interface to their
function.
H NOMAIN /COPY QRPGLESRC,LIBL
** Maximum libraries allowed on library list D MAXLIBL C Const(250) ** Field reference for Library Name (APIs use 11-pos name) D LIBNAME S 11A ** API Error data structure D ll_Error DS EXPORT D ll_DSLen 10I 0 Inz(%Size(ll_Error)) D ll_ByteRtn 10I 0 Inz D ll_cpfmsgid 7A D ll_reserved 1A D ll_msgdata 132A
D QUSRJOBI PR EXTPGM('QUSRJOBI') D libl 6000A OPTIONS(*VARSIZE) D nLibl 10I 0 Const D FmtName 8A Const D Job 26A Const D InternJob 16A Const D Api_Error 16A
D QLICHGLL PR EXTPGM('QLICHGLL') D CurLib 11A Const D ProdLib1 11A Const D ProdLib2 11A Const D UsrLibl 11A Const DIM(MAXLIBL) D nUsrLiblCount 10I 0 Const D Api_Error 16A
** ------------------------------------------ ** G E T L I B L -- (Get Library List) ** ------------------------------------------ P GetLibl B EXPORT ** GETLIBL - Retrieve the specified library list ** Usage: libl = GetLibl( list-type : rtn-Count ) ** Note: all parameters are optional.
** Return Value: ** LIBL - An array that receives the library list. ** Parameters: ** RTN-COUNT - An optional variable that recieves ** a count of the number of library returned. ** LIST-TYPE - An optional parameter that controls which ** library list is to be returned. ** Use the named constants in the prototype ** include member for the LIST-TYPE. D GetLibl PI 11A DIM(250) D lType 5I 0 Const Options(*NOPASS) D nLiblCount 5I 0 Options(*NOPASS)
** Return value is returned in LIBLARRAY D Libl DS D* LiblArray DIM(LMAXLIBL) LIKE(LIBNAME) ** Due to a bug in the RPG compiler, a global named constant ** cannot be specifed on the DIM keyword. :( D LiblArray DIM(250) LIKE(LIBNAME)
D nCount S 10I 0 D nSysLSize S 10I 0 D nUsrLSize S 10I 0 D nCurLSize S 10I 0 D nProdLSize S 10I 0
DLiblDS DS INZ D nBytesRtn 10I 0 D nBytesAvail 10I 0 D j_Name 10A D j_User 10A D j_Nbr 6A D ij_ID 16A D j_Status 10A D j_Type 1A D j_subtype 1A D j_Reserved 2A D nSysLib 10I 0 D nProdLib 10I 0 D nCurLib 10I 0 D nUsrLib 10I 0 D LibLists 3100A
D SysLibl s 2750A Based(pSysLibl) D ProdLibl s 2750A Based(pProdLibL) D CurLib s 2750A Based(pCurLib) D UsrLibl s 2750A Based(pUsrLibl)
C CALLP QusRJobI(LiblDS : %Size(LiblDS): C 'JOBI0700' : '*' : ' ' : ll_Error)
C Eval nSysLSize = nSysLib * %size(LibName) C Eval nProdLSize = nProdLib * %size(LibName) C Eval nCurLSize = nCurLib * %size(LibName) C Eval nUsrLSize = nUsrLib * %size(LibName)
C Eval pSysLibl = %addr(LibLists) C Eval pProdLibl = pSysLibl + nSysLSize C Eval pCurLib = pProdLibl + nProdLSize C Eval pUsrLibl = pCurLib + nCurLSize
C Select C When %Parms = 0 or lType = llUsrLibl C eval Libl = %subst(UsrLibl : 1 : nUsrLSize) C eval nCount = nUsrLib C When lType = llCurlib C eval Libl = %subst(CurLib : 1 : nCurLSize) C eval nCount = nCurLib C When lType = LLSysLibl C eval Libl = %subst(SysLibl : 1 : nSysLSize) C eval nCount = nSysLib C When lType = llPRODLIBL C eval Libl = %subst(ProdLibl : 1 : nProdLSize) C eval nCount = nProdLib C other C eval Libl = %subst(UsrLibl : 1 : nUsrLSize) C eval nCount = nUsrLib C endsl C if %Parms >= 2 C Eval nLibLCount = nCount C endif C return LiblArray P GetLibl E
** ---------------------------------------- ** S E T L I B L - Change Library List ** ---------------------------------------- P SetLibl B EXPORT D SetLibl PI 1N D InLibl 11A Const DIM(250) D lType 5I 0 Const Options(*NOPASS)
D CurLib s Like(LIBNAME) D ProdLib1 s Like(LIBNAME) D ProdLib2 s Like(LIBNAME)
D i S 10I 0 Inz(0)
C Dow InLibl(i+1) <> *BLANKS C Eval i = i + 1 C enddo C Select C When %Parms < 2 or lType = llUSRLIBL C CallP QliChgLL('*SAME':'*SAME':'*SAME': C InLibl : i : C ll_Error ) C When lType = llCURLIB C Eval CurLib = InLibl(1) C CallP QliChgLL(CurLib :'*SAME':'*SAME':' ': -1 C : ll_Error ) C When lType = llPRODLIBL C Eval ProdLib1 = InLibl(1) C Eval ProdLib2 = InLibl(2) C If ProdLib2 = *BLANKS C Eval ProdLib2 = '*SAME' C endif C CallP QliChgLL('*SAME':ProdLib1:ProdLib2:' ':-1 C : ll_Error ) C endsl C C return *ON P SetLibl E
** ---------------------------------------------- A D D L I B L E - Add Library List Entries ** ---------------------------------------------- P AddLiblE B EXPORT
D AddLiblE PI 10I 0 D InLibl 2750A Const VARYING D PosLib 10A Const VARYING D Options(*NOPASS) D Pos 1N Const D Options(*NOPASS)
D AddLibl S DIM(250) LIKE(LIBNAME) D OrgLibl S DIM(250) LIKE(LIBNAME) D NewLibl S DIM(250) LIKE(LIBNAME)
** *ON = place new lib(s) after otherwise place before D lAfter S 1N INZ(*OFF) D PlaceLib S LIKE(LIBNAME) INZ('*FIRST') D i S 10I 0 D x S 10I 0 D nPos S 10I 0 D nStart S 10I 0 D nLiblCount S 5I 0 D nAddLiblCount S 5I 0 C if %Parms >= 3 C Eval lAfter = Pos C endif C if %Parms >= 2 C Eval PlaceLib = PosLib C endif
C Eval nStart = 1 C Eval OrgLibl = GetLibl(llUsrLibl: nLiblCount) C Eval nPos = %Scan(' ':InLibl) C Dow nPos > 0 and i < MAXLIBL C Eval i = i + 1 C Eval AddLibl(i) = %subst(InLibl : nStart : C (nPos - nStart)+ 1) C Eval nStart = nPos+1 C Eval nPos = %Scan(' ':InLibl:nStart) C enddo C If %Len(InLibl) > nStart C Eval i = i + 1 C Eval AddLibl(i) = %subst(InLibl : nStart : C (%Len(InLibl)- nStart)+ 1) C endif
C eval nAddLiblCount = i ** Insert the new library(s) at the beginning ** of the existing library list C if PlaceLib = '*FIRST' C eval NewLibl = AddLibl C Eval x = nAddLiblCount + 1 C* eval NewLibl(x) = OrgLibl C MOVEA OrgLibl NewLibl(x) C Eval nLiblCount = nAddLiblCount + nLiblCount C else
** Insert before or after an existing library name C Eval X = 1 C for i = 1 TO nLiblCount
** Detect match on Placement-Libary name? C if OrgLibl(i) = PlaceLib ** Insert *AFTER C if lAfter ** Copy the Placement Library to the list C Eval NewLibl(x) = OrgLibl(i) C Eval X = X + 1 ** Add the new library names after the placement library C MOVEA AddLibl NewLibl(x) ** Copy the rest of the original library list C Eval X = X + nAddLiblCount C Eval i = i + 1 C MOVEA OrgLibl(i) NewLibl(x)
** Insert *BEFORE C else ** Add the new library names before the placement library C MOVEA AddLibl NewLibl(x) C Eval X = X + nAddLiblCount ** Copy the Placement Library to the list C Eval NewLibl(x) = OrgLibl(i) ** Copy the rest of the original library list C Eval X = X + nAddLiblCount C Eval i = i + 1 C MOVEA OrgLibl(i) NewLibl(x) C endif ** Done processing the library list C LEAVE
** NO-match on Placement-Libary name C else ** Just copy the library to the new list C Eval NewLibl(x) = OrgLibl(i) C Eval X = X + 1 C endif C endfor
C eval nLiblCount = X - 1 C endif ** Now do a Change Library List via the QLICHGLL API C CallP SetLibl(NewLibl) C Return X - 1 P AddLiblE E
Figure 2: Source code for Library List Procedures
Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.
This book provides an amazingly comprehensive introduction to the concepts while at the same time delivering enough technical detail to make you productive very quickly.
Today, it's all about input and output. Getting data into the IBM i from non-traditional sources and then displaying it back out again in varied formats. But where can you go to learn all that you need to know about this critical skill?
Too valuable to be classified as merely excellent certification material, this book should also rightly take its place on DB2 DBA bookshelves as a solid day-to-day DB2 reference.
Whether you want to obtain an IBM certified DB2 professional certification or simply become well-rounded in the fundamental concepts of DB2 and general database theory, this is your book.
Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:
More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.
IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:
TRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now! Request Now.
Forms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.
IT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.
Can you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:
Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:
Managing messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:
The thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:
For over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:
Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.
When it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:
Supply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:
The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from.
>> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit
Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.
IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn:
LATEST COMMENTS
MC Press Online