Tue, May
3 New Articles

The API Corner: Providing Access to an Application Function, Part II

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


Learn the details behind the User Function Registration APIs.


In last month's API Corner, we took an initial look at the QsyRegisterFunction API of the set of APIs supporting User Function Registration. The API was used to first define a product, BVS_APPLICATIONS, and to then define a function within the product, BVS_CMD_LINE_WINDOW. For space reasons, the API parameters in that article were hard-coded and not explained in any detail. This month, we'll take a deeper dive into this API and see how you can customize access to various application features.


The QsyRegisterFunction API, which can also be called as a program using the name QSYRGFN, defines three parameters. The first parameter, Function ID, is a CHAR(30) input value where you name the function being registered. A discussion of how you might want to name your functions can be found in last month's article. The second parameter, Function controls, is a variable-length input value where you define various attributes of the Function ID being registered. The third parameter is the common Error code parameter found with most system APIs.


The Function controls parameter represents the meat of the API. This parameter, as mentioned earlier, is of varying length and can contain one or more variable-length records. These variable-length records define the function being registered. The first field of this parameter is a 4-byte binary value telling the API how many variable-length records are being provided. Then, following this field is that number of contiguous variable-length records.


Each variable-length record starts with three 4-byte binary fields and then a variable-length field that can contain either a character or a binary value. The first three binary fields represent the length of the current variable-length record, the key value identifying what attribute of the function being registered is being defined, and the length of the variable-length field that follows the third fixed field, respectively. This can be depicted as shown below.










Number of variable length records


The following four fields repeat for the number of variable length records specified at offset 0




Length of variable length record




Function control key




Length of data





Last month, we initialized the Function controls parameter, when registering the product BVS_APPLICATIONS, with the following data structure:


dPrdControls     ds                 qualified                      

d NbrOfCtls                     10i 0 inz(1)                        

d LenKey2Len                  10i 0 inz(16)                        

d Key2                         10i 0 inz(2)                        

d LenKey2Dta                   10i 0 inz(1)                        

d Key2Dta                       1a   inz('1')                        

d                               3a                                  

These control values correspond to the following: the API has one variable-length record (NbrOfCtls = 1), the variable-length record is a total of sixteen bytes in length (LenKey2Len = 16), the variable length record is defining a type of function (Key2 = 2), the length of the data associated with the function group is one byte (LenKey2Dta = 1), and the function type is a product (Key2Dta = '1'). The value of sixteen for LenKey2Len (as opposed to the thirteen bytes we actually used) is to accommodate the four bytes for LenKey2Len, the four bytes for Key2, the four bytes for LenKey2Dta, the one byte for Key2Dta, and three bytes to set the entire length of the variable-length record to a multiple of four. This multiple of four consideration is due to the API documented requirement that all variable-length records be aligned on a four-byte boundary. Though we're using only one variable-length record, it's easiest (for me anyway) to consistently extend all variable-length records to a multiple of four (in anticipation of needing a second record "someday"). Calling the QsyRegisterFunction API, with these values for the Function controls parameter, then registers the product BVS_APPLICATIONS.


Having registered the product, we then called the API a second time with the Function controls parameter initialized as shown below, to register the function BVS_CMD_LINE_WINDOW.


dFcnControls     ds                qualified                      

d NbrOfCtls                     10i 0 inz(3)                        

d LenKey3Len                   10i 0 inz(44)                        

d Key3                         10i 0 inz(3)                        

d LenKey3Dta                   10i 0 inz(30)                        

d Key3Dta                       30a   inz('BVS_APPLICATIONS')        

d                               2a                                  

d LenKey6Len                   10i 0 inz(144)                        

d Key6                         10i 0 inz(6)                        

d LenKey6dta                   10i 0 inz(132)                      

d Key6Dta                     132a   inz('Provide command line -    

d                                    window access')                

d LenKey11Len                   10i 0 inz(16)                        

d Key11                         10i 0 inz(11)                        

d LenKey11Dta                   10i 0 inz(1)                        

d Key11Dta                       1a   inz('1')                      

d                               3a                                  

These control values correspond to providing the API with three variable-length records (NbrOfCtls = 3).


The first variable-length record is a total of 44 bytes in length (LenKey3Len = 44), the variable-length record is declaring that the function being registered is part of a previously registered product (Key3 = 3), the length of the data associated with the product is 30 bytes (LenKey3Dta = 30), and the product is BVS_APPLICATIONS (Key3Dta = 'BVS_APPLICATIONS'). Two bytes of padding are provided to align the next variable-length record on a four-byte boundary.


The second variable-length record is a total of 144 bytes in length (LenKey6Len = 144), the variable length record is providing a descriptive name to associate with the function being registered (Key6 = 6), the length of the data associated with the descriptive name is 132 bytes (LenKey6Dta = 132), and the description is 'Provide command line window access' (Key6Dta). Note that in practice I would recommend using Key 5 rather than Key 6 when providing descriptive information. Key 5 allows you to provide a message file and message ID from which the QsyRegiserFunction API can extract the descriptive text (rather than coding the text within the program itself). I'm using Key 5 only to avoid having to create a message file and message description as part of this article.


The third variable-length record is a total of 16 bytes in length (LenKey11Len = 16), the variable-length record is providing a default usage value for the function being registered (Key11 = 11), the length of the data associated with the default usage is one byte (LenKey11Dta = 1), and the default value is '1' (Key11Dta = '1'). The Key11Dta value of '1' indicates that the default is to not allow access to the function being registered. Three bytes of padding are provided to align the next variable-length record (though there is currently no "next" record being defined).



While defining the Functions control parameter using a hard-coded data structure approach as shown above works (and more importantly makes for program source that would fit into last month's column), I would tend to take other approaches if I anticipated needing to register very many functions to the BVS_APPLICATIONS product. Next month, we'll look at one of these alternative approaches.


Meanwhile, if you have some free time, you may want to look at the QsyRegisterFunction API documentation. The fact that we only used Function control key values of 2, 3, 6, and 11 (and briefly mentioned key 5) should suggest that there are additional keys available to you.



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



Support MC Press Online

$0.00 Raised:

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: