• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Message Received, But Not Understood

    November 18, 2009 Hey, Ted

    I had a problem last week. I was monitoring for error messages after an Add Physical File Member (ADDPFM) command in a CL program. Well, OS/400 sent two CPF messages when ADDPFM failed. MONMSG would only trap the second message, but I wanted to trap the first one because that’s the one that tells me what went wrong. What do I need to do?

    –Chris

    This seems like a good time to review some messaging fundamentals. Chris is not a newbie programmer, so if he doesn’t understand, there are probably others who don’t understand either.

    When a CL command fails, it often sends more than one message. All messages except the last one are diagnostic messages. Their purpose is to provide more information about the error. The last message is an escape message. Its role is to notify the caller that the command failed, but it may also, like the diagnostic messages, impart information about the error.

    For example, if ADDPFM tries to add a member, but the file already has the maximum number of members, the system sends two messages: diagnostic message CPF3213 (Members for file DOGPOUND more than maximum allowed); and escape message CPF7306 (Member PHIDEAUX not added to file DOGPOUND in THEBIGCITY).

    Likewise, if ADDPFM tries to add a member that already exists, the system sends two messages: diagnostic message CPF5812 (Member PHIDEAUX already exists in file DOGPOUND in library THEBIGCITY); and escape message CPF7306 (Member PHIDEAUX not added to file DOGPOUND in THEBIGCITY).

    Notice that the same escape message is sent in both instances.

    Chris wanted his program to determine why the ADDPFM command failed so that his program could pursue different courses of action according to the cause of the failure. The escape message, the only one he could monitor for, told him only that the command failed. The reason why it failed was in the diagnostic message.

    It is necessary to use the Receive Message (RCVMSG) command to get the diagnostic message. The following example shows one way to achieve this goal.

    PGM        PARM(&MBR)
    
       DCL        VAR(&MBR)        TYPE(*CHAR) LEN(10)
       DCL        VAR(&ERRORMSGID) TYPE(*CHAR) LEN( 7)
       DCL        VAR(&MSGTYPE)    TYPE(*CHAR) LEN( 2)
    
       ADDPFM     FILE(DOGPOUND) MBR(&MBR)
       MONMSG     MSGID(CPF7306) EXEC(DO)
    
          RCVMSG     MSGTYPE(*LAST) RMV(*YES) MSGID(&ERRORMSGID) +
                              RTNTYPE(&MSGTYPE) /* escape msg */
          RCVMSG     MSGTYPE(*LAST) RMV(*YES) MSGID(&ERRORMSGID) +
                              RTNTYPE(&MSGTYPE) /* diagnostic msg */
    
          IF         COND(&MSGTYPE *NE '02') THEN(DO)
             /* Do something here; the last message should have */
             /* been a diagnostic message, but it wasn't.   */
             CHGVAR     VAR(&ERRORMSGID) VALUE(' ')
          ENDDO
    
          SELECT
             WHEN       COND(&ERRORMSGID *EQ 'CPF5812') THEN(DO)
                /* The dog is already there */
                /* Do something */
             ENDDO
             WHEN       COND(&ERRORMSGID *EQ 'CPF3213') THEN(DO)
                /* The pound is full; no room for one more */
                /* Do something */
             ENDDO
             OTHERWISE  CMD(DO)
                /* Something else went wrong */
                /* Do something */
             ENDDO
          ENDSELECT
    
       ENDDO
    
    ENDPGM
    

    The MONMSG kicks in when the ADDPFM fails. The first RCVMSG retrieves the last message that was sent to the program message queue, which is the escape message, CPF7306. The second RCVMSG retrieves the message before that, which should be the diagnostic message. I’ve included an IF that verifies that the message was a diagnostic message (message type 02), just in case, because I’m the epitome of conservatism.

    Besides retrieving the message type, the second RCVMSG command also retrieves the message ID. This is the information that Chris wanted, the one he needs in order to decide how to proceed.

    –Ted



                         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
    Manta Technologies

    The Leader in IBM i Education!
    Need training on anything i?
    Manta is all you need.

    130 courses and competency exams on:
    · IBM i operations
    · System Management and Security
    · IBM i Programming Tools
    · Programming in RPG, COBOL, CL, Java
    · Web Development

    SQL, DB2, QueryProduct features:
    · Runs in every popular browser
    · Available 24/7/365
    · Free Student Reference Guides
    · Free Student Administration
    · Concurrent User License
    · Built-In IBM i Simulator

    You can download our 200-page catalog and take sample sessions at MantaTech.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    ARCAD Software:  November 20 Webinar: Unify your multi-platform release management - with IOS
    Halcyon Software:  Simplify the monitoring of your ERP systems and HA solutions
    Manta Technologies:  Your complete source for IBM i training

    IT Jungle Store Top Book Picks

    Easy Steps to Internet Programming for AS/400, iSeries, and System i: List Price, $49.95
    The iSeries Express Web Implementer's Guide: List Price, $49.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 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
    Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
    Getting Started with WebSphere Express for iSeries: List Price, $49.00
    Can the AS/400 Survive IBM?: List Price, $49.00
    Chip Wars: List Price, $29.95

    Vegas Casino Doesn’t Gamble with Software from Agilysys IBM Slashes Power Systems Memory Prices

    Leave a Reply Cancel reply

Volume 9, Number 36 -- November 18, 2009
THIS ISSUE SPONSORED BY:

Profound Logic Software
Help/Systems
WorksRight Software

Table of Contents

  • File Caching in RSE
  • Message Received, But Not Understood
  • More with the WDSc Tasks View

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