• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Enable or Disable Code at Run Time

    April 5, 2016 Ted Holt

    If you program in RPG or C, you should know how to use compiler directives to enable or disable source code at compile time. IBM i programmers should also know how to enable or disable executable code at run time, and why they would want to do such a thing.

    Let’s talk about the why first.

    One good reason to enable or disable code is for trouble-shooting. You might find it valuable to include commands to:

    • Display the job log
    • Dump program variables
    • Copy QTEMP files to another library
    • Build spooled files (like of the type I showed how to create in the March 1, 2016 edition of Four Hundred Guru)

    Such code can help with elusive problems and need only be enabled until a problem is resolved.

    Another reason to enable or disable code is to give an end user a way to control execution. For example, he may only want certain programs to run during the first and last months of the year. If you make a program check a setting at run time, and give the user a way to control the setting, you relieve the user of the need to make a run time selection. If the program runs from a job scheduler, then such code is the only way for the user to control run-time behavior.

    Now, the how.

    One easy way to enable or disable code is by checking for the existence of an object. Any type of object can serve this purpose. I prefer data structures because they’re easy to deal with in both CL and RPG.

    In the following example, logical variable &DbgIsOn (debug is on) is controlled by the presence or absence of a data structure named DBG.

    dcl  &DbgDta     *char     96
    dcl  &DbgDtaSiz  *uint      2 
    dcl  &DbgIsOn    *lgl              value('1') 
    
    chgvar     &DbgDtaSiz      value(%size(&DbgDta)) 
    rtvdtaara  dtaara(DBG (1 &DbgDtaSiz))    rtnvar(&DbgDta)
    monmsg     cpf1015   exec(do)   /* not found */ 
            chgvar  &DbgIsOn   '0' 
    enddo 
    
    . . . more stuff . . .
    
    if (&DbgIsOn) do
       dmpclpgm
       dspjoblog  output(*print)
    enddo
    

    If the data structure exists in any library that is in the library list, the program sets &DbgIsOn to true, causing the program to produce a dump and a job log.

    The only problem with this method is that other programs may also have tests for the same data structure. This may or may not cause problems. At best, it could slow down processing and produce a bunch of unwanted spooled files. For this reason, I like to add another test, which looks at the value within the data structure.

    Consider a program, which I’ll call AR100.

    dcl  &DbgDta     *char     96
    dcl  &DbgDtaSiz  *uint      2
    dcl  &DbgIsOn    *lgl              value('1')
    
    chgvar     &DbgDtaSiz      value(%size(&DbgDta))
    rtvdtaara  dtaara(DBG (1 &DbgDtaSiz))    rtnvar(&DbgDta)
    monmsg     cpf1015   exec(do)   /* not found */
            chgvar  &DbgIsOn   '0'
    enddo
    
    if (&DbgIsOn) do
       chgvar  &DbgIsOn   value(%scan(AR100 &DbgDta) *gt 0)
    enddo
    
    . . . more stuff . . .
    
    if (&DbgIsOn) do
       dmpclpgm
       dspjoblog  output(*print)
    enddo
    

    This program tests for the existence of a data structure named DBG, just as the previous one did. If the data structure exists, the program also looks for the value “AR100” in the data structure.

    I have seen programmers add code to aid with debugging and/or problem determination, then delete that code once a problem is found. That isn’t wrong, but many times I have found it valuable to retain such code and activate it as needed.

    RELATED STORY

    Easy Printing From CL

    Share this:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) Email

    Tags:

    Sponsored by
    Lightedge

    Your IBM Power Cloud Strategy Should Start With “Why?”

    Moving IBM i to the cloud isn’t just an infrastructure decision.

    A hardware refresh, data center exit, IBM i skills gap, disaster recovery requirement, or broader cloud initiative can each lead to a very different architecture.

    At Lightedge, we start by understanding what you’re trying to accomplish. Then we look at the workload, application dependencies, resiliency requirements, operating model, and long-term strategy to determine where that workload belongs.

    Managed IBM Power cloud? IBM Power Virtual Server? DR in the cloud? A hybrid architecture connecting IBM Power with AWS or Azure?

    There isn’t one right answer for every IBM i environment.

    Start with the business requirement. Understand the workload. Then decide where it belongs.

    Explore IBM Power cloud, managed services, and hybrid solutions from Lightedge.

    Share this:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) Email

    Sponsored Links

    COMMON:  2016 Annual Meeting & Expo, May 15 - 18, in New Orleans! Great Power Systems event!
    iTech Solutions:  Get your copy of Pete Massiello's The IBM i State of the Union report now!
    Rocket Software:  Extend green screen apps to HTML5 for use in any web or mobile browser.

    Surge Of Services In DB2 For i, Part 1 Refacing Your Database, Part 1

    Leave a ReplyCancel reply

Volume 16, Number 08 -- April 5, 2016
THIS ISSUE SPONSORED BY:

Bug Busters Software Engineering
WorksRight Software
UCG Technologies

Table of Contents

  • Surge Of Services In DB2 For i, Part 1
  • Enable or Disable Code at Run Time
  • Refacing Your Database, Part 1

Content archive

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

Recent Posts

  • Will Power Chips Get A Converged Arm Instruction Set Like Z Mainframe CPUs?
  • Thinking About Moving IBM i To The Cloud? Don’t Start With The Quote
  • Precisely To Add Ransomware Protection In MIMIX 11
  • It’s D-Day For Cybersecurity, AI Firms Warn
  • IBM i PTF Guide, Volume 28, Number 30
  • Oracle Dips A Toe Into IBM’s EBCDIC World
  • When Your Small IBM i Team Is Really A Team Of One
  • Guru: Putting Failure Handling In Its Place
  • Inside The Security Enhancements In ACS
  • IBM i PTF Guide, Volume 28, Number 28: A Crazy Number of Security Vulnerability Patches

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