• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Bind By Slash-Copy

    May 15, 2013 Ted Holt

    I advise, recommend, urge, admonish, and even cajole RPG programmers to quit using subroutines and start using subprocedures instead. Yet I still hear from people who work in shops that allow the use of RPG IV (a.k.a. ILE RPG), but do not allow binding to modules and service programs. Today I offer two ways to use subprocedures that do not require ILE binding.

    But first, let’s have a quick review of ILE binding of subprocedures into programs.

    1. Bind by copy

    The object code of the subprocedures of a module is copied into the object code of a program object. Once the program has been created, the modules are no longer needed, and may be deleted. Revising the source code and recreating the module does not affect the program.

    2. Bind by reference

    The object code of the subprocedures of a module is copied into a service program object. Programs bind to the service programs at run time, each time using the subprocedures in the service program as the subprocedures are at that instant. Revising the source code and recreating a module require that a service program be updated, but do not require that program objects that use the service program be updated.

    If you work in a shop that does not participate in the ILE binding process, you may have given up hope of ever using subprocedures, but here are two other ways that you may be able to use them.

    3. Internal subprocedures

    You can put subprocedures directly into a program, between the output specifications and compile-time data. This is the simple replacement of subroutines. Whether your shop binds or not, this is the normal method you should use for subprocedures that do not need to be shared with other programs.

    Instead of this:

    C                   exsr      CalcFreight
    
    C     CalcFreight   begsr
      . . . more stuff . . .
    C                   endsr
    

    Do this:

    H dftactgrp(*no) actgrp('QILE')
    
     /free
         CalcFreight ();
     /end-free
    
    P CalcFreight     b
     . . . more stuff . . .
    P                 e
    

    Now that CalcFreight is a subprocedure, you can avail yourself of the advantages of subprocedures, notably the passing of parameters and use of local variables.

    4. Subprocedures in copybooks

    I call this “bind by slash-copy” because I use the /COPY or /INCLUDE compiler directive to bring subprocedure source code into a program object. Also, this method achieves the same result as bind by copy. That is, the subprocedure’s object code becomes part of the program object.

    Here’s an example. First, a copybook that contains the iif function.

    P iif
    D                 pi           256a   varying
    D  Condition                      n           value
    D  TrueValue                   256a   varying value
    D  FalseValue                  256a   varying value
     /free
         if Condition;
            return TrueValue;
         else;
            return FalseValue;
         endif;
     /end-free
    P                 e
    

    This function returns one of two values, depending on a condition. I wrote about iif a while back.

    Here are snippets of a program that needs this function. Notice the /INCLUDE directive.

    H dftactgrp(*no) actgrp('QILE')
     . . . more stuff . . .
     /free
    . . . more stuff . . .
         DspSex  = iif (Sex = 'M': 'Male': 'Female');
         DspPreg = iif (Pregnant = 'Y': 'Yes': 'No');
         DspMinor = iif (Age < 21: 'Yes': 'No');
    . . . more stuff . . .
     /end-free
     /include qrpglesrc,iif
    

    If you change iif, you have to recompile the callers, but at least you don’t have to make the same modification over and over.

    The ideal is to use bind by reference and internal subprocedures (methods 2 and 3). Use bind by reference for shareable subprocedures and internal subprocedures for those that don’t need to be shared. But if bind by reference is out of the question, bind by slash-copy (method 4) works in a pinch. Because I am an optimist, I am willing to settle for a less-than-ideal solution when I must.

    RELATED STORY

    A Handy RPG Function



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    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

    Sponsored Links

    United Computer Group, Inc.:  Vault400 for secure online backup and disaster recovery solutions.
    Bytware:  Your IFS Files Aren't Safe. Download the free IFS Security Bundle.
    ProData Computer Services:  Let 'em run WILD . . . with SQL! Download today!

    More IT Jungle Resources:

    System i PTF Guide: Weekly PTF Updates
    IBM i Events Calendar: National Conferences, Local Events, and Webinars
    Breaking News: News Hot Off The Press
    TPM @ The Reg: More News From ITJ EIC Timothy Prickett Morgan

    The Sweet 16 Of Mobile App Dev Tools for IBM i Making Hadoop Elephants Drink From Silverlake

    Leave a Reply Cancel reply

Volume 13, Number 10 -- May 15, 2013
THIS ISSUE SPONSORED BY:

WorksRight Software
ProData Computer Services
American Top Tools

Table of Contents

  • Search SQL Source Using System Catalogs
  • Bind By Slash-Copy
  • Adding A Job Queue To A Batch Subsystem

Content archive

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

Recent Posts

  • Liam Allan Shares What’s Coming Next With Code For IBM i
  • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
  • VS Code Will Be The Heart Of The Modern IBM i Platform
  • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
  • IBM i PTF Guide, Volume 27, Number 25
  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24

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