12
Tue, Nov
5 New Articles

Binding Directories: The Easy Way to Link Your Modules and Service Programs

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times
If you haven't used binding directories yet, you will after reading this article. They provide a level of function that greatly simplifies the compile process.

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:

CRTPGM PGM(ORDENT) +
  MODULE(OEDEVLIB/OEMAIN +
    BOBTOOLS/DATRTN +
    BOBTOOLS/MATHLIB +
    OEDEVLIB/OE0500 +
    OEDEVLIB/OE0400 +
    OEDEVLIB/OE0300 +
    OEDEVLIB/OE0200 +
    OEDEVLIB/OE0100) +

 BNDSRVPGM(COZTOOLS/COZUTILS +
      OSILIB/STGTOOLS +

     OSILIB/IFSTOOLS)  ACTGRP(ORDERENT)

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.

CRTPGM PGM(ORDENT) MODULE(OEDEVLIB/OEMAIN) +
    BNDDIR(ORDBD1) ACTGRP(ORDERENT)

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:

CRTBNDDIR BNDDIR(ORDBD1) TEXT('Order Entry Binding Directory')

 

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:

ADDBNDDIRE BNDDIR(ORDBD1) +
   OBJ( (BOBTOOLS/DATRTN  *MODULE) +
    (BOBTOOLS/MATHLIB *MODULE)  +
    (OEDEVLIB/OE0500  *MODULE)  +
    (OEDEVLIB/OE0400  *MODULE)  +
    (OEDEVLIB/OE0300  *MODULE)  +
    (OEDEVLIB/OE0200  *MODULE)  +
    (OEDEVLIB/OE0100  *MODULE)  +
    (COZTOOLS/COZUTILS *SRVPGM) +
    (OSILIB/STGTOOLS *SRVPGM)   +
    (OSILIB/IFSTOOLS *SRVPGM)  )

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.

BOB COZZI

Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.


MC Press books written by Robert Cozzi available now on the MC Press Bookstore.

RPG TnT RPG TnT
Get this jam-packed resource of quick, easy-to-implement RPG tips!
List Price $65.00

Now On Sale

The Modern RPG IV Language The Modern RPG IV Language
Cozzi on everything RPG! What more could you want?
List Price $99.95

Now On Sale

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: