• 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
    Chilli IT

    Chilli is one of the UKs leading IBM support and management providers with 20 years’ experience in the power and storage industry. Our bespoke solutions for maintenance, security and infrastructure delivers a service which is cost effective, increases productivity and enhances efficiency. Our ethical approach and unrivalled knowledge has secured business partnerships with blue-chip companies in the technology, retail, banking and travel sectors.

    As an IBM Business Partner, we provide you with the peace of mind that you are working in partnership with a company accredited to the highest standard. Our team of experts have worked together for many years and deliver projects which include consolidation, High Availability, Operating System upgrades; and backup and recovery installations.

    Contact us to see how we can help your business with IBM support and management.

    www.chilli-it.co.uk

    info@chilli–it.co.uk

    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

  • Guild Mortgage Takes The 20-Year Option For Modernization
  • IBM i Licensing, Part 3: Can The Hardware Bundle Be Cheaper Than A Smartphone?
  • Guru: The Finer Points of Exit Points
  • Big Blue Tweaks IBM i Pricing Ahead Of Subscription Model
  • We Still Want IBM i On The Impending Power E1050
  • DRV Brings More Automation to IBM i Message Monitoring
  • Managed Cloud Saves Money By Cutting System And People Overprovisioning
  • Multiple Security Vulnerabilities Patched on IBM i
  • Four Hundred Monitor, June 22
  • IBM i PTF Guide, Volume 24, Number 25

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 © 2022 IT Jungle

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.