An ILE activation group is a substructure of a job. It is used to allocate and handle resources used by the programs running within the activation group. Activation groups are a vital component of ILE programming. In this article, we'll explore what activation groups are and how they affect the way your ILE programs run.
Program Activation
To understand the activation group concept, you have to first understand what ILE program activation is. Any ILE program or service program must be activated before the program is run. Activation initializes resources used by the program, including static variables, open files, SQL cursors, and open files. The activation process also handles binding of programs to associated service programs. The process of activating a program needs to occur only once within a given activation group. When a program is called, if it is not activated, program activation will occur. If, on the other hand, that program has already been activated, the existing activation is used.
When a program is activated, any static variables are initialized. Once a program has been activated, these variables remain available for access within the given activation group. It's important to remember that each job running a program has its own copy of each of these static variables. This means that if two users execute the same program, the static variables within each will be unique.
Activation Group Options
When determining what activation group a program will belong to, you have several options. The default activation group is automatically created when any job starts and destroyed when that job ends. While you can create ILE programs using the default activation group, you really lose much of the functionality that you use ILE for. For example, an ILE RPG program compiled to use the default activation group cannot contain any subprocedures.
The default activation group is used by all non-ILE (OPM) programs. When compiling an ILE RPG program, this option is specified on the DFTACTGRP parameter. Valid values are *YES to use the default activation group and *NO to define the activation group to be used. When *NO is specified, additional parameters for the activation group and binding directory to be used are displayed. You have several options when specifying the activation group: You can specify a named activation group that you've defined for the program, you can specify the special value *NEW to create a new activation group, or you can use *CALLER to identify that the program being compiled should always run in whatever activation group the program calling it is running in. With this last option, it is possible to have a true ILE application exist in the default activation group. The default value for this parameter is the QILE named activation group. Each of these has its own merits and purpose. Here's a breakdown of the life cycle of each type of activation group.
- Named Activation Group--When a program with a named activation group is called, if the activation group does not exist, it is created. It remains in existence until any and all programs using that activation group are no longer active.
- *NEW Activation Group--A program that was compiled with an activation group of *NEW creates a new activation group each time the program is called. This newly created activation group exists until the program that created it is no longer active.
- *CALLER Activation Group--When *CALLER is specified, the activation group is already in existence when the program is called and will continue to exist until the activation group is deleted based on one of the two scenarios described above.
It's important to mention that the *NEW option is not available when creating a service program using the CRTSRVPGM command. The other two options, however, are both valid on that command. This is because the general idea behind a service program is that it will be used by many other programs. Creating a new activation group each time the service program is accessed wouldn't make much sense.
It's also important to note that a program within a given activation group can remain active even after the program has ceased execution. This can be accomplished in RPG, for example, by executing a RETURN statement without first turning on *INLR. In this circumstance, the activation group containing the program will remain in existence until the job under which the activation group has been created ends.
Activation Group Resources
As I mentioned, static variables keep their values as long as an activation group exists. In addition, open files remain open in their current state until their activation group is deleted. Static (or global) variables are either those defined within the main procedure of a program or those defined in subprocedures with the STATIC keyword. As you've already learned, these variables hold their value on concurrent calls to the same program. The source shown in Figure 1 is a simple ILE RPG program that can be used to illustrate static variables.
|
Figure 1: This program helps illustrate the use of global variables.
You'll notice that the compile command shown creates a named activation group called TEST. When this program is called, if the activation group TEST doesn't exist, it will be created. Since this program contains only a single procedure, all of this program's variables are global.
The ACTION parameter defines the action to be performed by the program. A value of 'A' tells the program to add 1 to Variable1. An action of 'S' indicates that the program should subtract 1 from Variable1. When 'X' is specified for the action, it instructs the program to turn on *INLR, which causes the global variables to be reset. If the program is called again with one of the other action values after it is called with 'X', the value of Variable1 will be re-initialized. Our TEST activation group, however, will continue to remain in existence until it is reclaimed using the RCLACTGRP command. This can be seen by looking at the Display Activation Group screen, option 18 from the WRKJOB menu, as shown in Figure 2.
Figure 2: Any activation groups currently in existence are displayed on this screen. (Click image to enlarge.)
Similarly, opened files are kept open as long as the program is active and as long as the activation group remains in existence. The program shown in Figure 3 is an example of a program that accesses a database resource.
|
Figure 3: This program illustrates file use within an activation group.
Once again, this application is compiled to use the TEST named activation group. Each time the program is called, the program reads a record from the file CUSTOMERS and displays the value of the field CUSNAME. Once an end-of-file condition has been achieved, the program turns on *INLR.
In either of these examples, if the Reclaim Activation Group (RCLACTGRP) command is issued, any opened file pointers and static/global variables will be reset. If, for example, we called AGR002RG and then the RCLACTGRP was executed, the CUSTOMERS table would be closed. At this point, the activation group no longer appears in the Display Activation Groups screen. If AGR002RG is called again, the program will again create the activation group and will start with the first record in the CUSTOMERS table.
The same would be true of the global variable used in AGR001RG. When the activation group is reclaimed, the global variable will be reset, and a subsequent call to the program will recreate the activation group with newly initialized global variable values.
Similarly, the Reclaim Resources (RCLRSC) command can be used for programs running in the default activation group. These can be either OPM programs or ILE programs compiled with the option DFTACTGRP(*YES). The two parameters on the RCLRSC command are used to define the call level at which the cleanup should occur and to indicate whether an abnormal close notification should be sent to open communication files. Below is the syntax for the RCLRSC command.
The call level (LVL) parameter has an asterisk (*) option to identify that open resources at the current level or greater should be reclaimed. *CALLER can be specified to reclaim all resources at the level of the program that called the program issuing the RCLRSC command. Similarly the RCLACTGRP command accepts two parameters; however, the first parameter on this command is used to identify the activation group to be reclaimed. Below is the syntax for the RCLACTGRP command.
The ACTGRP parameter is used to specify the name of the activation group to be reclaimed. The optional special value *ELIGIBLE can be specified to reclaim all eligible activation groups (that is, activation groups that are no longer in use). The OPTION parameter on this command not only handles sending an abnormal close notification to open communication files, but also determines whether to commit or roll back pending changes for an activation group level commitment definition.
Start Today!
While this discussion of activation groups has been at a fairly introductory level, I hope it has helped to give you the concept behind ILE activation groups. How you make use of this powerful ILE feature can greatly impact the performance and flow of your ILE programs.
Mike Faust is an application programmer for Fidelity Integrated Financial Solutions in Maitland, Florida. Mike is also the author of the books The iSeries and AS/400 Programmer's Guide to Cool Things and Active Server Pages Primer and SQL Built-in Functions and Stored Procedures. You can contact Mike at
LATEST COMMENTS
MC Press Online