• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Beefing Up The Job Log

    July 23, 2014 Ted Holt

     

     

    Next to Barbara Morris, the job log is the IBM i professional’s best friend. However, even though job logs give useful information, they don’t always tell us everything we need to know to diagnose job failure. A recent email from perspicacious reader Daniel Long reminded me that sometimes we have to help ourselves.

    A job log can tell us when a job started and ended, the list of libraries at its disposal, the CL commands and programs it ran, the messages those programs sent, etc. The one thing the job log does not show us, and how I wish it would, is the list of parameters passed to a CALL command. No, the job log shows us this lame message:

    CALL PGM(MYPGM)          /* The CALL command contains parameters */
    

    I have written about this before. And also before that. As far as I was concerned, this topic had received adequate coverage in this august publication, and I had no plans to revisit it.

    Then came Daniel’s email. Daniel, a really sharp guy, mentioned using the Qp0zLprintf API to write to the job log from RPG programs. I realized that I had not finished the job.

    Here’s the procedure prototype Daniel uses:

    dcl-pr UTIL_writeJobLog int(10) extproc('Qp0zLprintf');
       out_String pointer value options(*string);
       out_Substitute01 pointer value options(*string:*nopass);
       out_Substitute02 pointer value options(*string:*nopass);
       out_Substitute03 pointer value options(*string:*nopass);
       out_Substitute04 pointer value options(*string:*nopass);
       out_Substitute05 pointer value options(*string:*nopass);
       out_Substitute06 pointer value options(*string:*nopass);
       out_Substitute07 pointer value options(*string:*nopass);
       out_Substitute08 pointer value options(*string:*nopass);
       out_Substitute09 pointer value options(*string:*nopass);
       out_Substitute10 pointer value options(*string:*nopass);
    end-pr;
    

    Here are some sample calls:

    if sqlstate > EOF;
       UTIL_WriteJobLog( '- - - - - - - - - - - - - -' + X'25' );
       UTIL_WriteJobLog( '- %s ended with 10-%s' + X'25' :
                         %trim(prognm) :
                         sqlstate );
       UTIL_WriteJobLog( '- - - - - - - - - - - - - -' + X'25' );
       return;
    endif;
    

    This API works like C’s printf function. The first parameter is a string that may contain substitution variables. The remaining parameters are optional, and refer to the values that are to replace the substitution variables.

    As I have worked with this API, I have come to prefer passing only one parameter to Qp0zLprintf. The only substitution variable I have found that works well from RPG is %s, which means that parameters two and following must be character strings. Since all the parameters have to be strings, why not put the string values into the message?

    WriteToJobLog ('Counter=' + %char(Counter) + X'25');
    

    Here, then, is an example that puts it all together. First, portions of CL program QAD1C.

    pgm
    
       dcl  &Account   *char    5
       dcl  &ErrorFlag *char    3
    
    
       sndpgmmsg ('&Account=' *cat &Account) topgmq(*same) msgtype(*info)
    . . . more stuff . . .
       call qad1r (*list &Account &ErrorFlag)
    . . . more stuff . . .
       sndpgmmsg ('&ErrorFlag=' *cat &ErrorFlag) topgmq(*same) msgtype(*info)
    
    endpgm
    

    Next, the RPG program.

    H dftactgrp(*no) actgrp(*new)
    
    D Qad1R           pr                  extpgm('QAD1R')
    D  inAction                     10a   const
    D  inAccount                     5a   const
    D  ouErrorFlag                   3a
    
    D psds           sds                  qualified
    D   ProcName                    10a
    
    D WriteToJobLog   pr            10i 0 extproc('Qp0zLprintf')
    D  inMessage                      *   options(*string: *nopass) value
    
    D EOL             c                   const(x'25')
    
    D Counter         s              5p 0
    
    D Qad1R           pi
    D  inAction                     10a   const
    D  inAccount                     5a   const
    D  ouErrorFlag                   3a
    
     /free
       *inlr = *on;
       Counter += 1;
       WriteToJobLog ('**Enter ' + %trim(psds.ProcName) + EOL);
    . . . more stuff . . . 
       WriteToJobLog ('Counter=' + %char(Counter) + EOL);
    . . . more stuff . . .
       WriteToJobLog ('**Leave ' + %trim(psds.ProcName) + EOL);
       ouErrorFlag = 'NO';
       return;
    

    We have covered all bases. The job log has messages like these:

    &Account=23456
    **Enter QAD1R
    Counter=5
    **Leave QAD1R
    &ErrorFlag=NO
    

    I will mention one more thing. Qp0zLprintf returns a four-byte signed integer value that tells how many bytes of data were written, so you can call the API this way if you prefer:

    D BytesWritten    s             10i 0
    
      BytesWritten = WriteToJobLog ('**Enter ' + %trim(psds.ProcName) + EOL);
    

    But I don’t know any need for this.

    Now that you have effective ways to write to the job log, load the job log with useful information. Life’s too short to spend time debugging programs.

     

    RELATED STORIES

    Remove Misleading Messages from Job Logs

    A Better Way to Read Job Log

    Let’s See Those Command Parameters

    Vincent’s Standards

     



                         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
    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!

    Register now!

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    NGS:  NGS-IQ is the complete IBM i query, reporting, and analytics solution. System i Developer:  Upgrade your skills at the RPG & DB2 Summit in Minneapolis, Sept 30 - Oct 2. COMMON:  Join us at the COMMON 2014 Fall Conference & Expo in Indianapolis, Oct 27-29

    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 @ EnterpriseTech: High Performance Computing Industry News From ITJ EIC Timothy Prickett Morgan

    IBM i Community-Minded Planning IBM Readies More Power8 Iron For Launch

    One thought on “Beefing Up The Job Log”

    • Tony Payne says:
      May 11, 2018 at 5:51 am

      Excellent description of how to do this Ted, thanks very much. I just Googled if this was possible, and yours was the clearest description by far.

      The problem I have is an RPG Free program that performs SQL compares with a number (about 20) of files, checking for each to see if there are differences (at record level) between the current and previously saved copies of the file.
      At least one of these SQL’s is generating errors on occasion, but it’s really difficult to determine which one, and the job log error messages just show which SQL API the error was detected in.
      By adding comments to the job log between the processing of each file, this ought to help to narrow it down.

      Reply

    Leave a Reply Cancel reply

Volume 14, Number 16 -- July 23, 2014
THIS ISSUE SPONSORED BY:

CCSS
Valence Framework for IBM i
System i Developer

Table of Contents

  • DB2 for i 7.2 Features And Fun: Part 2
  • Beefing Up The Job Log
  • Porting A User Profile From One IBM i Machine To Another

Content archive

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

Recent Posts

  • IBM Unveils Manzan, A New Open Source Event Monitor For IBM i
  • Say Goodbye To Downtime: Update Your Database Without Taking Your Business Offline
  • i-Rays Brings Observability To IBM i Performance Problems
  • Another Non-TR “Technology Refresh” Happens With IBM i TR6
  • IBM i PTF Guide, Volume 27, Number 18
  • Will The Turbulent Economy Downdraft IBM Systems Or Lift It?
  • How IBM Improved The Database With IBM i 7.6
  • Rocket Celebrates 35th Anniversary As Private Equity Owner Ponders Sale
  • 50 Acres And A Humanoid Robot With An AI Avatar
  • IBM i PTF Guide, Volume 27, Number 17

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