Forums >> Programming >> RPG Programming >>
Implementing a Binding Directory




Posted:
bvstone

Implementing a Binding Directory

 
Implementing a Binding Directory

Most of us on the IBM i are familiar with the concept of a Library List and how they work.  

When using modules or service programs a similar concept can be used that makes compiling programs much easier.  These are known as Binding Directories.

A Binding Directory is nothing more than a list of modules and/or service programs.  When you compile your program and that program needs to bind to a module and/or service program you specify a binding directory (or more than one) on the CRTxxxPGM command.  The system will then look through the modules and service programs listed in the binding directory for modules and service programs to bind to your program.

Lets see this in action.  Lets first create a binding directory using the Create Binding Directory (CRTBNDDIR) command:

CRTBNDDIR BNDDIR(ILESAMPLE/MYBNDDIR) TEXT('My First Binding Directory')

Once the binding directory is created, we can work with it using the WRKBNDDIR command:

WRKBNDDIR BNDDIR(ILESAMPLE/MYBNDDIR)

You should be presented with a screen similar to the following:

                         Work with Binding Directories 
             
 Type options, press Enter. 
   1=Create   4=Delete   5=Display   9=Work with binding directory entries 
   13=Change description 

      Binding 
 Opt  Directory   Library     Text 

      MYBNDDIR    ILESAMPLE   My First Binding Directory

If we use option 9 next to our binding directory we are presented with the following screen:

                      Work with Binding Directory Entries 
             
 Binding Directory:   MYBNDDIR       Library:   ILESAMPLE  

 Type options, press Enter. 
   1=Add   4=Remove 

                                                   --------Creation--------- 
 Opt     Object         Type        Library        Date           Time 


   (No binding directory entries for this binding directory.)                 

Because we just created our binding directory there are no entries in it.  Remember, an "entry" will simply be a module or service program.

Lets add our F.MATH module to this binding directory by using option 1 on the first blank entry.  Specify F.MATH for the Object, *MODULE for the Type and ILESAMPLE for the library.  Once added, we should see it in the list:

                     Work with Binding Directory Entries 
            
Binding Directory:   MYBNDDIR       Library:   ILESAMPLE  

Type options, press Enter. 
  1=Add   4=Remove 

                                                  --------Creation--------- 
Opt     Object         Type        Library        Date           Time 

        F.MATH         *MODULE     ILESAMPLE      04/06/15       13:04:37   

Now that we have our F.MATH module in our binding directory, lets try creating our program MATHTEST again, but this time instead of specifying a module or service program to bind to it, let's instead specify our new binding directory.  What's different is in this case we'll get to use the Create Bound RPG Program (CRTBNDRPG) command instead of the sequence of CRTMOD for each module, then CRTPGM to bind the modules into a program:

CRTBNDRPG PGM(ILESAMPLE/MATHTEST) SRCFILE(ILESAMPLE/QRPGLESRC) DFTACTGRP(*NO) BNDDIR(ILESAMPLE/MYBNDDIR)

Once this command is completed, use the DSPPGM command to display your MATHTEST program to verify that it's bound to the F.MATH module and not the F.MATH service program.

DSPPGM PGM(ILESAMPLE/MATHTEST) DETAIL(*MODULE)

Pretty neat, huh?  This is much easier than issuing all the CRTMOD commands and then CRTPGM.  

Now, let's add the F.MATH service program to our binding directory:

                     Work with Binding Directory Entries 
            
Binding Directory:   MYBNDDIR       Library:   ILESAMPLE  

Type options, press Enter. 
  1=Add   4=Remove 

                                                  --------Creation--------- 
Opt     Object         Type        Library        Date           Time 

        F.MATH         *MODULE     ILESAMPLE      04/06/15       13:04:37   
        F.MATH         *SRVPGM     ILESAMPLE      04/07/15       14:38:27  
 

Now, issue the CRTBNDRPG command again to recreate our MATHTEST program and lets see what happens.  Yep, that's right... it failed.  Here is the messages you most likely will see in your job log:

CRTBNDRPG PGM(ILESAMPLE/MATHTEST) SRCFILE(ILESAMPLE/QRPGLESRC) DFTACTGRP(*NO) BNDDIR(ILESAMPLE/MYBNDDIR)                                             
Definition supplied multiple times for symbol '#MATH_GETSUMINT'.           
Program MATHTEST in library ILESAMPLE not created.                         
Compilation failed. Program MATHTEST not created in library ILESAMPLE.

What this error is telling us is that it tried to create the MATHTEST program but it found more than one reference to the #math_getSumInt() procedure.  Because it was using our binding directory it would have found it both in the F.MATH module and the F.MATH service program.  

So, how do we fix this?

The answer will depend on which path you choose for the type of binding you and your shop will use,  Bind by Copy (using Modules) or Bind By Reference (using Service Programs).  Once that decision is made, you'll remove either the module or service program from your binding directory.

For the sake of this series on ILE, let's take the Bind By Reference path and remove the F.MATH module from our binding directory.  Once that is done we can issue the CRTBNDRPG command again and create our program.  Then we can use the DSPPGM command to verify that the F.MATH module is not bound to our program, but the F.MATH service program is.  Later in this series we will go back and look at the benefits and uses of each type of binding and where we've found it's best to use each and under which circumstances.

The last step in our adventure using Binding Directories is taking advantage of using an H-Spec to define the binding directory we want to use.  We simply add one line of code to the top of our MATHTEST program:

H DFTACTGRP(*NO) BNDDIR('MYBNDDIR')                                      
 ****************************************************************        
 * Prototypes                                                            
 ****************************************************************        
 /COPY QCOPYSRC,P.MATH                                                   
 ****************************************************************        
D Sum             S             10i 0                                    
 ****************************************************************        
 /free                                                                   
                                                                         
  Sum = #math_getSumInt(20:21);                                          
                                                                         
  *INLR = *ON;                                                           
 /end-free                                                               

This H-Spec defines some compiling options required when using a binding directory.  This means that we can use this simplified command to create our program:

CRTBNDRPG PGM(ILESAMPLE/MATHTEST) SRCFILE(ILESAMPLE/QRPGLESRC)

You'll notice the DFTACTGRP and BNDDIR parameters can be left off as the H spec is used for those values.  And yes, this means we can even use option 14 next to our program in PDM to compile!

Next, we will look at adding a new procedure to our service program and how that will affect the service program signature.


Last edited 04/21/2015 at 08:17:41


Reply




Copyright 1983-2017 BVSTools
GreenBoard(v3) Powered by the eRPG SDK, MAILTOOL Plus!, GreenTools for Google Apps, jQuery, jQuery UI, BlockUI, CKEditor and running on the IBM i (AKA AS/400, iSeries, System i).