• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Make a CL Program or Module Retrieve Its Name

    April 21, 2004 Hey, Ted

    As if I didn’t have enough to do, I wasted an hour on a wild goose chase. A user contacted me when a program cancelled. The message she received told her that program XYZ had ended abnormally. It took me a while to determine that program ABC had cancelled instead. It turned out that ABC was a clone of XYZ and still included the following, misleading CL command.

    SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Program +
                  XYZ ended abnormally') MSGTYPE(*ESCAPE)     
    

    I would like to make CL programs determine their own names, so that I can make sure each program reports the correct name in error messages, even when cloned. I have not found a CL command or an API to make a program retrieve its own name. Is this possible?

    –Chuck

    Yes. The trick is to make a program send a message to itself and retrieve the program name from the message about the sender. The following code works in OPM CL programs, ILE CL programs, and ILE CL modules.

    dcl   &MsgKey        *char      4                               
    dcl   &PgmName       *char     10                               
    dcl   &Sender        *char     80                               
                                                                    
    sndpgmmsg msg(' ') topgmq(*same) msgtype(*info) keyvar(&msgkey) 
    rcvmsg    pgmq(*same) msgtype(*info) sender(&sender) rmv(*yes)     
    chgvar    &PgmName   %sst(&Sender 56 10)                        
    

    In the case of CL modules, you should know that this routine returns the name of the program in which this module is bound, not the name of the module. In ILE modules, try the following code to retrieve both program name and module name.

    dcl   &MsgKey        *char      4                             
    dcl   &PgmName       *char     10                             
    dcl   &ModName       *char     10                             
    dcl   &Sender        *char    720                             
                                                                  
    sndpgmmsg msg(' ') topgmq(*same) msgtype(*info) keyvar(&msgkey
    rcvmsg    pgmq(*same) msgtype(*info) rmv(*yes) +              
                 sender(&sender) senderfmt(*long)                 
    chgvar    &PgmName   %sst(&Sender 42 10)                      
    chgvar    &ModName   %sst(&Sender 54 10)                      
    

    –Ted

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Cleo Enhances Automation with AS2 Software for OS/400 IBM Cuts iSeries Prices Ahead of Power5 Launch

    One thought on “Make a CL Program or Module Retrieve Its Name”

    • Svetlana says:
      June 30, 2023 at 7:38 am

      Hello! Thank you for the tip, but I have a question. Can we figure out the library of the programm?

      Best regards,
      Svetlana

      Reply

    Leave a Reply Cancel reply

Volume 4, Number 13 -- April 21, 2004
THIS ISSUE
SPONSORED BY:

T.L. Ashford
Damon Technologies
COMMON
iTera
Guild Companies

Table of Contents

  • Smooth the Java Journey with Struts
  • Programming with Assertions
  • Make a CL Program or Module Retrieve Its Name
  • Admin Alert: When Management Central Server Won’t Start
  • OS/400 Alert: Microsoft Extends the Life of JVM

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