Find out by using the Retrieve Product Information (QSZRTVPR) API.
A question that seems to come up on a regular basis is "How can a program tell what release level of the operating system it's running on?" To answer this question, we'll look at a category of system APIs that many of you may not have reviewed in the past—the Software Product APIs, which are introduced here.
We will not be looking at all of the available APIs today, but by using these APIs you can create your own products, support your company's products with PTFs, license your products…basically have the i support your products in the same manner it supports IBM-provided software products.
The specific API we'll be looking at today is the Retrieve Product Information (QSZRTVPR) API. While this API can return quite a bit of information about a software product, our interest today is in simply determining the release level of the operating system. The API defines six parameters:
Required Parameter Group:
1 |
Receiver variable |
Output |
Char(*) |
2 |
Length of receiver variable |
Input |
Binary(4) |
3 |
Format name |
Input |
Char(8) |
4 |
Product information |
Input |
Char(*) |
5 |
Error code |
I/O |
Char(*) |
Optional Parameter:
6 |
Product information format name |
Input |
Char(8) |
If you're familiar with retrieve-type APIs, you should see no surprises in this parameter list. If you aren't familiar with retrieve-type APIs, you may want to review the earlier articles "System API Basics," "Understanding API Data Types," and the series of articles starting with "Retrieving Information, Part I."
The QSZRTVPR API currently supports nine formats when returning information. Format PRDR0100, which is what we will be using, returns basic information, such as the product ID, the release level of the product, the option of the product being returned, the minimum release of the operating system the product can be saved to, etc. The other formats can be used to access more specific information such as:
PRDR0200—A list of the libraries and exit programs associated with the product
PRDR0300—A list of the folders associated with the product
PRDR0400—A list of the packaged objects associated with the product
…
PRDR0900—A list of the software agreement documents associated with the product
Below are listed the first few fields (there are many more) that are returned with format PRDR0100 along with their QSYSINC definitions. Note that the field Release level at decimal offset 19 is our specific field of interest.
Offset |
Type |
Field |
|
Dec |
Hex |
||
0 |
0 |
BINARY(4) |
Bytes returned |
4 |
4 |
BINARY(4) |
Bytes available |
8 |
8 |
BINARY(4) |
Reserved |
12 |
C |
CHAR(7) |
Product ID |
19 |
13 |
CHAR(6) |
Release level |
25 |
19 |
CHAR(4) |
Product option |
DQSZR0100 DS
D* Qsz PRDR0100
D QSZBRTN 1 4B 0
D* Bytes Returned
D QSZBAVL 5 8B 0
D* Bytes Available
D QSZRSV1 9 12B 0
D* Reserved 1
D QSZPI01 13 19
D* Product Id
D QSZRL03 20 25
D* Release Level
D QSZPO01 26 29
D* Product Option
The Product information parameter of the QSZRTVPR API is used to identify the product we're interested in. The default format for this parameter is format PRDI0100 which, along with its QSYSINC definition, is shown below:
Offset |
Type |
Field |
|
Dec |
Hex |
||
0 |
0 |
CHAR(7) |
Product ID |
7 |
7 |
CHAR(6) |
Release level |
13 |
D |
CHAR(4) |
Product option |
17 |
11 |
CHAR(10) |
Load ID |
DQSZPIR DS
D* Qsz Product Info Rec
D QSZPI00 1 7
D* Product Id
D QSZRL02 8 13
D* Release Level
D QSZPO00 14 17
D* Product Option
D QSZLI01 18 27
D* Load Id
Product ID (QSZPI00) identifies the product of interest and supports the special value *OPSYS to return information related to the operating system.
Release level (QSZRL02) identifies the release of the product we're interested in and supports (among other special values) the special value *CUR, indicating that the release level of the currently installed operating system should be used.
Product option (QSZPO00) identifies the option of interest with the value '0000' indicating the base option.
Load ID (QSZLI01) identifies the load of interest with the special value '*CODE' indicating the code load for the product.
Using these special values, the following program displays the current release of the operating system.
h dftactgrp(*no)
d RtvPrdInfo pr extpgm('QSZRTVPR')
d RcvVar 1a options(*varsize)
d LenRcvVar 10i 0 const
d Format 8a const
d PrdI 4096a const options(*varsize)
d ErrCde likeds(QUSEC)
d PrdIFmt 8a const options(*nopass)
/copy qsysinc/qrpglesrc,qszrtvpr
/copy qsysinc/qrpglesrc,qusec
/free
QUSBPrv = 0;
QSZPI00 = '*OPSYS';
QSZRL02 = '*CUR';
QSZPO00 = '0000';
QSZLI01 = '*CODE';
RtvPrdInfo(QSZR0100 :%size(QSZR0100) :'PRDR0100'
:QSZPIR :QUSEC);
dsply QSZRL03;
*inlr = *on;
return;
/end-free
As you can see, accessing the current release of the operating system is very straightforward. The program:
- Prototypes the QSZRTVPR API
- Includes the QSYSINC-provided definitions for the API (QSZRTVPR) and the standard API error code structure (QUSEC)
- Sets the API error code bytes provided field to send exceptions in the case of an API error
- Sets the Product information parameter to identify the product to be retrieved as being the current (*CUR) operating system (*OPSYS) base option ('0000') code load (*CODE)
- Calls the API
- Dsplys the returned release level (QSZRL03)
Assuming the previous RPG source is stored in member RTVOSINF (Retrieve Operating System Information) of source file QRPGLESRC, you can create and run the program using the following commands:
CRTBNDRPG RTVOSINF
CALL RTVOSINF
It's as simple as that to determine the current release level of the system a given program is running on. I find this ability to quickly ascertain such information to be quite handy when I have developed some code that runs across a range of release levels and the system provides more efficient ways to perform a given function (perhaps a new or enhanced API) on later release levels.
As usual, if you have any API questions, send them to me at
LATEST COMMENTS
MC Press Online