• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Guru: Beefing Up The Job Log, Take Two

    August 6, 2018 Ted Holt

    In Tracing Routines Explain Why The Computer Did What It Did, I wrote about the usefulness of writing information about program execution to determine why a program run gave certain results. Today I want to present a simpler method than the tracing routines. The tracing routines are not obsolete, but they are powerful and I have found them at times to be overkill.

    Just a word about terminology. Since I wrote that article five and a half years ago, my reading has led me to a different understanding of the terms tracing and logging. I’ve since decided that the activity I described in my article was more properly logging, not tracing. For that reason, I use the term logging in this article. In the grand scheme of things, terminology is of little importance.

    I often need a way to determine why a program behaved as it did. Sometimes I can use an interactive debugger to accomplish that. Sometimes an interactive debugger won’t answer the purpose, so I resort to logging. IBM i already has an effective logging mechanism — every job has a job log. An easy way, then, to understand program behavior is to write helpful messages into the job log. To do that, I use the Qp0zLprintf API, which Daniel Long shared with me and I wrote about in Beefing Up The Job Log.

    Here’s a short program that illustrates the process.

    /define LoggingIsOn
    
    H dftactgrp(*no) actgrp(*caller) option(*srcstmt: *nodebugio)
    
    D GrossAmt        s              7p 2
    D Discount        s              7p 2
    D Policy          s              1a
    
    (. . . more code . . .)
    
    C     TAG01         TAG
     /if defined(LoggingIsOn)
       JobLog ('> TAG TAG01');
     /endif
    
    C                   exsr      CalcDiscount
    (. . . more code . . .)
    
    C     CalcDiscount  begsr
    
     /if defined(LoggingIsOn)
       JobLog ('> Enter CalcDiscount. Policy=/' + Policy +
                                 '/ GrossAmt=/' + %char(GrossAmt) + '/');
     /endif
    
    (. . . more code . . .)
    
     /if defined(LoggingIsOn)
       JobLog ('> Leave CalcDiscount, Discount=/' + %char(Discount) + '/');
     /endif
    
    C                   endsr
    
     /if defined(LoggingIsOn)
       dcl-proc JobLog;
    
          dcl-pi JobLog;
                  inMessage  varchar(132)    const;
          end-pi JobLog;
    
       dcl-pr  Qp0zLprintf   int(10)  extproc('Qp0zLprintf');
                  inMessage  pointer  options(*string: *nopass) value;
       end-pr  Qp0zLprintf;
    
       dcl-c  EOL           const(x'25');
    
       Qp0zLprintf (%trimr(inMessage) + EOL);
    
       end-proc JobLog;
     /endif
    

    Let’s look at this code one piece at a time.

    /define LoggingIsOn 
    

    I use this compiler to include logging during development. When the program goes into production, I change the directive to /undefine so that the logging code does not run in production.

    C     TAG01         TAG
     /if defined(LoggingIsOn)
       JobLog ('> TAG TAG01');
     /endif
    
    C                   exsr      CalcDiscount
    (. . . more code . . .)
    C     CalcDiscount  begsr
    
     /if defined(LoggingIsOn)
       JobLog ('> Enter CalcDiscount. Policy=/' + Policy +
                                 '/ GrossAmt=/' + %char(GrossAmt) + '/');
     /endif
    
    (. . . more code . . .)
    
     /if defined(LoggingIsOn)
       JobLog ('> Leave CalcDiscount. Discount=/' + %char(Discount) + '/');
     /endif
    
    C                   endsr
    

    It is a good to log the tags. Spaghetti code is hard to follow, and logging the tags helps greatly to understand program flow.

    You may or may not want to log the entrance to or exit from a subprocedure or a subroutine. In this example, I report that the subroutine to calculate discounts ran, and I log the value of the gross amount and the policy used to calculate the discount. I always surround values with some character, usually a slash or a quotation mark, in case there are embedded blanks of significance in a value.

    The leading greater-than signs are not necessary and are only there to make the messages stand out in the job.

    To write to the job log, I created a wrapper over Qp0zLprintf. The JobLog subprocedure takes care of the messy details, such as passing a string by pointer and appending a line-feed character to the message.

    /if defined(LoggingIsOn)
       dcl-proc JobLog;
    
          dcl-pi JobLog;
                  inMessage  varchar(132)    const;
          end-pi JobLog;
    
       dcl-pr  Qp0zLprintf   int(10)  extproc('Qp0zLprintf');
                  inMessage  pointer  options(*string: *nopass) value;
       end-pr  Qp0zLprintf;
    
       dcl-c  EOL           const(x'25');
    
       Qp0zLprintf (%trimr(inMessage) + EOL);
    
       end-proc JobLog;
     /endif
    

    When I ran this example, the job log had these messages:

    > TAG TAG01 
    > Enter CalcDiscount. Policy=/A/ GrossAmt=/499.49/
    > Leave CalcDiscount. Discount=/24.95/ 
    

    I have two good ways to follow program flow and determine why a program did what it did — the JobLog subprocedure and my trace routines. Both save me a lot of time so that I can do the really important things in life, none of which have anything to do with computers.

    RELATED STORIES

    Tracing Routines Explain Why The Computer Did What It Did

    Beefing Up The Job Log

    An Introduction To Logging For Programmers

    How Logging Made Me A Better Developer

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: 400guru, FHG, Four Hundred Guru, IBM i

    Sponsored by
    ARCAD Software

    Embrace VS Code for IBM i Development

    The IBM i development landscape is evolving with modern tools that enhance efficiency and collaboration. Ready to make the move to VS Code for IBM i?

    Join us for this webinar where we’ll showcase how VS Code can serve as a powerful editor for native IBM i code and explore the essential extensions that make it possible.

    In this session, you’ll discover:

    • How ARCAD’s integration with VS Code provides deep metadata insights, allowing developers to assess the impact of their changes upfront.
    • The role of Git in enabling seamless collaboration between developers using tools like SEU, RDi, and VS Code.
    • Powerful extensions for code quality, security, impact analysis, smart build, and automated RPG conversion to Free Form.
    • How non-IBM i developers can now contribute to IBM i projects without prior knowledge of its specifics, while ensuring full control over their changes.

    The future of IBM i development is here. Let ARCAD be your guide!

    Watch Now

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    As I See It: Just Bag IT CIO Summit Brings Execs Up To Speed On IBM i

    Leave a Reply Cancel reply

TFH Volume: 28 Issue: 52

This Issue Sponsored By

  • ProData Computer Services
  • Computer Keyes
  • RPG & DB2 Summit
  • Manta Technologies
  • LUG

Table of Contents

  • Big Blue Moves Up Technology Refreshes For IBM i
  • CIO Summit Brings Execs Up To Speed On IBM i
  • Guru: Beefing Up The Job Log, Take Two
  • As I See It: Just Bag IT
  • IBM i PTF Guide, Volume 20, Number 30

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