• 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
    DRV Tech

    Get More Out of Your IBM i

    With soaring costs, operational data is more critical than ever. IBM shops need faster, easier ways to distribute IBM applications-based data to users more efficiently, no matter where they are.

    The Problem:

    For Users, IBM Data Can Be Difficult to Get To

    IBM Applications generate reports as spooled files, originally designed to be printed. Often those reports are packed together with so much data it makes them difficult to read. Add to that hardcopy is a pain to distribute. User-friendly formats like Excel and PDF are better, offering sorting, searching, and easy portability but getting IBM reports into these formats can be tricky without the right tools.

    The Solution:

    IBM i Reports can easily be converted to easy to read and share formats like Excel and PDF and Delivered by Email

    Converting IBM i, iSeries, and AS400 reports into Excel and PDF is now a lot easier with SpoolFlex software by DRV Tech.  If you or your users are still doing this manually, think how much time is wasted dragging and reformatting to make a report readable. How much time would be saved if they were automatically formatted correctly and delivered to one or multiple recipients.

    SpoolFlex converts spooled files to Excel and PDF, automatically emailing them, and saving copies to network shared folders. SpoolFlex converts complex reports to Excel, removing unwanted headers, splitting large reports out for individual recipients, and delivering to users whether they are at the office or working from home.

    Watch our 2-minute video and see DRV’s powerful SpoolFlex software can solve your file conversion challenges.

    Watch Video

    DRV Tech

    www.drvtech.com

    866.378.3366

    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

  • 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
  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23

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