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.

Rafael Victoria-Pereira

Rafael Victória-Pereira has more than 20 years of IBM i experience as a programmer, analyst, and manager. Over that period, he has been an active voice in the IBM i community, encouraging and helping programmers transition to ILE and free-format RPG. Rafael has written more than 100 technical articles about topics ranging from interfaces (the topic for his first book, Flexible Input, Dazzling Output with IBM i) to modern RPG and SQL in his popular RPG Academy and SQL 101 series on mcpressonline.com and in his books Evolve Your RPG Coding and SQL for IBM i: A Database Modernization Guide. Rafael writes in an easy-to-read, practical style that is highly popular with his audience of IBM technology professionals.

Rafael is the Deputy IT Director - Infrastructures and Services at the Luis Simões Group in Portugal. His areas of expertise include programming in the IBM i native languages (RPG, CL, and DB2 SQL) and in "modern" programming languages, such as Java, C#, and Python, as well as project management and consultancy.


MC Press books written by Rafael Victória-Pereira available now on the MC Press Bookstore.

Evolve Your RPG Coding: Move from OPM to ILE...and Beyond Evolve Your RPG Coding: Move from OPM to ILE...and Beyond
Transition to modern RPG programming with this step-by-step guide through ILE and free-format RPG, SQL, and modernization techniques.
List Price $79.95

Now On Sale

Flexible Input, Dazzling Output with IBM i Flexible Input, Dazzling Output with IBM i
Uncover easier, more flexible ways to get data into your system, plus some methods for exporting and presenting the vital business data it contains.
List Price $79.95

Now On Sale

SQL for IBM i: A Database Modernization Guide SQL for IBM i: A Database Modernization Guide
Learn how to use SQL’s capabilities to modernize and enhance your IBM i database.
List Price $79.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

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

  • 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

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