• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Guru: The Binding Directory Is The Key

    October 1, 2018 Ted Holt

    Hey, Ted:

    We license a software package to handle email on our IBM i system. When I write an RPG program that uses those routines, I can’t compile with the usual Create Bound RPG Program (CRTBNDRPG) command. Instead I have to use a two-step process — Create RPG Module (CRTRPGMOD) followed by Create Program (CRTPGM). Can you explain why this is? Even better, can you tell me if there is a way that I’m not aware of to compile with CRTBNDRPG?

    — David

    David continued, “I use CRTBNDCL and CRTBNDRPG, as they get me what I need, otherwise I am like the ostrich with his head in the sand, until I am attacked by the lion of need.” Today is David’s lucky day. He asked me to write an article, and I am granting his wish.

    Why does David have to go through two steps? Because his program does not contain all the routines it uses. One of the beauties of ILE is that a program can use an external routine as if it were an internal routine. This is not a new concept. Linkage editors have been around for a long time.

    In David’s case, the software vendor has delivered the email routines in the form of a service program. David must link his program to those routines.

    I think I can best explain David’s situation with an example.

    Let’s say that you and I work in a shop that stores dates as seven-digit packed-decimal numbers in CYYMMDD format (e.g. 1181225), and we often have to print or display such dates as day, month-name, and year (25 December 2018). We have licensed a DATERTNS (date routines) service program that contains a DisplayDate subprocedure to make such a conversion. Here’s the source code for that service program:

    ctl-opt nomain option(*srcstmt: *nodebugio);
    
    /include prototypes,DateRtns
    
    dcl-ds Months;
       *n    varchar(11)  inz(' January '  );
       *n    varchar(11)  inz(' February ' );
       *n    varchar(11)  inz(' March '    );
       *n    varchar(11)  inz(' April '    );
       *n    varchar(11)  inz(' May '      );
       *n    varchar(11)  inz(' June '     );
       *n    varchar(11)  inz(' July '     );
       *n    varchar(11)  inz(' August '   );
       *n    varchar(11)  inz(' September ');
       *n    varchar(11)  inz(' October '  );
       *n    varchar(11)  inz(' November ' );
       *n    varchar(11)  inz(' December ' );
       Month varchar(11)  dim(12)   pos(1);
    end-ds Months;
    
    dcl-proc DisplayDate export;
    
       dcl-pi DisplayDate   varchar(17);
          inDate    packed (7)    const;
       end-pi DisplayDate;
    
       dcl-s  CharDate      char(8);
    
       CharDate = %char(%date(inDate: *cymd): *iso0);
    
       return %triml(%subst(CharDate: 7: 2): '0') +
              Month(%uns(%subst(CharDate: 5: 2))) +
              %subst(CharDate: 1: 4);
    
    end-proc DisplayDate;
    

    Here’s the prototype, which we copy into our programs using the /INCLUDE compiler directive.

    dcl-pr  DisplayDate   varchar(17); 
               inDate    packed (7)    const;
    end-pr  DisplayDate; 
    

    Here’s our program, which calls the DisplayDate routine.

    ctl-opt  option(*srcstmt: *nodebugio);
    
    /include prototypes,DateRtns
    
    dcl-s  PrintDate     varchar(17);
    dcl-s  FromDate      packed(7)     inz(1181225);
    
    *inlr = *on;
    PrintDate = DisplayDate (FromDate);
    return;
    

    Note that our code includes the prototype and calls the DisplayDate subprocedure, which is defined in the service program.

    When we need to compile a program, CRTBNDRPG doesn’t work because the compiler doesn’t know where the DisplayDate routine is. At this point, we have been doing the only thing we knew to do — drop back and punt.

    CRTRPGMOD MODULE(QTEMP/SALES02R) 
                 SRCFILE(MYLIB/QRPGLESRC) 
                 SRCMBR(SALES02R)      
    

    Now we have a module object. CRTPGM lets us link that module to the vendor’s service program.

    CRTPGM PGM(MYLIB/SALES02R) 
              MODULE(QTEMP/SALES02R) 
              BNDSRVPGM((DATERTNS))
    

    Now we have a program object that uses a subprocedure in a vendor-supplied service program. Mission accomplished.

    But it would be so much simpler if we could use CRTBNDRPG, and we can! Here’s how.

    First, we create a binding directory. I recommend keeping the number of binding directories low. In many shops, one is sufficient. Let’s call our binding directory PRODUCTION.

    CRTBNDDIR BNDDIR(MYLIB/PRODUCTION)
    

    A binding directory is just a list of service programs and/or modules that programs might need.

    Second, we use the Add Binding Directory Entry (ADDBNDDIRE) command to add the DATERTNS service program to the binding directory.

    ADDBNDDIRE BNDDIR(MYLIB/PRODUCTION) OBJ((DATERTNS *SRVPGM))
    

    Last, we refer to the binding directory in the control (header) spec of our RPG programs.

    ctl-opt  dftactgrp(*no)  
             option(*srcstmt: *nodebugio)
             bnddir('PRODUCTION');                       
    

    Now we can compile using CRTBNDRPG. When the compiler looks for external routines, it will search the service programs and modules that are listed in the binding directory.

    I hope this helps David and others who have been “attacked by the lion of need.”

    This reminds me of a recent conversation with a fellow IBM i professional. He reminded me that one of the System/38 features that IBM widely promoted was that the dynamic calls were so fast, there was no need for a linkage editor on that system. I had forgotten.

    And that bit of trivia, in turn, reminds me of a question that I have been asked several times — why bother with service programs? Why not use dynamic calls? I will honor that request, as I have honored David’s, but it will have to wait for another day.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: FHG, Four Hundred Guru, Guru, IBM i, RPG

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Advice For The IBM i Shop Buying X86 Servers Can ERP Vendors Deliver On Industry 4.0 Expectations?

    4 thoughts on “Guru: The Binding Directory Is The Key”

    • Bill Pahl says:
      October 1, 2018 at 8:15 am

      In your last instruction, you meant to say “Now we can compile using CRTBNDRPG.”

      Reply
    • glenngundy says:
      October 1, 2018 at 9:02 am

      Great article Ted. Btw, I think you have a typo here: Now we can compile using CRTBNDDIR.

      Reply
    • robert says:
      October 2, 2018 at 2:27 pm

      Now we can compile using CRTBNDDIR ? Typo I believe.

      Reply
    • Jon Paris says:
      October 6, 2018 at 1:15 pm

      Saddest thing really is that the vendor apparently didn’t include a binding directory and/or instructions on how to create one.

      Reply

    Leave a Reply Cancel reply

TFH Volume: 28 Issue: 65

This Issue Sponsored By

  • Fresche Solutions
  • New Generation Software
  • SEA
  • COMMON
  • Manta Technologies

Table of Contents

  • The NUMA NUMA [Song] Tax
  • Can ERP Vendors Deliver On Industry 4.0 Expectations?
  • Guru: The Binding Directory Is The Key
  • Advice For The IBM i Shop Buying X86 Servers
  • The Herculean Task Of Applying Spectre/Meltdown Patches

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • POWERUp 2025 –Your Source For IBM i 7.6 Information
  • Maxava Consulting Services Does More Than HA/DR Project Management – A Lot More
  • Guru: Creating An SQL Stored Procedure That Returns A Result Set
  • As I See It: At Any Cost
  • IBM i PTF Guide, Volume 27, Number 19
  • IBM Unveils Manzan, A New Open Source Event Monitor For IBM i
  • Say Goodbye To Downtime: Update Your Database Without Taking Your Business Offline
  • i-Rays Brings Observability To IBM i Performance Problems
  • Another Non-TR “Technology Refresh” Happens With IBM i TR6
  • IBM i PTF Guide, Volume 27, Number 18

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle