• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Send Messages Unto Others

    March 4, 2009 Ted Holt

    I’ll never forget the guy who used to call my telephone with a cheery “My computer won’t compute!” whenever he had a problem. Ambiguous appeals for help annoy me to no end. The least a guy can do is give me something to go on; some information to give me a place to start to look for his problem. But in fairness to users, I often find that they don’t have much information to give me because the programmer didn’t make the program tell them anything. A crafty CL programmer knows how to easily avoid such situations.

    When something goes wrong, send a message to the user. But don’t send any old message–make it a descriptive message! Here’s how.

    First, create a message file, if you don’t have one already. The following CL command creates a message file called AUSRMSG in library TOOLS.

    crtmsgf msgf(tools/ausrmsg)
    

    Next, design a descriptive message, keeping the following ideas in mind.

    1. Write a short message of 76 characters or less.
    2. Write a longer, more detailed message.
    3. Include placeholders (numbers prefixed with ampersands) in both of the aforementioned message texts. This is how you make your messages descriptive by replacing placeholders with appropriate text at run time.

    For example, here’s a short message:

    xxxxxxxxxxxxxxxxxxxxxxxxx canceled; xxxxx errors were found.
    

    Here’s a longer message:

    The xxxxxxxxxxxxxxxxxxxxxxxx application ended abnormally.
    Status is xxxxxxxx.
    You must correct the errors before you can continue.
    

    I have left three placeholders: application name, status code, and number of errors.

    Here’s the Add Message Description command that implements the message description.

    addmsgd msgid(usr1001) msgf(tools/ausrmsg) +
       msg('&1 canceled; &3 errors were found.') +
       seclvl('The &1 application ended abnormally. Status +
           is &2. You must correct the errors before you +
            can continue.') +
       sev(90) +
       fmt((*char 24) (*char 8) (*bin 2)) 
    

    Notice the three placeholders: &1, &2, and &3. The FMT parameter defines them to be 24-byte character, 8-byte character, and 2-byte signed binary (integer) respectively.

    The following program fragments illustrate how to use the message description. Program PAYEDIT returns the number of errors it finds in a payroll batch through the second parameter. If this number is more than zero, the program cancels, sending a descriptive message to the caller.

    dcl   &AppName       *char     24   value(' Payroll edit')
    dcl   &AppStatus     *char      8
    dcl   &NbrErrors     *dec       5
                                     
    dcl   &Bin2          *char      2
    
    call PayEdit parm(&AppStatus &NbrErrors)
    if (&NbrErrors *gt 0) do
       chgvar   var(%bin(&Bin2 1 2)) value(&NbrErrors)
       chgvar   var(&MsgDta)  value(&AppName *cat &AppStatus *cat &Bin2)
       sndpgmmsg msgid(usr1001) msgf(ausrmsg) msgdta(&msgdta) +
                    msgtype(*escape)
    enddo
    

    Since CL cannot concatenate decimal values into a string, I defined the third parameter as integer, which can be copied bit-for-bit into a character value using the %BIN function.

    The user sees the following in the message line at the bottom of his screen (or you see it his job log):

    Payroll edit canceled; 3 errors were found.
    

    If he positions the cursor to the messages and presses F1, he sees the second-level text:

    The Payroll edit application ended abnormally. Status is 25-32126.
    You must correct the errors before you can continue. 
    

    If you need to send more than one message in response to an error, send all of them except for the last one as diagnostic messages.

    sndpgmmsg msgid(usr1236) ... msgtype(*diag)
    sndpgmmsg msgid(usr6642) ... msgtype(*diag)
    sndpgmmsg msgid(usr3285) ... msgtype(*diag)
    sndpgmmsg msgid(usr1124) ... msgtype(*escape)
    

    Put yourself in the user’s place. Send messages unto others as you would have messages sent unto you.



                         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
    New Generation Software, Inc.

    IBM Query/400? DB2 Web Query?

    Compiled Report Programs?

    You believe in IBM i and Db2 on i. Your users might share your enthusiasm – if they weren’t dependent on unsupported query software, legacy report programs, and CSV file transfers.

    NGS-IQ simplifies and automates the creation, execution, and delivery of queries, reports and files to Excel, Web pages, multidimensional models, Adobe PDF, Power BI, and more.

    Request a demo or FREE trial.

    Talk to us at NEU and COMMON PowerUp.

    www.ngsi.com – 800-824-1220

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    System i Developer:  RPG & DB2 Summit in Orlando, April 15-17 for 3 days of serious training
    ARCAD Software:  FREE Webinar and White Paper, How ALM Can Save You Money
    COMMON:  Join us at the 2009 annual meeting and expo, April 26-30, Reno, Nevada

    IT Jungle Store Top Book Picks

    Easy Steps to Internet Programming for AS/400, iSeries, and System i: List Price, $49.95
    Getting Started with PHP for i5/OS: List Price, $59.95
    The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
    The System i Pocket RPG & RPG IV Guide: List Price, $69.95
    The iSeries Pocket Database Guide: List Price, $59.00
    The iSeries Pocket Developers' Guide: List Price, $59.00
    The iSeries Pocket SQL Guide: List Price, $59.00
    The iSeries Pocket Query Guide: List Price, $49.00
    The iSeries Pocket WebFacing Primer: List Price, $39.00
    Migrating to WebSphere Express for iSeries: List Price, $49.00
    iSeries Express Web Implementer's Guide: List Price, $59.00
    Getting Started with WebSphere Development Studio for iSeries: List Price, $79.95
    Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
    Getting Started with WebSphere Express for iSeries: List Price, $49.00
    WebFacing Application Design and Development Guide: List Price, $55.00
    Can the AS/400 Survive IBM?: List Price, $49.00
    The All-Everything Machine: List Price, $29.95
    Chip Wars: List Price, $29.95

    A Bevy of BIFs: %XLATE and %REPLACE Admin Alert: Things I Learned About IBM Maintenance Contracts

    Leave a Reply Cancel reply

Volume 9, Number 8 -- March 4, 2009
THIS ISSUE SPONSORED BY:

Help/Systems
COMMON
System i Developer

Table of Contents

  • A Bevy of BIFs: %XLATE and %REPLACE
  • Send Messages Unto Others
  • Admin Alert: Things I Learned About IBM Maintenance Contracts

Content archive

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

Recent Posts

  • What Is Threatening IBM i Security Now
  • GiAPA Tracks SQL Performance Issues On IBM i
  • LegacyBridge Uses AI To Automate Data Entry On 5250 Screens
  • As I See It: The Surgical Years
  • IBM i PTF Guide, Volume 28, Number 11
  • We Need To Get A Little Insight From You
  • No Joke: Big Memory And Flash Price Hikes Coming April 1
  • Strategic Topics To Think About For 2026, Part 2
  • Guru: IBM i Job Log Detective Brings Structure To Job Log Analysis In VS Code
  • IBM Launches Hybrid Cloud Backup Product With Cobalt Iron

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