21
Sat, Dec
3 New Articles

RPG Academy: Database Modernization - Methodology, Part 7

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

As promised, let’s go over some I/O Server sample code. Again, with the precious help of Patrick Sheehy of Adsero Optima.

In the previous TechTip, I introduced the concept of I/O Server. Now let’s explore a sample I/O Server so that you can better grasp the concept, starting with its header, available here.

As you can see, everything has comments and is carefully organized, as a modern RPG piece of code should be. Note that there’s a function for each operation. Before discussing the sample code, here’s an important note from Patrick Sheehy:

“Not all actions may apply to all files. For a given file (particularly logical files or indices), certain functions may be omitted from the I/O Server (although a generic “not supported” procedure may make the programmer’s life easier for the excluded operations). Likewise, the I/O Server may allow an “atomic” operation (from the user perspective) not possible using the base database operations. For example, when modernizing (and normalizing) a typical IBM i database, the effort often splits large monolithic files into smaller tables with discrete data sets. A new joined logical typically gets created to represent the “old” perspective of the original fie.

If a feature within the application provides update capability for the original file perspective, this could require an extensive rewrite, since DB2 for i does not allow update via a joined logical file. However, an I/O Server for the joined logical file easily provides the functionality available for the original file. Hidden in the “guts” of the Insert and Update procedures for the joined logical, the code can split the input record and write the fields to the multiple new, normalized tables. To the application programmer (and end user), the function remains virtually the same, with minimal recoding.”

You can find the code for the PUT and UPD functions here. Notice the error-handling for each set of operations, provided via MONITOR/ENDMON groups. It’s another good example of the “damage control” particularly important when writing data to the database. Finally, Patrick added a brief discussion about activation groups from the I/O Server perspective, which is something some programmers might not be familiar with:

“I/O Servers require some understanding and consideration of how activation groups impact database access. An activation group provides an isolated pool for memory and other resources required to run a program. A job can own many activation groups and activation groups can nest while maintaining their isolation from each other.

Activation groups come in three basic “flavors”; the Default Activation Group (DAG), system managed activation groups, and named activation groups. A fourth option uses the caller’s activation group, which while useful, still requires basic understanding of the first three definitions.

The DAG supports the OPM and does not support ILE features like procedures, service programs, and binding directories. Since this series of articles [RPG Academy] presume moving to modern RPG (i.e., ILE), avoid having a program run in the DAG by either compiling the source files to *MODULE objects using the CRTRPGMOD command before creating the actual program using CRTPGM, or specify DFTACTGRP(*NO) on the CRTBNDRPG command.

A system managed activation group (specified by the ACTGRP(*NEW) parameter on the CRTPGM command) provides the ILE equivalent of the DAG. The system creates a new activation group whenever the program executes and cleans up the resource pool when the program terminates. For programs called frequently (especially within the same job), this results in significant overhead as the operating system creates and reclaims the activation group on each invocation. Therefore, use ACTGRP(*NEW) sparingly.

A named activation group (ACTGRP(name)) may require more explicit work by the application, but provides operational and performance advantages. The first time the program executes, the system creates the activation group. The activation group then remains in existence within the job until the application explicitly reclaims the resources using the RCLACTGRP command, or the job itself ends. Until either of those occurs, subsequent calls to the program within the job use the already running activation group, significantly reducing program initiation time.

Service programs can also use a named activation group, but use this option very sparingly and with significant care. While this may offer a level of performance advantage for a very commonly used procedure in a service program (for example, if many different programs running in many different jobs all call a certain procedure often, the named activation group for the service program allows all the callers to share the same activation group), it carries significant risk. Any global or static variables used within the service program become accessible to every caller, effectively rendering the service program “stateless” with regard to any particular job and potentially introducing both unexpected results and security holes.

The last option, to use the caller’s activation group (ACTGRP (*CALLER)), runs the program or service program within the activation group of the calling program or procedure. This removes the overhead of creating a new activation group while at the same time isolating the invocation to the current program stack (avoiding the global variable issue noted above). This works best for procedures invoked by other procedures such as service programs. Likewise, avoid running programs such as the entry point for an application using the caller’s activation group. Such practice could result in an ILE program running under the DAG (if executed from the command line), which both defeats the isolation advantage of activation groups and clutters the resource pool used by the operating system. For most application entry points, a named activation group provides the greatest advantage.

Regarding nested activation groups, if a new activation group comes into existence (for example, through an external program call) during the lifespan of another activation group, activities within the nested activation group do not impact the activities in the original activation group. If the original activation group contains an open commit cycle and the new activation group performs an operation within its own commit cycle (including the actual commit), the latter operation has no effect on the original activation group’s commit cycle. The original commit cycle remains open until a commit or rollback operation occurs under the auspices of the original activation group.”

You can find the complete source of the I/O Server program here.

In summary, there are times when it’s not feasible at all or would require a massive amount of effort to move a certain business rule to the database. Using referential integrity constraints will certainly take you a long way, and using I/O Servers to free your program’s code of the database operations part is useful, but sometimes it is simply not enough. Once you’ve achieved this level of modernization, you’re ready to move on to the next stage: taking advantage of DB2’s advanced functionalities.

I’d like to end this topic with a very, very big “thanks!” to Patrick Sheehy and the rest of the fantastic team at Adsero Optima, without whom these last few articles would have been impossible.

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: