24
Sun, Nov
1 New Articles

The API Corner: Accessing System Information

APIs
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

It's easy with the Materialize Machine Attributes MI instruction.

While RPG application developers can easily access job-related information, such as the current job date (special words such as UDATE or *DATE) and the current user of the program (offset 358 through 367 of the PSDS), there are (admittedly infrequent) times when the developer also needs specific pieces of system-related information. Items that rapidly come to mind are the serial number of the system and the name of the system, though I've also seen questions about the serial number of the LPAR the application is running on, how many processors there are on the system, and so on.

 

There are many ways to access information such as the system serial number and/or the system name. In the case of the system serial number, the RPG developer might elect to call a CL program that runs the Retrieve System Value (RTVSYSVAL) command and then returns the system value QSRLNBR. Alternatively, the developer might choose to call the Retrieve System Values (QWCRSVAL) API directly to access the system value QSRLNBR. Along the same lines, access to the system name could be accomplished by using the Retrieve Network Attributes (RTVNETA) command within a called CL program or calling the Retrieve Network Attributes (QWCRNETA) API.

 

For accessing these specific pieces of system information, there's a third method that can be usedone that does not involve needing to call another program to do it. If you look at the various API categories that are documented in the Information Center, you'll notice a category named Machine Interface (MI) Instructions. Many of these instructions provide for bound program access, meaning they can be imbedded directly within your ILE RPG application program and appear to the developer as a procedure. The MI instruction of interest to us today is Materialize Machine Attributes (MATMATR).

 

The MATMATR instruction materializes (or retrieves to use common API terminology) information about the machine (or more typically, the partition of the machine) the instruction is running on. The interface to the instruction is defined as shown below.

 

 

Bound Program Access

Built-in number for MATMATR1 is 92.

MATMATR1 (

         materialization     : address

         machine_attributes   : address (of just a selector value)

)

 

 

 

A few items to point out about the interface documentation as provided in the Information Center:

 

  1. The line "Bound program access" indicates that the instruction can be directly imbedded into an ILE application program (in our case, ILE RPG but it could just as well be used in ILE CL).

  2. The RPG prototype will define the MI built-in as an external procedure using the documented name (MATMATR1) preceded by an underscore (_).

 

The term "address" indicates that the parameter is passed by reference (an address or pointer to the actual parameter values).

 

Reading the instruction documentation a bit further, we also learn that:

  1. The first parameter (referred to in the documentation as operand 1) identifies where the information is to be returned. This loosely corresponds to the Receiver variable of the system Retrieve APIs you might be familiar with. One significant difference, however, is that the first four bytes of this parameter are defined as a 4-byte integer input representing the length of the parameter. When calling most system Retrieve-type APIs, this length of the receiver variable would be a separate parameter and the first 4 bytes of the receiver variable would be defined as an output value representing the number of bytes returned by the API in the receiver variable.

  2. The second parameter (operand 2) is a 2-byte character input value identifying the information to be returned. This loosely corresponds to the Format parameter of many system Retrieve-type APIs.

    With this information, here is a program that retrieves the serial number of the machine and then DSPLYs it.

    h dftactgrp(*no)                                              

                                                                  

    d MatMAtr         pr                 extproc('_MATMATR1')    

    d RcvVar                       1a   options(*varsize)        

    d Format                       2a   const                    

                                                                  

    d MchInfo         ds                 qualified                

    d BytPrv                       10i 0 inz(%size(MchInfo))      

    d BytAvl                       10i 0                          

    d SrlNbr                       8a                            

                                                                  

    /free                                                        

                                                                  

    MatMatr(MchInfo :x'0004');                                  

                                                                  

    dsply ('Serial number . . . ' + MchInfo.SrlNbr);            

                                                                  

    *inlr = *on;                                                

    return;                                                      

                      

    /end-free        

    The program prototypes the MATMATR instruction as discussed earlier and then defines the data structure MchInfo. Reviewing the MI instruction documentation, we see that a Selection value of x'0004' corresponds to the physical machine serial number identification and that this serial number is returned as an 8-byte character value immediately following the 4-byte integer field "Number of bytes provided by the user" and the 4-byte integer value "Number of bytes available for materialization" of the receiver variable parameter. The MchInfo data structure is our receiver variable which mirrors this definition. Note that the definition of MchInfo also initializes MchInfo.BytPrv to the size of the MchInfo data structure.

    The program then runs the MATMATR instruction and DSPLYs the returned serial number. Not much to using this MI instruction is there?

    Assuming the previous source is stored in member GETSRLNBR of QRPGLESRC, you can compile it using CRTBNDRPG PGM(GETSRLNBR) and call it with CALL PGM(GETSRLNBR). After calling the program, you should see a message similar to this:

    DSPLY Serial number . . . 01AB23R

    Here's another program demonstrating how you might access other types of system-related information and some of the flexibility you have when running the MATMATR instruction.

    h dftactgrp(*no)                                                

                                                                    

    d MatMAtr         pr                  extproc('_MATMATR1')      

    d RcvVar                       1a   options(*varsize)        

    d Format                       2a   const                    

                                                                    

    d Various         ds                  qualified                

    d BytPrv                       10i 0 inz(%size(Various))      

    d BytAvl                       10i 0                          

    d SrlNbr                       8a                            

    d SysNam                      8a   overlay(SrlNbr)          

    d NbrCPUs                       5u 0 overlay(SrlNbr)          

                                                                    

    d LPARInfo       ds                 qualified                

    d BytPrv                       10i 0 inz(%size(LPARInfo))      

    d BytAvl                       10i 0                          

    d OldNbrLPARs                   1a                            

    d OldCurLPARID                 3u 0                          

    d OldPriLPARID                 1a                            

    d OldSvcLPARID                 1a                    

    d FirmwareLvl                   1a                    

    d                               3a                    

    d LPARSrlNbr                  10a                    

    d NewNbrLPARs           97     98u 0                  

    d NewCurLPARID         99   100u 0                  

    d NewPriLPARID         101   102u 0                  

    d NewSvcLPARID         103   104u 0                  

                                                          

    /free                                                

                                                          

    MatMatr(Various :x'0130');                          

                                                            

    dsply ('System name . . . . ' + Various.SysNam);    

                                                          

    MatMatr(Various :x'0004');                          

                                                            

    dsply ('Serial number . . . ' + Various.SrlNbr);    

                                                          

    MatMAtr(LPARInfo :x'01E0');                          

                                                                      

    dsply ('LPAR serial number . ' + LPARInfo.LPARSrlNbr);          

    dsply ('LPAR ID (new) . . . ' + %char(LPARInfo.NewCurLPARID));

    dsply ('LPAR ID (old) . . . ' + %char(LPARInfo.OldCurLPARID));

    dsply ('Number of LPARs . . ' + %char(LPARInfo.NewNbrLPARs));  

                                                                      

    MatMatr(Various :x'01DC');                                      

                                                                      

    dsply ('Number of CPUs . . . ' + %char(Various.NbrCPUs));      

                                                                      

    *inlr = *on;                                                    

    return;                                                        

                                                                      

    /end-free                                                        

    Our first program, GETSRLNBR, used the data structure MchInfo, which was defined with only the system serial number in mind. In the new program, we use the data structure Various to return various types of informationthe system serial number, the system name, and the number of processors installed on the system. For other accesses to system information, we use another data structureLPARInfo.

    The first use of MATMATR uses a format (selection value) of x'0130'. This value indicates that we want to materialize/retrieve network attribute information. While the amount of network information available is 190 bytes in length, we're interested only in the system name, which is returned as an 8-byte character value immediately following the Bytes provided (BytPrv) and Bytes available (BytAvl) fields discussed when accessing the serial number. As Various.BytPrv is initialized to a value of 16, we will materialize only the system name.

    The program then reuses the Various data structure to access and DSPLY the system serial number.

    Following this, the program uses the data structure LPARInfo and format x'01E0'. A selection value of x'01E0' indicates that we want to materialize partitioning information. I would like to point out a couple of items about the LPARInfo data structure:

  1. Field "Current partition identifier (legacy)" is defined as being a Char(1) that represents a binary value. In addition, if the ID value is greater than or equal to 255, then the value x'FF' will be returned with the actual value being returned in "Current partition identifier." While the field is documented as Char(1), LPARInfo defines it as a 1-byte unsigned integer value. This definition makes it much easier to work with when subsequently DSPLYing the value.

  2. Field "Current partition identifier" is defined as being a UBin(2), which corresponds to an RPG 2-byte unsigned integer value. As LPARInfo does not define all of the fields returned with selector value x'01E0' but we do want to access the Current partition identifier value, LPARInfo defines this field using absolute from and to location values. These values are 1 greater than those found in the MATMATR documentation as the documentation is using a base of 0 while RPG data structures are defined using a base of 1.

     

    After DSPLYing the current partition's serial number (which is not the same as the physical serial number), the LPAR ID (where both the legacy and non-legacy values will be the same, assuming you have less than 255 LPAR IDs assigned), and the number of LPARs, the program then uses selector value x'01DC' to access the number of installed processors for the physical machine. This information is returned as a 2-byte unsigned integer. When accessing the installed processor count, the program is using the Various data structure with a BytPrv value of 16 while there are only 10 bytes to actually materialize. As with our earlier access to network attributes, where BytPrv was smaller than the data that could be materialized, it's also not a problem to provide a BytPrv value that is larger than the data that can be materialized.

    In the case of x'01DC' (processor count), Various.BytAvl will be returned as a value of 10the number of bytes actually available. In the earlier case of x'0130' (network attributes), Various.BytAvl will be returned with a value of 198the number of bytes available if a larger receiver variable was provided (with, of course, an appropriately set Various.BytPrv value).

    Assuming the previous source is stored in member GETMCHINFO of QRPGLESRC, you can compile it using CRTBNDRPG PGM(GETMCHINFO) and call it with CALL PGM(GETMCHINFO). After calling GETMCHINFO, you should see messages similar to this:

    DSPLY System name . . . . S0123456

    DSPLY Serial number . . . 01AB23R

    DSPLY LPAR serial number . 01AB23RH

    DSPLY LPAR ID (new) . . . 17      

    DSPLY LPAR ID (old) . . . 17      

    DSPLY Number of LPARs . . 26      

    DSPLY Number of CPUs . . . 24      

    Today, we've looked at another method that can be used to access some system-level information. Using the MATMATR MI instruction is different from using approaches such as CL commands and callable system APIs, but you'll find that this MI instruction can "run circles" around these other approaches and, as we've seen, is pretty easy to use.

    As usual, if you have any API questions, send them to me at This email address is being protected from spambots. You need JavaScript enabled to view it.. I'll see what I can do about answering your burning questions in future columns.

