I started using binding directories several years ago after I created an RPG IV program that consisted of eight *MODULE objects and two service programs. It was a complex application that was easy to manage because I broke down the program into multiple source members, each with its own specific purpose.
I'm not going to sing out the virtues of decomposing your programs; that tune's been played. But I do want to explain why binding directories are cool.
A binding directory is a simple object type on the AS/400. The *BNDDIR object is simply a directory of *MODULE and/or *SRVPGM names. Note that I said directory, not repository; *BNDDIR contains only object names, not copies of the objects themselves. However, a link is created to the actual object so that so that if the object is re-created, the binding directory does not have to be changed.
Using a Binding Directory
Once a binding directory is created and has a list of *MODULE and *SRVPGM names stored in it, it can be used by any of the compiler commands to help simplify program creation by allowing you to avoid typing in a long list of *MODULE names when you create a program.
For example, if an RPG IV program is made up of eight modules and three service programs, creating it can be typing challenge, as follows in Figure 1:
|
Figure 1: Sample CRTPGM without binding directory
Okay, so typing this in once or twice is no big deal, and you have the good old F9 key on Command Entry to duplicate the prior commands. But what happens when you sign off and go home for the weekend and return to work on Monday for another try at it? You need to type in CRTPGM PGM(ORDENT) and so on. This can become a real pain!
By putting the module names and service program names in a binding directory, you can avoid keying in that long list of module and service program names. How? The BNDDIR parameter of the CRTPGM command allows you to specify the name of one or more binding directories.
By the way, a binding directory eliminates both the MODULE and the BNDSRVPGM parameters, although you may still specify them in conjunction with binding directories.
Now I'll issue the CRTPGM command for the ORDENT program, using the new ORDBD1 binding directory. See Figure 2.
|
Figure 2: Sample CRTPGM with binding directory
Specify the name of the program being created, the name of the entry module, the binding directory and activation group, and you're done. Now that's something I can live with!
Note that you need the name of the "entry module." This module is created from the source member that contains the mainline calcs in RPG IV. The entry module contains the piece of code that is evoked when the program is called. The entry module normally branches to procedures in other modules and is the start-up point for the program.
Creating a Binding Directory
To create a binding directory, use the CRTBNDDIR command. For example, to create a binding directory named ORDBD1 (order entry binding directory 1), use the following command:
No source code is used to create a binding directory; you simply create it using the CRTBNDDIR command.
Adding to the Binding Directory
To add module and service program names to a binding directory, the ADDBNDDIRE command may be used. The ADDBNDDIRE command is very sophisticated and allows multiple modules and service program names to be added with one evocation of the command. Once the modules are added, the binding directory can be used over and over again.
The following example adds the order entry module and service program names to the sample binding directory:
|
Figure 3: Adding modules to a binding directory
Note that the object parameter (OBJ) accepts a large number of object names simultaneously. Each object name and its associated object type are enclosed in parentheses.
There are also Work with Binding Directories (WRKBNDDIR) and Work with Binding Directory Entries (WRKBNDDIRE) commands. WRKBNDDIR is a typical work with objects command. It displays a list of binding directories that match the BNDDIR parameter. It is an interesting command in that the user interface of the work-with panel is mystifying (for example, option 9 evokes the WRKBNDDIRE command; why?), but it's not very useful on a day-to-day basis.
WRKBNDDIRE, however, is extremely useful. This command gives you the ability to add, change, and delete *MODULE and *SRVPGM names in a binding directory, using the now familiar work-with panel interface. Once a binding directory is created, it may be easiest to use WRKBNDDIRE to access and maintain its entries.
Program Binding Review
While a complete article on the binding process may be called for, it is beyond the context of binding directories. But let's review a few thing regarding binding directories and the program bind process.
The OS/400 binder is evoked by the CRTPGM and CRTSRVPGM commands. When a binding directory is specified, the modules and service programs specified on the MODULE and BNDSRVPGM parameters are used to bind the program to the modules and service programs specified in the binding directories.
Modules listed in the binding directory are copied into the target program only when their procedures are referenced, directly or indirectly, by a module specified on the MODULE parameter. Modules with unreferenced procedures are not included in the resulting program or service program.
That's a mouthful, but basically I'm saying that if the program needs the module, it will include it; if it doesn't need it, it won't. This only occurs with modules and service programs specified in a binding directory. Modules specified on the MODULE parameter are always included in the bind, as are service programs specified on the BNDSRVPGM parameter.
For program objects, binding directories are extremely useful, but the same cannot be for service program objects. While binding directories perform the same functionality with service programs as they do with programs, the dynamics behind building a service program are different.
A service program is often comprised of multiple modules, but the procedures in those modules do not normally refer to (i.e., call) one another. Instead, they are procedures that will be called by other programs. Hence, they are unreferenced by any one module in the service program. Therefore, under normal circumstances, the modules named on the binding directory parameter of the CRTSRVPGM command will not be included in the final *SRVPGM object. This is not an error; it is identical to the way CRTPGM works. With service programs, you tend not to reference things like you do in programs. The bottom line is you still need to use the MODULE parameter on the CRTSRVPGM command in addition to the BNDDIR parameter.
Binding directories are a key component in application development with any ILE-targeted languages (RPG IV, C, C++, COBOL, etc.). They are simply objects that can be used to reduce frustration when taking advantage of *MODULE and *SRVPGM objects.
LATEST COMMENTS
MC Press Online