• 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
    Computer Keyes

    Fax Directly from your IBM i

    KeyesFax is a full function automated IBM i fax system. Spooled files are burst by fax number and auto transmitted with overlays.  It combines both a send and receive facsimile processing system with a complete image package.

    The fax software will edit, send, receive, display, print, and track fax documents or images using any standard IBM i without additional expensive hardware, software or subscriptions.

    Computer Keyes has been developing Software Solutions since 1978!

    www.computerkeyes.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

  • Power Systems Grows Nicely In Q3, Looks To Grow For All 2025, Too
  • Beta Of MCP Server Opens Up IBM i For Agentic AI
  • Sundry IBM i And Power Stack Announcements For Your Consideration
  • Please Take The IBM i Marketplace Survey
  • IBM i PTF Guide, Volume 27, Number 43
  • IBM Pulls The Curtain Back A Smidge On Project Bob
  • IBM Just Killed Merlin. Here’s Why
  • Guru: Playing Sounds From An RPG Program
  • A Bit More Insight Into IBM’s “Spyre” AI Accelerator For Power
  • IBM i PTF Guide, Volume 27, Number 42

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