Bruce Vining

Bruce Vining is president and co-founder of Bruce Vining Services, LLC, a firm providing contract programming and consulting services to the System i community. He began his career in 1979 as an IBM Systems Engineer in St. Louis, Missouri, and then transferred to Rochester, Minnesota, in 1985, where he continues to reside. From 1992 until leaving IBM in 2007, Bruce was a member of the System Design Control Group responsible for OS/400 and i5/OS areas such as System APIs, Globalization, and Software Serviceability. He is also the designer of Control Language for Files (CLF).A frequent speaker and writer, Bruce can be reached at This email address is being protected from spambots. You need JavaScript enabled to view it.. 


MC Press books written by Bruce Vining available now on the MC Press Bookstore.

IBM System i APIs at Work IBM System i APIs at Work
Leverage the power of APIs with this definitive resource.
List Price $89.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 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:

  • SB Profound WP 5539More 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.

  • SB HelpSystems ROBOT Generic 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:

  • Magic MarkTRY 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.

  • SB HelpSystems ROBOT GenericForms 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.

  • SB HelpSystems ROBOT GenericIT 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.

  • SB HelpSystems ROBOT GenericCan 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:

  • FORTRA 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:

  • FORTRAManaging 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:

  • FORTRAThe 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:

  • FORTRAFor 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:

  • LANSA 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.

  • LANSAWhen 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:

  • LANSASupply 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

  • Profound Logic 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.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra 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: